From d9b6876ec2ffd318618d39fdaf53c3e71d50fcba Mon Sep 17 00:00:00 2001 From: Greg Burd Date: Mon, 11 Mar 2024 11:39:12 -0400 Subject: [PATCH] fixes --- .clang-tidy | 149 +++++++++++++++++++++++++++++++++++++++++++ .envrc | 3 +- .gitignore | 2 + README | 4 +- dist/gen_inc.awk | 15 +++++ dist/s_include | 42 ++++++------ dist/sqlconf | 0 shell.nix | 1 + src/api.c | 29 ++++----- src/cg_date.c | 6 +- src/cg_select.c | 2 +- src/dbsql.in | 2 +- src/inc/dbsql_int.in | 22 +++---- src/vdbe.c | 4 +- 14 files changed, 225 insertions(+), 56 deletions(-) create mode 100644 .clang-tidy mode change 100644 => 100755 dist/sqlconf diff --git a/.clang-tidy b/.clang-tidy new file mode 100644 index 0000000..5c5a906 --- /dev/null +++ b/.clang-tidy @@ -0,0 +1,149 @@ +# Generated from CLion Inspection settings +#bugprone-reserved-identifier, +--- +Checks: '-*, +-deprecated-non-prototype +bugprone-argument-comment, +bugprone-assert-side-effect, +bugprone-bad-signal-to-kill-thread, +bugprone-branch-clone, +bugprone-copy-constructor-init, +bugprone-dangling-handle, +bugprone-dynamic-static-initializers, +bugprone-fold-init-type, +bugprone-forward-declaration-namespace, +bugprone-forwarding-reference-overload, +bugprone-inaccurate-erase, +bugprone-incorrect-roundings, +bugprone-integer-division, +bugprone-lambda-function-name, +bugprone-macro-parentheses, +bugprone-macro-repeated-side-effects, +bugprone-misplaced-operator-in-strlen-in-alloc, +bugprone-misplaced-pointer-arithmetic-in-alloc, +bugprone-misplaced-widening-cast, +bugprone-move-forwarding-reference, +bugprone-multiple-statement-macro, +bugprone-no-escape, +bugprone-not-null-terminated-result, +bugprone-parent-virtual-call, +bugprone-posix-return, +bugprone-sizeof-container, +bugprone-sizeof-expression, +bugprone-spuriously-wake-up-functions, +bugprone-string-constructor, +bugprone-string-integer-assignment, +bugprone-string-literal-with-embedded-nul, +bugprone-suspicious-enum-usage, +bugprone-suspicious-include, +bugprone-suspicious-memset-usage, +bugprone-suspicious-missing-comma, +bugprone-suspicious-semicolon, +bugprone-suspicious-string-compare, +bugprone-suspicious-memory-comparison, +bugprone-suspicious-realloc-usage, +bugprone-swapped-arguments, +bugprone-terminating-continue, +bugprone-throw-keyword-missing, +bugprone-too-small-loop-variable, +bugprone-undefined-memory-manipulation, +bugprone-undelegated-constructor, +bugprone-unhandled-self-assignment, +bugprone-unused-raii, +bugprone-unused-return-value, +bugprone-use-after-move, +bugprone-virtual-near-miss, +cert-dcl21-cpp, +cert-dcl58-cpp, +cert-err34-c, +cert-err52-cpp, +cert-err60-cpp, +cert-flp30-c, +cert-msc50-cpp, +cert-msc51-cpp, +cert-str34-c, +cppcoreguidelines-interfaces-global-init, +cppcoreguidelines-narrowing-conversions, +cppcoreguidelines-pro-type-member-init, +cppcoreguidelines-pro-type-static-cast-downcast, +cppcoreguidelines-slicing, +google-default-arguments, +google-explicit-constructor, +google-runtime-operator, +hicpp-exception-baseclass, +hicpp-multiway-paths-covered, +misc-misplaced-const, +misc-new-delete-overloads, +misc-no-recursion, +misc-non-copyable-objects, +misc-throw-by-value-catch-by-reference, +misc-unconventional-assign-operator, +misc-uniqueptr-reset-release, +modernize-avoid-bind, +modernize-concat-nested-namespaces, +modernize-deprecated-headers, +modernize-deprecated-ios-base-aliases, +modernize-loop-convert, +modernize-make-shared, +modernize-make-unique, +modernize-pass-by-value, +modernize-raw-string-literal, +modernize-redundant-void-arg, +modernize-replace-auto-ptr, +modernize-replace-disallow-copy-and-assign-macro, +modernize-replace-random-shuffle, +modernize-return-braced-init-list, +modernize-shrink-to-fit, +modernize-unary-static-assert, +modernize-use-auto, +modernize-use-bool-literals, +modernize-use-emplace, +modernize-use-equals-default, +modernize-use-equals-delete, +modernize-use-nodiscard, +modernize-use-noexcept, +modernize-use-nullptr, +modernize-use-override, +modernize-use-transparent-functors, +modernize-use-uncaught-exceptions, +mpi-buffer-deref, +mpi-type-mismatch, +openmp-use-default-none, +performance-faster-string-find, +performance-for-range-copy, +performance-implicit-conversion-in-loop, +performance-inefficient-algorithm, +performance-inefficient-string-concatenation, +performance-inefficient-vector-operation, +performance-move-const-arg, +performance-move-constructor-init, +performance-no-automatic-move, +performance-noexcept-move-constructor, +performance-trivially-destructible, +performance-type-promotion-in-math-fn, +performance-unnecessary-copy-initialization, +performance-unnecessary-value-param, +portability-simd-intrinsics, +readability-avoid-const-params-in-decls, +readability-const-return-type, +readability-container-size-empty, +readability-convert-member-functions-to-static, +readability-delete-null-pointer, +readability-deleted-default, +readability-inconsistent-declaration-parameter-name, +readability-make-member-function-const, +readability-misleading-indentation, +readability-misplaced-array-index, +readability-non-const-parameter, +readability-redundant-control-flow, +readability-redundant-declaration, +readability-redundant-function-ptr-dereference, +readability-redundant-smartptr-get, +readability-redundant-string-cstr, +readability-redundant-string-init, +readability-simplify-subscript-expr, +readability-static-accessed-through-instance, +readability-static-definition-in-anonymous-namespace, +readability-string-compare, +readability-uniqueptr-delete-release, +readability-use-anyofallof' diff --git a/.envrc b/.envrc index 779839f..f4244f0 100644 --- a/.envrc +++ b/.envrc @@ -1,7 +1,6 @@ export DBSQL_VERSION="$(sh -c '. ./dist/RELEASE; echo $DBSQL_VERSION')" export DBSQL_VERSION_STRING="$(sh -c '. ./dist/RELEASE; echo $DBSQL_VERSION_STRING')" -#export $(grep -v '^#' .env | xargs -0) +#dotenv watch_file devShell.nix shell.nix flake.nix use flake || use nix - diff --git a/.gitignore b/.gitignore index 4fe4e16..b000b02 100644 --- a/.gitignore +++ b/.gitignore @@ -3,9 +3,11 @@ build_unix/** TAGS tags .direnv/ +.idea/ dist/autom4te.cache/ dist/config.hin dist/configure +dist/config.log src/py/setup.py test/scr050/Makefile result-bin diff --git a/README b/README index 37a051d..1cd033b 100644 --- a/README +++ b/README @@ -1,6 +1,6 @@ -DBSQL 0.3.1: (October 23, 2023) +DBSQL 0.4.0: (March 8, 2024) -This is version 0.3.1 of DBSQL. +This is version 0.4.0 of DBSQL. To view the release and installation documentation, load the distribution file docs/index.html into your web browser. diff --git a/dist/gen_inc.awk b/dist/gen_inc.awk index fd97a6e..595bf93 100644 --- a/dist/gen_inc.awk +++ b/dist/gen_inc.awk @@ -34,6 +34,7 @@ # e_pfile include file that contains EXTERN prototypes # i_dfile list of internal (PUBLIC) #defines # i_pfile include file that contains internal (PUBLIC) prototypes +# i_sfile include file that contains internal (STATIC) prototypes /PUBLIC:/ { sub("^.*PUBLIC:[ ][ ]*", "") if ($0 ~ "^#if|^#ifdef|^#ifndef|^#else|^#endif") { @@ -49,6 +50,20 @@ } } +/STATIC:/ { + sub("^.*STATIC:[ ][ ]*", "") + if ($0 ~ "^#if|^#ifdef|^#ifndef|^#else|^#endif") { + print $0 >> i_sfile + next + } + sline = sprintf("%s %s", sline, $0) + if (sline ~ "\\)\\);") { + sub("^[ ]*", "", sline) + print sline >> i_sfile + sline = "" + } +} + /EXTERN:/ { sub("^.*EXTERN:[ ][ ]*", "") if ($0 ~ "^#if|^#ifdef|^#ifndef|^#else|^#endif") { diff --git a/dist/s_include b/dist/s_include index 2323acc..bc88334 100755 --- a/dist/s_include +++ b/dist/s_include @@ -77,7 +77,8 @@ e_dfile=/tmp/__db_c.$$ e_pfile=/tmp/__db_a.$$ i_dfile=/tmp/__db_d.$$ i_pfile=/tmp/__db_b.$$ -trap 'rm -f $e_dfile $e_pfile $i_dfile $i_pfile; exit 0' 0 1 2 3 13 15 +i_sfile=/tmp/__db_e.$$ +trap 'rm -f $e_dfile $e_pfile $i_dfile $i_pfile $i_sfile; exit 0' 0 1 2 3 13 15 head defonly space _DBSQL_EXT_DEF_IN_ > $e_dfile head space _DBSQL_EXT_PROT_IN_ > $e_pfile @@ -85,21 +86,26 @@ head defonly _DBSQL_INT_DEF_IN_ > $i_dfile # Process the standard directories, creating per-directory prototype # files and adding to the external prototype and #define files. -for i in dbsql os clib common ; do - head "_${i}_ext_h_" > $i_pfile - - f="../src/$i/*.c" - [ "$f" = "../src/dbsql/*.c" ] && f="../src/*.c" - awk -f gen_inc.awk \ - -v e_dfile=$e_dfile \ - -v e_pfile=$e_pfile \ - -v i_dfile=$i_dfile \ - -v i_pfile=$i_pfile $f - - tail "_${i}_ext_h_" >> $i_pfile - - f="../src/inc/${i}_ext.h" - cmp $i_pfile $f > /dev/null 2>&1 || - (echo "Building $f" && rm -f $f && cp $i_pfile $f && chmod 444 $f) +for pkg in dbsql os clib common ; do + head "_${pkg}_ext_h_" > $i_pfile + cfiles="../src/${pkg}/*.c" + [ "$cfiles" = "../src/dbsql/*.c" ] && cfiles="../src/*.c" + for file in $(ls $cfiles); do + fname="$(echo $file | sed -n 's/^\(.*\/\)*\([^.]*\)\(.*\)/\2/p')" + head "_${fname}_decl_h_" > $i_sfile + awk -f gen_inc.awk \ + -v e_dfile=$e_dfile \ + -v e_pfile=$e_pfile \ + -v i_dfile=$i_dfile \ + -v i_pfile=$i_pfile \ + -v i_sfile=$i_sfile $file + tail "_${fname}_decl_h_" >> $i_sfile + decl="../src/inc/${fname}_decl.h" +# cmp $i_sfile $decl > /dev/null 2>&1 || +# (echo "Building $decl" && rm -f $decl && cp $i_sfile $decl && chmod 444 $decl) + done + tail "_${pkg}_ext_h_" >> $i_pfile + ext="../src/inc/${pkg}_ext.h" + cmp $i_pfile $ext > /dev/null 2>&1 || + (echo "Building $ext" && rm -f $ext && cp $i_pfile $ext && chmod 444 $ext) done - diff --git a/dist/sqlconf b/dist/sqlconf old mode 100644 new mode 100755 diff --git a/shell.nix b/shell.nix index 7e122d8..c6cc1c3 100644 --- a/shell.nix +++ b/shell.nix @@ -13,6 +13,7 @@ pkgs.mkShell { pkg-config perl ripgrep + python3 ]; buildInputs = with pkgs; [ diff --git a/src/api.c b/src/api.c index 1e51572..84cc6e8 100644 --- a/src/api.c +++ b/src/api.c @@ -48,8 +48,7 @@ typedef struct { * * STATIC: static void __corrupt_schema __P((init_data_t *)); */ -static void -__corrupt_schema(data) +static void __corrupt_schema(data) init_data_t *data; { __str_append(data->err_msgs, "malformed database schema", @@ -70,7 +69,7 @@ __corrupt_schema(data) * argv[4] = "1" for temporary files, "0" for main database, * "2" or more for auxiliary database files. * - * STATIC: static int __init_callback __P((init_data_t *)); + * STATIC: static int __init_callback __P((void *, int, char **, char **)); */ static int __init_callback(init, argc, argv, col_name) @@ -152,7 +151,7 @@ __init_callback(init, argc, argv, col_name) default: /* This can not happen! */ nerr = 1; - DBSQL_ASSERT(nerr == 0); /* TODO create a __fatal() */ + DBSQL_ASSERT(nerr == 0); /* TODO: create a __fatal() */ } return nerr; } @@ -174,8 +173,6 @@ __init_db_file(dbp, dbi, err_msgs) int dbi; char **err_msgs; { - int rc; - int size; table_t *table; char *args[6]; char db_num[30]; @@ -194,7 +191,7 @@ __init_db_file(dbp, dbi, err_msgs) " sql text\n" ")" ; - static char temp_master_schema[] = + static char temp_master_schema[] = "CREATE TEMP TABLE " TEMP_MASTER_NAME "(\n" " type text,\n" " name text,\n" @@ -210,7 +207,7 @@ __init_db_file(dbp, dbi, err_msgs) * master is an increasing integer. So we can play back master * and all the CREATE statements will appear in the right order. */ - static char init_script[] = + static char init_script[] = "SELECT type, name, rootpage, sql, 1 FROM " TEMP_MASTER_NAME " " "UNION ALL " "SELECT type, name, rootpage, sql, 0 FROM " MASTER_NAME ""; @@ -384,7 +381,7 @@ __sqldb_init(p, dbp, name, temp, mem, init_sm) * is locked) then that step is deferred until the first call to * DBSQL->exec(). * - * STATIC: int __api_open __P((DBSQL *, const char *, int, char **)); + * STATIC: static int __api_open __P((DBSQL *, const char *, int, char **)); */ int __api_open(dbp, filename, mode, err_msgs) @@ -555,9 +552,9 @@ __api_close(dbp) * * STATIC: static int __process_sql __P((DBSQL *, const char *, * STATIC: dbsql_callback, void *, const char **, - * STATIC: dbsql_stmt_t, char **)) + * STATIC: dbsql_stmt_t **, char **)); * - * dbp The database on which the SQL executes + * dbp The database * sql The SQL to be executed * callback Invoke this callback routine * arg First argument to callback() @@ -888,7 +885,7 @@ __api_set_busy_timeout(dbp, ms) #else u_int32_t delay = ms; #endif - + if (ms > 0) dbp->set_busycall(dbp, __default_busy_callback, (void*)delay); else @@ -953,7 +950,7 @@ __api_get_encoding() * of arguments, including 0. * * STATIC: static int __api_create_function __P((DBSQL *, const char *, int, - * STATIC: int, void *, + * STATIC: void *, int, * STATIC: void (*)(dbsql_func_t *, int, const char**), * STATIC: void (*)(dbsql_func_t *, int, const char**), * STATIC: void (*)(dbsql_func_t *))); @@ -1011,7 +1008,7 @@ __api_create_function(dbp, name, num_arg, user_data, encoding, func, * __api_exec_printf -- * * STATIC: static int __api_exec_printf __P((DBSQL *, const char *, - * STATIC: dbsql_callback, void *, char **, ...)); + * STATIC: dbsql_callback, void *, char **, ...)) * STATIC: __attribute__ ((__format__ (__printf__, 2, 5))); * * dbp The DBSQL database @@ -1079,7 +1076,7 @@ __api_exec_vprintf(dbp, fmt, callback, arg, err_msgs, ap) * __api_exec_table_printf -- * * STATIC: static int __api_exec_table_printf __P((DBSQL *, const char *, - * STATIC: char ***, int *, int *, char **, ...)); + * STATIC: char ***, int *, int *, char **, ...)) * STATIC: __attribute__ ((__format__ (__printf__, 2, 7))); * * dbp The DBSQL database @@ -1304,7 +1301,7 @@ __api_set_errpfx(dbp, prefix) * __api_get_errpfx -- * Get the error prefix. * - * STATIC: static void __api_get_errpfx __P((DBSQL *, char **)); + * STATIC: static void __api_get_errpfx __P((DBSQL *, const char **)); * * dbp Attach the hook to this database * prefix OUT: The prefix string diff --git a/src/cg_date.c b/src/cg_date.c index f6b0af5..2b0623f 100644 --- a/src/cg_date.c +++ b/src/cg_date.c @@ -27,7 +27,7 @@ * * All times and dates are managed as Julian Day numbers. The * dates and times are stored as the number of days since noon - * in Greenwich on November 24, 4714 B.C. according to the Gregorian + * in Greenwich on November 24, 4714, B.C. according to the Gregorian * calendar system. * * 1970-01-01 00:00:00 is JD 2440587.5 @@ -41,7 +41,7 @@ * The Gregorian calendar system is used for all dates and times, * even those that predate the Gregorian calendar. Historians usually * use the Julian calendar for dates prior to 1582-10-15 and for some - * dates afterwards, depending on locale. Beware of this difference. + * dates afterward, depending on locale. Beware of this difference. * * The conversion algorithms are implemented based on descriptions * in the following text: @@ -168,7 +168,7 @@ __convert_str_to_double(date, result) * * A missing specifier is not considered an error. * - * STATIC: int __parse_tz __P((const char *, datetime_t *)); + * STATIC: static int __parse_tz __P((const char *, datetime_t *)); */ static int __parse_tz(date, dt) diff --git a/src/cg_select.c b/src/cg_select.c index a88c9c1..fba0c78 100644 --- a/src/cg_select.c +++ b/src/cg_select.c @@ -1838,7 +1838,7 @@ static void __subst_expr_list(expr_list_t*,int,expr_list_t*); * changes to pExpr so that it refers directly to the source table * of the subquery rather the result set of the subquery. * - * STATIC: void __subst_expr __P((expr_t *, int, expr_list_t *)); + * STATIC: static void __subst_expr __P((expr_t *, int, expr_list_t *)); */ static void __subst_expr(expr, table, elist) diff --git a/src/dbsql.in b/src/dbsql.in index 41b26f9..9eea3b7 100644 --- a/src/dbsql.in +++ b/src/dbsql.in @@ -343,7 +343,7 @@ struct __dbsql { #define DBSQL_Threaded 0x00000800 /* Set when we're expected to be thread safe. */ u_int8_t want_to_close; /* Close after all VDBEs are deallocated */ - int next_sig; /* Next value of aDb[0].schema_sig */ + u_int32_t next_sig; /* Next value of aDb[0].schema_sig */ int nTable; /* Number of tables in the database */ void *pBusyArg; /* 1st Argument to the busy callback */ int (*xBusyCallback)(DBSQL *, void *, const char*, int); diff --git a/src/inc/dbsql_int.in b/src/inc/dbsql_int.in index f1fc0de..b4f4219 100644 --- a/src/inc/dbsql_int.in +++ b/src/inc/dbsql_int.in @@ -183,20 +183,20 @@ typedef struct sm_cursor { * the ATTACH statement during the session. */ struct __dbsql_db { - char *zName; /* Name of this database */ - sm_t *pBt; /* The storage manager for this database */ - int schema_sig; /* Database schema version number for this file */ - hash_t tblHash; /* All tables indexed by name */ - hash_t idxHash; /* All (named) indices indexed by name */ - hash_t trigHash; /* All triggers indexed by name */ - hash_t aFKey; /* Foreign keys indexed by to-table */ - int inTrans; /* 0: not writable. 1: Transaction. 2: Checkpoint */ - DBSQL *dbp; /* A reference to our managing DBSQL */ - int flags; /* Flags associated with this database */ + char *zName; /* Name of this database */ + sm_t *pBt; /* The storage manager for this database */ + u_int32_t schema_sig; /* Database schema version number for this file */ + hash_t tblHash; /* All tables indexed by name */ + hash_t idxHash; /* All (named) indices indexed by name */ + hash_t trigHash; /* All triggers indexed by name */ + hash_t aFKey; /* Foreign keys indexed by to-table */ + int inTrans; /* 0: not writable. 1: Transaction. 2: Checkpoint */ + DBSQL *dbp; /* A reference to our managing DBSQL */ + int flags; /* Flags associated with this database */ /* * The DBSQL_SCHEMA_LOCKED flag is set when the first OP_Transaction or * OP_Checkpoint opcode is emitted for a database. This prevents multiple - * occurances of those opcodes for the same database in the same program. + * occurrences of those opcodes for the same database in the same program. * TODO: do we need this? * * Similarly, the DBSQL_COOKIE flag is set when the OP_VerifyCookie opcode diff --git a/src/vdbe.c b/src/vdbe.c index 1fa8911..d21a894 100644 --- a/src/vdbe.c +++ b/src/vdbe.c @@ -274,7 +274,7 @@ __entity_as_string(stack) * string space if the string will fit but this routine will always * __dbsql_malloc new memory. Return non-zero if we run out of memory. * - * STATIC: int __entity_to_string __P((mem_t *)); + * STATIC: static int __entity_to_string __P((mem_t *)); */ static int __entity_to_string(stack) @@ -344,7 +344,7 @@ __entity_release_mem(stack) * __pop_stack -- * Pop the stack N times. * - * STATIC: void __pop_stack __P((mem_t **, int)); + * STATIC: static void __pop_stack __P((mem_t **, int)); */ static void __pop_stack(stack, n)