fixed portability to mac os/x 10.4.9
There was no need to maintain random number generation state within the DBSQL structure, that is removed and now static within the two functions requiring random number generation. The placement of the function hash table in the memory allocated for DBSQL was wrong, that is now fixed.
This commit is contained in:
parent
4a8fcf6cd1
commit
f1037cdd9a
10 changed files with 33 additions and 26 deletions
7
dist/Makefile.in
vendored
7
dist/Makefile.in
vendored
|
@ -136,15 +136,14 @@ C_FILES=\
|
|||
# Object and utility lists.
|
||||
##################################################
|
||||
|
||||
C_OBJS= @ADDITIONAL_OBJS@ @REPLACEMENT_OBJS@ \
|
||||
cg_attach@o@ cg_insert@o@ sql_tokenize@o@ cg_auth@o@ \
|
||||
C_OBJS= cg_attach@o@ cg_insert@o@ sql_tokenize@o@ cg_auth@o@ \
|
||||
cg_copy@o@ api_table@o@ cg_date@o@ api@o@ xvprintf@o@ \
|
||||
cg_pragma@o@ cg_where@o@ cg_trigger@o@ cg_build@o@ \
|
||||
sql_fns@o@ random@o@ cg_update@o@ cg_delete@o@ hash@o@ \
|
||||
cg_expr@o@ opcodes@o@ sql_parser@o@ cg_vacuum@o@ \
|
||||
vdbe@o@ vdbe_method@o@ sm@o@ snprintf@o@ dbsql_err@o@ cg_select@o@ \
|
||||
os_jtime@o@ memcmp@o@ dbsql_atof@o@ safety@o@ \
|
||||
strcasecmp@o@ strdup@o@ dbsql_alloc@o@ str@o@ dbsql_atoi@o@
|
||||
os_jtime@o@ memcmp@o@ dbsql_atof@o@ safety@o@ dbsql_atoi@o@ \
|
||||
strcasecmp@o@ strdup@o@ dbsql_alloc@o@ str@o@
|
||||
|
||||
LEMON_OBJS=\
|
||||
lemon@o@
|
||||
|
|
5
dist/configure.ac
vendored
5
dist/configure.ac
vendored
|
@ -490,10 +490,7 @@ esac
|
|||
|
||||
# We need to add the additional object files into the Makefile with the correct
|
||||
# suffix. We can't use $LTLIBOBJS itself, because that variable has $U encoded
|
||||
# in it for automake, and that's not what we want. See SR #7227 for additional
|
||||
# information.
|
||||
#
|
||||
# XXX: I'm not sure this is correct.
|
||||
# in it for automake, and that's not what we want.
|
||||
REPLACEMENT_OBJS=`echo "$LIB@&t@OBJS" |
|
||||
sed "s,\.[[^.]]* ,$o ,g;s,\.[[^.]]*$,$o,"`
|
||||
|
||||
|
|
|
@ -789,7 +789,7 @@ __default_busy_callback(dbp, arg, not_used, count)
|
|||
#if defined(__LP64) || defined(__LP64__)
|
||||
u_int64_t timeout = (u_int64_t)arg;
|
||||
#else
|
||||
u_int32_t timeout = (u_int32_)t)arg;
|
||||
u_int32_t timeout = (u_int32_t)arg;
|
||||
#endif
|
||||
#if DBSQL_MIN_SLEEP_MS==1
|
||||
static const char delays[] =
|
||||
|
@ -1438,13 +1438,11 @@ dbsql_create(dbpp, dbenv, flags)
|
|||
DBSQL_GLOBAL(encoding) = "iso8859";
|
||||
#endif
|
||||
|
||||
if (__dbsql_calloc(NULL, 1, sizeof(*dbp) + sizeof(hash_t), &dbp)
|
||||
if (__dbsql_calloc(NULL, 1, sizeof(DBSQL) + sizeof(hash_t), &dbp)
|
||||
== ENOMEM)
|
||||
return DBSQL_NOMEM;
|
||||
|
||||
dbp->aFunc = dbp + sizeof(hash_t);
|
||||
|
||||
srand48_r(1, &dbp->rand); /* seed our random number generator TODO */
|
||||
dbp->aFunc = dbp + sizeof(DBSQL);
|
||||
|
||||
if (LF_ISSET(DBSQL_THREAD))
|
||||
F_SET(dbp, DBSQL_Threaded);
|
||||
|
|
|
@ -1053,9 +1053,15 @@ void __change_schema_signature(dbp, v)
|
|||
DBSQL *dbp;
|
||||
vdbe_t *v;
|
||||
{
|
||||
static struct drand48_data rand;
|
||||
static int first_time = 1;
|
||||
if (first_time) {
|
||||
first_time = 0;
|
||||
srand48_r(&rand);
|
||||
}
|
||||
if (dbp->next_sig == dbp->aDb[0].schema_sig) {
|
||||
u_int8_t n;
|
||||
rand8_r(&dbp->rand, &n);
|
||||
rand8_r(&rand, &n);
|
||||
dbp->next_sig = dbp->aDb[0].schema_sig + n + 1;
|
||||
dbp->flags |= DBSQL_InternChanges;
|
||||
__vdbe_add_op(v, OP_Integer, dbp->next_sig, 0);
|
||||
|
|
|
@ -129,7 +129,7 @@ __rng_seed(buf)
|
|||
#ifdef CONFIG_TEST
|
||||
return;
|
||||
#else
|
||||
__os_pid(&pid);
|
||||
__os_id(NULL, &pid, NULL);
|
||||
__os_jtime(&jt);
|
||||
for (i = 0; i < SEED_SZ; i++) {
|
||||
if (i % 2)
|
||||
|
@ -152,7 +152,7 @@ __rng_seed(buf)
|
|||
*/
|
||||
#ifndef HAVE_SRAND48_R
|
||||
int
|
||||
srand48_r(seedval, buffer)
|
||||
srand48_r(buffer)
|
||||
struct drand48_data *buffer;
|
||||
{
|
||||
int i;
|
||||
|
|
|
@ -326,7 +326,6 @@ struct __dbsql {
|
|||
FILE *dbsql_errfile; /* The error file */
|
||||
char *dbsql_errpfx; /* The error prefix string */
|
||||
void (*dbsql_paniccall)(DBSQL *, int); /* The panic callback */
|
||||
struct drand48_data rand; /* Random generator state */
|
||||
int panic; /* If non-zero, shut down the application */
|
||||
dbsql_db_t *aDb; /* One for each open SQL database + 2 */
|
||||
int nDb; /* Number of open dbsql_db_t's open */
|
||||
|
|
|
@ -46,6 +46,7 @@ extern int __os_urealloc__DB_UNIQUE_NAME__ __P((DB_ENV *, size_t, void *));
|
|||
extern int __os_umalloc__DB_UNIQUE_NAME__ __P((DB_ENV *, size_t, void *));
|
||||
extern int __os_exists__DB_UNIQUE_NAME__ __P((const char *, int *));
|
||||
extern int __db_omode__DB_UNIQUE_NAME__ __P((const char *));
|
||||
extern int __os_id__DB_UNIQUE_NAME__ __P((DB_ENV *, pid_t *, db_threadid_t*));
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
|
|
|
@ -37,17 +37,18 @@
|
|||
|
||||
#include <db.h>
|
||||
|
||||
#include "dbsql.h"
|
||||
#include "sql_parser.h"
|
||||
|
||||
#include "inc/queue.h"
|
||||
#include "inc/hash.h"
|
||||
#include "inc/str.h"
|
||||
#include "inc/random.h"
|
||||
#include "inc/vdbe.h"
|
||||
#include "inc/debug.h"
|
||||
#include "inc/xvprintf.h"
|
||||
#include "inc/globals.h"
|
||||
|
||||
#include "dbsql.h"
|
||||
|
||||
/*
|
||||
* Forward references to structures.
|
||||
*/
|
||||
|
@ -184,7 +185,7 @@ typedef struct sm_cursor {
|
|||
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 */
|
||||
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 */
|
||||
|
|
|
@ -351,12 +351,12 @@ __random_func(context, argc, argv)
|
|||
int argc;
|
||||
const char **argv;
|
||||
{
|
||||
int n;
|
||||
u_int32_t n;
|
||||
static struct drand48_data rand;
|
||||
static int first_time = 1;
|
||||
if (first_time) {
|
||||
first_time = 0;
|
||||
srand48_r(1, &rand); /* TODO seed our random number generator */
|
||||
srand48_r(&rand);
|
||||
}
|
||||
rand32_r(&rand, &n);
|
||||
dbsql_set_result_int(context, n);
|
||||
|
|
14
src/vdbe.c
14
src/vdbe.c
|
@ -2445,7 +2445,7 @@ case OP_SetSchemaSignature: {
|
|||
** everyone (and their data).
|
||||
*/
|
||||
case OP_VerifySchemaSignature: {
|
||||
int sig;
|
||||
u_int32_t sig;
|
||||
DBSQL_ASSERT(pOp->p1 >= 0 && pOp->p1 < db->nDb);
|
||||
rc = __sm_get_schema_sig(db->aDb[pOp->p1].pBt, &sig);
|
||||
if (rc == DBSQL_SUCCESS && sig != pOp->p2) {
|
||||
|
@ -2943,8 +2943,14 @@ case OP_NotExists: {
|
|||
** onto the stack.
|
||||
*/
|
||||
case OP_NewRecno: {
|
||||
static struct drand48_data rand;
|
||||
static int first_time = 1;
|
||||
if (first_time) {
|
||||
first_time = 0;
|
||||
srand48_r(&rand);
|
||||
}
|
||||
int i = pOp->p1;
|
||||
int v = 0;
|
||||
u_int32_t v = 0;
|
||||
cursor_t *pC;
|
||||
DBSQL_ASSERT(i >= 0 && i < p->nCursor);
|
||||
if ((pC = &p->aCsr[i])->pCursor == 0) {
|
||||
|
@ -3017,12 +3023,12 @@ case OP_NewRecno: {
|
|||
cnt = 0;
|
||||
do {
|
||||
if (v == 0 || cnt > 2) {
|
||||
rand32_r(&db->rand, &v);
|
||||
rand32_r(&rand, &v);
|
||||
if (cnt < 5)
|
||||
v &= 0xffffff;
|
||||
} else {
|
||||
u_int8_t rb;
|
||||
rand8_r(&db->rand, &rb);
|
||||
rand8_r(&rand, &rb);
|
||||
v += rb + 1;
|
||||
}
|
||||
if (v == 0)
|
||||
|
|
Loading…
Reference in a new issue