From 9ab52d89beef1a517f2058da981d13a30f8b5345 Mon Sep 17 00:00:00 2001 From: Gregory Burd Date: Sun, 21 Oct 2007 01:33:16 +0100 Subject: [PATCH] Clean up and type fixes. After discussions with Keith Bostic I've learned that always specifying the full type (u_int32_t rather than int) as a general rule is not always a good idea. Now, as I review code I'm reverting some of those changes. The new rule of thumb is to use explict typing only in places that require it. --- src/dbsql/dbsql.c | 7 ++++--- src/inc/dbsql_int.in | 10 +++++----- src/sql_fns.c | 2 +- src/vdbe.c | 6 +++--- src/vdbe_method.c | 2 +- 5 files changed, 14 insertions(+), 13 deletions(-) diff --git a/src/dbsql/dbsql.c b/src/dbsql/dbsql.c index c532196..afacafb 100644 --- a/src/dbsql/dbsql.c +++ b/src/dbsql/dbsql.c @@ -589,7 +589,8 @@ open_db(p) filename = p->db_filename; if (!strcmp(p->db_filename, ":memory:")) filename = 0; - rc = dbsql_create_env(&p->db, filename, p->crypt_key,0,flags); + rc = dbsql_create_env(&p->db, filename, + p->crypt_key, 0, flags); switch (rc) { case DB_RUNRECOVERY: fprintf(g.errfp, "Database requires recovery.\n"); @@ -966,7 +967,7 @@ do_meta_command(line, p) fprintf(p->out, "\n\n"); } else if (c == 't' && n > 1 && strncmp(args[0], "tables", n) == 0) { char **results; - int nRow, rc; + int nRow, nCol, rc; char *err_msgs; open_db(p); if (num_args == 1) { @@ -977,7 +978,7 @@ do_meta_command(line, p) "SELECT name FROM " TEMP_MASTER_NAME " " "WHERE type IN ('table','view') " "ORDER BY 1", - &results, &nRow, 0, &err_msgs); + &results, &nRow, &nCol, &err_msgs); } else { rc = p->db->exec_table_printf(p->db, "SELECT name FROM " MASTER_NAME " " diff --git a/src/inc/dbsql_int.in b/src/inc/dbsql_int.in index aedb435..35a9f3f 100644 --- a/src/inc/dbsql_int.in +++ b/src/inc/dbsql_int.in @@ -183,16 +183,16 @@ 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 */ - u_int32_t schema_sig;/* Database schema version number for this file */ + 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 */ - u_int8_t inTrans; /* 0: not writable. 1: Transaction. 2: Checkpoint */ + int inTrans; /* 0: not writable. 1: Transaction. 2: Checkpoint */ DBSQL *dbp; /* A reference to our managing DBSQL */ - u_int16_t flags; /* Flags associated with this database */ + 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 diff --git a/src/sql_fns.c b/src/sql_fns.c index fcb4968..0d37b82 100644 --- a/src/sql_fns.c +++ b/src/sql_fns.c @@ -351,7 +351,7 @@ __random_func(context, argc, argv) int argc; const char **argv; { - u_int32_t n; + int n; static struct drand48_data rand; static int first_time = 1; if (first_time) { diff --git a/src/vdbe.c b/src/vdbe.c index 7a1389f..7ce5296 100644 --- a/src/vdbe.c +++ b/src/vdbe.c @@ -2445,7 +2445,7 @@ case OP_SetSchemaSignature: { ** everyone (and their data). */ case OP_VerifySchemaSignature: { - u_int32_t sig; + int 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) { @@ -2950,7 +2950,7 @@ case OP_NewRecno: { srand48_r(1, &rand); /* XXX create a portable rand function */ } int i = pOp->p1; - u_int32_t v = 0; + int v = 0; cursor_t *pC; DBSQL_ASSERT(i >= 0 && i < p->nCursor); if ((pC = &p->aCsr[i])->pCursor == 0) { @@ -3396,7 +3396,7 @@ case OP_Recno: { break; } else { DBSQL_ASSERT(pC->pCursor != 0); - __sm_key(pC->pCursor, 0, sizeof(u_int32_t), (char*)&v); + __sm_key(pC->pCursor, 0, sizeof(int), (char*)&v); v = KEY_TO_INT(v); } pTos->i = v; diff --git a/src/vdbe_method.c b/src/vdbe_method.c index 2378cc7..38c4248 100644 --- a/src/vdbe_method.c +++ b/src/vdbe_method.c @@ -533,7 +533,7 @@ dbsql_set_result_string(p, result, n) p->s.flags = MEM_Str | MEM_Short; p->s.z = p->s.zShort; } else { - if (__dbsql_calloc(NULL, 1, n + 1, &p->s.z) != ENOMEM){ + if (__dbsql_calloc(NULL, 1, n + 1, &p->s.z) != ENOMEM) { memcpy(p->s.z, result, n); p->s.z[n] = 0; }