This commit is contained in:
Gregory Burd 2024-03-11 11:39:12 -04:00
parent 7ce1172dcd
commit d9b6876ec2
14 changed files with 225 additions and 56 deletions

149
.clang-tidy Normal file
View file

@ -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'

3
.envrc
View file

@ -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

2
.gitignore vendored
View file

@ -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

4
README
View file

@ -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.

15
dist/gen_inc.awk vendored
View file

@ -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") {

42
dist/s_include vendored
View file

@ -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

0
dist/sqlconf vendored Normal file → Executable file
View file

View file

@ -13,6 +13,7 @@ pkgs.mkShell {
pkg-config
perl
ripgrep
python3
];
buildInputs = with pkgs; [

View file

@ -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

View file

@ -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)

View file

@ -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)

View file

@ -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);

View file

@ -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

View file

@ -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)