From 2ea8e2a05af7abb79d89ebd7d8af349250c28b81 Mon Sep 17 00:00:00 2001 From: vraatikka Date: Wed, 26 Jun 2013 09:39:38 +0300 Subject: [PATCH] Added licences and changed the use of zero-length arrays due to compiler problems. --- log_manager/log_manager.cc | 70 +++++++++++++++++++++++++------------- log_manager/log_manager.h | 17 +++++++++ log_manager/test/testlog.c | 23 +++++++++++++ utils/skygw_debug.h | 38 +++++++++++++++------ utils/skygw_types.h | 43 +++++++++++------------ utils/skygw_utils.cc | 19 +++++++++++ 6 files changed, 153 insertions(+), 57 deletions(-) diff --git a/log_manager/log_manager.cc b/log_manager/log_manager.cc index 64507e45c..df5c82edd 100644 --- a/log_manager/log_manager.cc +++ b/log_manager/log_manager.cc @@ -1,3 +1,22 @@ +/* + * This file is distributed as part of the SkySQL Gateway. It is free + * software: you can redistribute it and/or modify it under the terms of the + * GNU General Public License as published by the Free Software Foundation, + * version 2. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., 51 + * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Copyright SkySQL Ab 2013 + */ + + #include #include #include @@ -16,7 +35,7 @@ typedef struct logfile_writebuf_st { skygw_chk_t wb_chk_top; size_t wb_bufsize; - char wb_buf[1]; + char wb_buf[1]; /** no zero length arrays in C++ */ } logfile_writebuf_t; /** Writer thread structure */ @@ -403,7 +422,7 @@ static int logmanager_write( } /** Split loginfo to buffers, if necessary, and add buffers * to logfile. - * Free write buffer pointer array, and original string. */ + * Free write buffer pointer array. */ logfile_write_buffers(lf, wb_arr, str); } else { ss_dassert(flush); @@ -459,36 +478,35 @@ static logfile_writebuf_t** get_or_create_writebuffers( fprintf(stderr, "Allocating memory for write buffer " "pointer array failed.\n"); - goto return_p_str; + goto return_p_wb; } /** Allocate memory for all write buffers. * Real allocation size includes logfile_writebuf_t and bufsize. * -1 is the one byte defined in logfile_writebuf_st. */ allocsize = sizeof(logfile_writebuf_t)+bufsize-1; - *p_wb = (logfile_writebuf_t *)calloc(nbufs, allocsize); - if (*p_wb == NULL) { - fprintf(stderr, - "Allocating memory for write buffer " - "pointer array failed.\n"); - free(*p_wb); - free(p_wb); - *p_wb = NULL; - goto return_p_str; - } - - /** Store pointers of each buffer from continuous memory chunk - * to p_str. Initialize each write buffer. - */ + /** Allocate each buffer with separate call because memory checkers + * don't like array of structs which have flexible arrays. */ for (i=0; i=0) { + free(p_wb[i]); + i -= 1; + } + free(p_wb); + p_wb = NULL; + fprintf(stderr, "Allocating memory for write buffer failed.\n"); + goto return_p_wb; + } p_wb[i]->wb_chk_top = CHK_NUM_WRITEBUF; p_wb[i]->wb_bufsize = bufsize; } - ss_dassert(p_wb[i] == NULL); -return_p_str: +return_p_wb: return p_wb; } @@ -525,8 +543,6 @@ static void logfile_write_buffers( p += copylen; slen -= copylen; } - /** Release log string */ - free(str); ss_dassert(slen == 0); ss_dassert(*p_wb == NULL); p_wb = p_data; @@ -583,6 +599,8 @@ int skygw_log_write_flush( return_unregister: logmanager_unregister(lmgr); return_err: + /** Free log string */ + free(str); return err; } @@ -593,7 +611,7 @@ int skygw_log_write( char* str) { int err = 0; - + if (lmgr == NULL) { fprintf(stderr, "Error. Logmanager is not initialized.\n"); err = -1; @@ -622,6 +640,8 @@ int skygw_log_write( return_unregister: logmanager_unregister(lmgr); return_err: + /** Free log string */ + free(str); return err; } @@ -931,6 +951,7 @@ static bool logfile_init( { bool succp = FALSE; size_t namelen; + size_t s; fnames_conf_t* fn = &logmanager->lm_fnames_conf; logfile->lf_chk_top = CHK_NUM_LOGFILE; @@ -947,10 +968,11 @@ static bool logfile_init( /** Read existing files to logfile->lf_files_list and create * new file for log named after / */ + s = UINTLEN(logfile->lf_name_sequence); namelen = strlen(logfile->lf_logpath) + sizeof('/') + strlen(logfile->lf_name_prefix) + - printf("%d",logfile->lf_name_sequence) + + s + strlen(logfile->lf_name_suffix) + sizeof('\0'); diff --git a/log_manager/log_manager.h b/log_manager/log_manager.h index 79b0018b1..23a06492b 100644 --- a/log_manager/log_manager.h +++ b/log_manager/log_manager.h @@ -1,3 +1,20 @@ +/* + * This file is distributed as part of the SkySQL Gateway. It is free + * software: you can redistribute it and/or modify it under the terms of the + * GNU General Public License as published by the Free Software Foundation, + * version 2. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., 51 + * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Copyright SkySQL Ab 2013 + */ typedef struct filewriter_st filewriter_t; diff --git a/log_manager/test/testlog.c b/log_manager/test/testlog.c index 8d6d9c070..ee187a21c 100644 --- a/log_manager/test/testlog.c +++ b/log_manager/test/testlog.c @@ -1,3 +1,26 @@ +/* + * This file is distributed as part of the SkySQL Gateway. It is free + * software: you can redistribute it and/or modify it under the terms of the + * GNU General Public License as published by the Free Software Foundation, + * version 2. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., 51 + * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Copyright SkySQL Ab 2013 + */ + + +/** @file +@brief (brief description) + +*/ #include #include #include diff --git a/utils/skygw_debug.h b/utils/skygw_debug.h index 66659cf4d..dbafb3d23 100644 --- a/utils/skygw_debug.h +++ b/utils/skygw_debug.h @@ -1,3 +1,22 @@ +/* + * This file is distributed as part of the SkySQL Gateway. It is free + * software: you can redistribute it and/or modify it under the terms of the + * GNU General Public License as published by the Free Software Foundation, + * version 2. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., 51 + * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Copyright SkySQL Ab 2013 + */ + + #include #include #include @@ -18,15 +37,6 @@ #if defined(SS_DEBUG) -# define STRBOOL(b) ((b) ? "TRUE" : "FALSE") -# define STRQTYPE(t) ((t) == QUERY_TYPE_WRITE ? "QUERY_TYPE_WRITE" : \ - ((t) == QUERY_TYPE_READ ? "QUERY_TYPE_READ" : \ - ((t) == QUERY_TYPE_SESSION_WRITE ? "QUERY_TYPE_SESSION_WRITE" : \ - "QUERY_TYPE_UNKNOWN"))) -#define STRLOGID(i) ((i) == LOGFILE_TRACE ? "LOGFILE_TRACE" : \ - ((i) == LOGFILE_MESSAGE ? "LOGFILE_MESSAGE" : \ - ((i) == LOGFILE_ERROR ? "LOGFILE_ERROR" : \ - "Unknown logfile type"))) # define ss_dfprintf fprintf # define ss_dfflush fflush # define ss_dfwrite fwrite @@ -63,7 +73,6 @@ #else /* SS_DEBUG */ -# define STRBOOL(b) # define ss_dfprintf(a, b, ...) # define ss_dfflush # define ss_dfwrite @@ -94,6 +103,15 @@ typedef enum skygw_chk_t { CHK_NUM_WRITEBUF } skygw_chk_t; +# define STRBOOL(b) ((b) ? "TRUE" : "FALSE") +# define STRQTYPE(t) ((t) == QUERY_TYPE_WRITE ? "QUERY_TYPE_WRITE" : \ + ((t) == QUERY_TYPE_READ ? "QUERY_TYPE_READ" : \ + ((t) == QUERY_TYPE_SESSION_WRITE ? "QUERY_TYPE_SESSION_WRITE" : \ + "QUERY_TYPE_UNKNOWN"))) +#define STRLOGID(i) ((i) == LOGFILE_TRACE ? "LOGFILE_TRACE" : \ + ((i) == LOGFILE_MESSAGE ? "LOGFILE_MESSAGE" : \ + ((i) == LOGFILE_ERROR ? "LOGFILE_ERROR" : \ + "Unknown logfile type"))) #define CHK_MLIST(l) { \ ss_info_dassert((l->mlist_chk_top == CHK_NUM_MLIST && \ diff --git a/utils/skygw_types.h b/utils/skygw_types.h index 4766d5ab1..6d0d3b26b 100644 --- a/utils/skygw_types.h +++ b/utils/skygw_types.h @@ -1,28 +1,23 @@ -/** - * @section LICENCE - * - * This file is distributed as part of the SkySQL Gateway. It is - * free software: you can redistribute it and/or modify it under - * the terms of the GNU General Public License as published by the - * Free Software Foundation, version 2. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - * 02110-1301 USA. - * - * Copyright SkySQL Ab - * - * @file - * @brief - * +/* + * This file is distributed as part of the SkySQL Gateway. It is free + * software: you can redistribute it and/or modify it under the terms of the + * GNU General Public License as published by the Free Software Foundation, + * version 2. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., 51 + * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Copyright SkySQL Ab 2013 */ +#include + #if !defined(SKYGW_TYPES_H) #define SKYGW_TYPES_H @@ -37,7 +32,9 @@ #define MB MEGABYTE_BYTE #define GB GIGABYTE_BYTE +#define CALCLEN(i) (floor(log10(abs(i))) + 1) +#define UINTLEN(i) (i<10 ? 1 : (i<100 ? 2 : (i<1000 ? 3 : CALCLEN(i)))) #if defined(__cplusplus) && !defined(TRUE) && !defined(FALSE) # define TRUE true diff --git a/utils/skygw_utils.cc b/utils/skygw_utils.cc index c04a42685..2b00ae28e 100644 --- a/utils/skygw_utils.cc +++ b/utils/skygw_utils.cc @@ -1,3 +1,22 @@ +/* + * This file is distributed as part of the SkySQL Gateway. It is free + * software: you can redistribute it and/or modify it under the terms of the + * GNU General Public License as published by the Free Software Foundation, + * version 2. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., 51 + * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Copyright SkySQL Ab 2013 + */ + + #include #include #include