On 9/14/07, Liam Healy <[EMAIL PROTECTED]> wrote:
> I tried eliminating sqliteInt.h and replacing with explicit declarations
> of i64 and u8. That part worked fine, but func_ext.c also uses
> sqliteMalloc
void *sqlite3_malloc(int);
void *sqlite3_realloc(void*, int);
void sqlite3_free(void*);
are the right functions to use (they are in sqlite3.h).
> which is also defined in sqliteInt.h which led me down a rabbit hole of
> pulling
> more and more from sqliteInt.h, and I still can't eliminate the errors and
> warnings. As a reminder, I didn't write the original source code, and I
> have
> only the vaguest sense of the meaning and need for these functions. So, if
> anyone has any insight on how to accomplish the same goal without using
> internal definitions, I'd appreciate hearing about it.
I attached a patch with the required changes just to compile using
only <sqlite3.h>.
Used the current source code of the extensions on the contrib page.
This is not enough to create a sqlite module, but at least it compiles
without using the private sqlite headers.
Regards,
~Nuno Lucas
>
> Liam
diff -urN orig/func_ext.c fixed/func_ext.c
--- orig/func_ext.c 2007-09-05 21:29:10.000000000 +0100
+++ fixed/func_ext.c 2007-09-15 05:16:34.000000000 +0100
@@ -13,13 +13,13 @@
#define HAVE_COSH 1
#define HAVE_TANH 1
#define HAVE_LOG10 1
-#define HAVE_ISBLANK 1
+//#define HAVE_ISBLANK 1
#define SQLITE_SOUNDEX 1
#define HAVE_TRIM 1 /* LMH 2007-03-25 if sqlite has trim functions */
//#if SQLITE_WITH_EXTRA_FUNCTIONS
-#include "sqliteInt.h"
+#include "sqlite3.h"
#include <ctype.h>
/* relicoder */
#include <math.h>
@@ -29,10 +29,18 @@
#include <stdlib.h>
#include <assert.h>
-#include "vdbeInt.h"
-#include "os.h"
#include "map.h"
+
+typedef uint8_t u8;
+typedef uint16_t u16;
+typedef int64_t i64;
+
+static char *sqlite3StrDup( const char *z ) {
+ char *res = sqlite3_malloc( strlen(z)+1 );
+ return strcpy( res, z );
+}
+
/*
** These are copied verbatim from fun.c so as to not have the names exported
*/
@@ -98,6 +106,55 @@
0xffff0000,
};
+/* LMH salvaged from sqlite3 3.3.13 source code src/utf.c */
+#define READ_UTF8(zIn, c) { \
+ int xtra; \
+ c = *(zIn)++; \
+ xtra = xtra_utf8_bytes[c]; \
+ switch( xtra ){ \
+ case 4: c = (int)0xFFFD; break; \
+ case 3: c = (c<<6) + *(zIn)++; \
+ case 2: c = (c<<6) + *(zIn)++; \
+ case 1: c = (c<<6) + *(zIn)++; \
+ c -= xtra_utf8_bits[xtra]; \
+ if( (utf_mask[xtra]&c)==0 \
+ || (c&0xFFFFF800)==0xD800 \
+ || (c&0xFFFFFFFE)==0xFFFE ){ c = 0xFFFD; } \
+ } \
+}
+
+static int sqlite3ReadUtf8(const unsigned char *z){
+ int c;
+ READ_UTF8(z, c);
+ return c;
+}
+
+#define SKIP_UTF8(zIn) { \
+ zIn += (xtra_utf8_bytes[*(u8 *)zIn] + 1); \
+}
+
+/*
+** pZ is a UTF-8 encoded unicode string. If nByte is less than zero,
+** return the number of unicode characters in pZ up to (but not including)
+** the first 0x00 byte. If nByte is not less than zero, return the
+** number of unicode characters in the first nByte of pZ (or up to
+** the first 0x00, whichever comes first).
+*/
+static int sqlite3Utf8CharLen(const char *z, int nByte){
+ int r = 0;
+ const char *zTerm;
+ if( nByte>=0 ){
+ zTerm = &z[nByte];
+ }else{
+ zTerm = (const char *)(-1);
+ }
+ assert( z<=zTerm );
+ while( *z!=0 && z<zTerm ){
+ SKIP_UTF8(z);
+ r++;
+ }
+ return r;
+}
/*
** X is a pointer to the first byte of a UTF-8 character. Increment
@@ -462,8 +519,8 @@
nLen = sqlite3_value_bytes(argv[0]);
nTLen = nLen*iCount;
- z=sqliteMalloc(nTLen+1);
- zo=sqliteMalloc(nLen+1);
+ z=sqlite3_malloc(nTLen+1);
+ zo=sqlite3_malloc(nLen+1);
strcpy((char*)zo, (char*)sqlite3_value_text(argv[0]));
for(i=0; i<iCount; ++i){
@@ -471,8 +528,8 @@
}
sqlite3_result_text(context, (char*)z, -1, SQLITE_TRANSIENT);
- sqliteFree(z);
- sqliteFree(zo);
+ sqlite3_free(z);
+ sqlite3_free(zo);
}
}
@@ -493,7 +550,7 @@
char r;
int c=1;
- assert( argc!==1);
+ assert( argc!=1);
if( SQLITE_NULL==sqlite3_value_type(argv[0]) ){
sqlite3_result_null(context);
return;
@@ -519,7 +576,7 @@
*zt = '\0';
sqlite3_result_text(context, (char*)zo, -1, SQLITE_TRANSIENT);
- sqliteFree(zo);
+ sqlite3_free(zo);
}
/*
@@ -554,7 +611,7 @@
zo = sqlite3StrDup(zi);
sqlite3_result_text(context, zo, -1, SQLITE_TRANSIENT);
}else{
- zo = sqliteMalloc(strlen(zi)+ilen-zl+1);
+ zo = sqlite3_malloc(strlen(zi)+ilen-zl+1);
zt = zo;
for(i=1; i+zl<=ilen; ++i){
*(zt++)=' ';
@@ -563,7 +620,7 @@
strcpy(zt,zi);
}
sqlite3_result_text(context, zo, -1, SQLITE_TRANSIENT);
- sqliteFree(zo);
+ sqlite3_free(zo);
}
}
@@ -601,7 +658,7 @@
sqlite3_result_text(context, zo, -1, SQLITE_TRANSIENT);
}else{
zll = strlen(zi);
- zo = sqliteMalloc(zll+ilen-zl+1);
+ zo = sqlite3_malloc(zll+ilen-zl+1);
zt = strcpy(zo,zi)+zll;
for(i=1; i+zl<=ilen; ++i){
*(zt++) = ' ';
@@ -609,7 +666,7 @@
*zt = '\0';
}
sqlite3_result_text(context, zo, -1, SQLITE_TRANSIENT);
- sqliteFree(zo);
+ sqlite3_free(zo);
}
}
@@ -648,7 +705,7 @@
sqlite3_result_text(context, zo, -1, SQLITE_TRANSIENT);
}else{
zll = strlen(zi);
- zo = sqliteMalloc(zll+ilen-zl+1);
+ zo = sqlite3_malloc(zll+ilen-zl+1);
zt = zo;
for(i=1; 2*i+zl<=ilen; ++i){
*(zt++) = ' ';
@@ -661,7 +718,7 @@
*zt = '\0';
}
sqlite3_result_text(context, zo, -1, SQLITE_TRANSIENT);
- sqliteFree(zo);
+ sqlite3_free(zo);
}
}
@@ -691,7 +748,7 @@
** maybe I could allocate less, but that would imply 2 passes, rather waste
** (possibly) some memory
*/
- zo = sqliteMalloc(strlen(zi1)+1);
+ zo = sqlite3_malloc(strlen(zi1)+1);
zot = zo;
z1 = zi1;
while( (c1=sqliteCharVal(z1))!=0 ){
@@ -710,7 +767,7 @@
*zot = '\0';
sqlite3_result_text(context, zo, -1, SQLITE_TRANSIENT);
- sqliteFree(zo);
+ sqlite3_free(zo);
}
}
@@ -826,11 +883,11 @@
cc=zt-z;
- rz = sqliteMalloc(zt-z+1);
+ rz = sqlite3_malloc(zt-z+1);
strncpy((char*) rz, (char*) z, zt-z);
*(rz+cc) = '\0';
sqlite3_result_text(context, (char*)rz, -1, SQLITE_TRANSIENT);
- sqliteFree(rz);
+ sqlite3_free(rz);
}
/*
@@ -873,10 +930,10 @@
sqliteNextChar(zt);
}
- rz = sqliteMalloc(ze-zt+1);
+ rz = sqlite3_malloc(ze-zt+1);
strcpy((char*) rz, (char*) (zt));
sqlite3_result_text(context, (char*)rz, -1, SQLITE_TRANSIENT);
- sqliteFree(rz);
+ sqlite3_free(rz);
}
#ifndef HAVE_TRIM
@@ -934,7 +991,7 @@
rz = sqlite3StrDup(z);
rtrim(rz);
sqlite3_result_text(context, rz, -1, SQLITE_TRANSIENT);
- sqliteFree(rz);
+ sqlite3_free(rz);
}
/*
@@ -955,7 +1012,7 @@
rz = sqlite3StrDup(z);
rtrim(rz);
sqlite3_result_text(context, ltrim(rz), -1, SQLITE_TRANSIENT);
- sqliteFree(rz);
+ sqlite3_free(rz);
}
#endif
@@ -965,11 +1022,11 @@
** All lengths in bytes.
** This is just an auxiliary function
*/
-static void _append(char **s1, int l1, const char *s2, int l2){
- *s1 = realloc(*s1, (l1+l2+1)*sizeof(char));
- strncpy((*s1)+l1, s2, l2);
- *(*(s1)+l1+l2) = '\0';
-}
+// static void _append(char **s1, int l1, const char *s2, int l2){
+// *s1 = realloc(*s1, (l1+l2+1)*sizeof(char));
+// strncpy((*s1)+l1, s2, l2);
+// *(*(s1)+l1+l2) = '\0';
+// }
#ifndef HAVE_TRIM
@@ -1037,7 +1094,7 @@
}
_append(&zo, lzo, zt1, lz1-(zt1-z1));
sqlite3_result_text(context, zo, -1, SQLITE_TRANSIENT);
- sqliteFree(zo);
+ sqlite3_free(zo);
}
#endif
@@ -1060,7 +1117,7 @@
}
z = sqlite3_value_text(argv[0]);
l = strlen(z);
- rz = sqliteMalloc(l+1);
+ rz = sqlite3_malloc(l+1);
rzt = rz+l;
*(rzt--) = '\0';
@@ -1074,7 +1131,7 @@
}
sqlite3_result_text(context, rz, -1, SQLITE_TRANSIENT);
- sqliteFree(rz);
+ sqlite3_free(rz);
}
/*
@@ -1434,7 +1491,7 @@
** external linkage.
*/
void sqlite3RegisterExtraFunctions(sqlite3 *db){
- static const struct {
+ static const struct FuncDef {
char *zName;
signed char nArg;
u8 argType; /* 0: none. 1: db 2: (-1) */
@@ -1501,7 +1558,7 @@
};
/* Aggregate functions */
- static const struct {
+ static const struct FuncDefAgg {
char *zName;
signed char nArg;
u8 argType;
@@ -1528,13 +1585,15 @@
/* LMH no error checking */
sqlite3_create_function(db, aFuncs[i].zName, aFuncs[i].nArg,
aFuncs[i].eTextRep, pArg, aFuncs[i].xFunc, 0, 0);
+#if 0
if( aFuncs[i].needCollSeq ){
- FuncDef *pFunc = sqlite3FindFunction(db, aFuncs[i].zName,
+ struct FuncDef *pFunc = sqlite3FindFunction(db, aFuncs[i].zName,
strlen(aFuncs[i].zName), aFuncs[i].nArg, aFuncs[i].eTextRep, 0);
if( pFunc && aFuncs[i].needCollSeq ){
pFunc->needCollSeq = 1;
}
}
+#endif
}
for(i=0; i<sizeof(aAggs)/sizeof(aAggs[0]); i++){
@@ -1547,64 +1606,16 @@
/* LMH no error checking */
sqlite3_create_function(db, aAggs[i].zName, aAggs[i].nArg, SQLITE_UTF8,
pArg, 0, aAggs[i].xStep, aAggs[i].xFinalize);
+#if 0
if( aAggs[i].needCollSeq ){
- FuncDef *pFunc = sqlite3FindFunction( db, aAggs[i].zName,
+ struct FuncDefAgg *pFunc = sqlite3FindFunction( db, aAggs[i].zName,
strlen(aAggs[i].zName), aAggs[i].nArg, SQLITE_UTF8, 0);
if( pFunc && aAggs[i].needCollSeq ){
pFunc->needCollSeq = 1;
}
}
+#endif
}
}
//#endif
-
-
-/* LMH salvaged from sqlite3 3.3.13 source code src/utf.c */
-#define READ_UTF8(zIn, c) { \
- int xtra; \
- c = *(zIn)++; \
- xtra = xtra_utf8_bytes[c]; \
- switch( xtra ){ \
- case 4: c = (int)0xFFFD; break; \
- case 3: c = (c<<6) + *(zIn)++; \
- case 2: c = (c<<6) + *(zIn)++; \
- case 1: c = (c<<6) + *(zIn)++; \
- c -= xtra_utf8_bits[xtra]; \
- if( (utf_mask[xtra]&c)==0 \
- || (c&0xFFFFF800)==0xD800 \
- || (c&0xFFFFFFFE)==0xFFFE ){ c = 0xFFFD; } \
- } \
-}
-int sqlite3ReadUtf8(const unsigned char *z){
- int c;
- READ_UTF8(z, c);
- return c;
-}
-
-#define SKIP_UTF8(zIn) { \
- zIn += (xtra_utf8_bytes[*(u8 *)zIn] + 1); \
-}
-
-/*
-** pZ is a UTF-8 encoded unicode string. If nByte is less than zero,
-** return the number of unicode characters in pZ up to (but not including)
-** the first 0x00 byte. If nByte is not less than zero, return the
-** number of unicode characters in the first nByte of pZ (or up to
-** the first 0x00, whichever comes first).
-*/
-int sqlite3utf8CharLen(const char *z, int nByte){
- int r = 0;
- const char *zTerm;
- if( nByte>=0 ){
- zTerm = &z[nByte];
- }else{
- zTerm = (const char *)(-1);
- }
- assert( z<=zTerm );
- while( *z!=0 && z<zTerm ){
- SKIP_UTF8(z);
- r++;
- }
- return r;
-}
diff -urN orig/map.c fixed/map.c
--- orig/map.c 2006-06-15 07:40:00.000000000 +0100
+++ fixed/map.c 2007-09-15 05:02:34.000000000 +0100
@@ -1,4 +1,7 @@
+
#include "map.h"
+#include <stdio.h>
+#include <stdlib.h>
map map_make(cmp_func cmp){
map r;
@@ -74,8 +77,8 @@
}
int int_cmp(const void *a, const void *b){
- i64 aa = *(i64 *)(a);
- i64 bb = *(i64 *)(b);
+ int64_t aa = *(int64_t *)(a);
+ int64_t bb = *(int64_t *)(b);
/* printf("cmp %d <=> %d\n",aa,bb); */
if(aa==bb)
return 0;
@@ -97,7 +100,7 @@
return 1;
}
-void print_elem(void *e, i64 c, void* p){
+void print_elem(void *e, int64_t c, void* p){
int ee = *(int*)(e);
- printf("%d => %d\n", ee,c);
+ printf("%d => %lld\n", ee,c);
}
diff -urN orig/map.h fixed/map.h
--- orig/map.h 2006-06-15 07:40:00.000000000 +0100
+++ fixed/map.h 2007-09-15 04:13:40.000000000 +0100
@@ -1,7 +1,7 @@
#ifndef _MAP_H_
#define _MAP_H_
-#include "sqliteInt.h"
+#include <stdint.h>
/*
** Simple binary tree implementation to use in median, mode and quartile calculations
@@ -9,13 +9,13 @@
*/
typedef int(*cmp_func)(const void *, const void *);
-typedef void(*map_iterator)(void*, i64, void*);
+typedef void(*map_iterator)(void*, int64_t, void*);
typedef struct node{
struct node *l;
struct node *r;
void* data;
- i64 count;
+ int64_t count;
} node;
typedef struct map{
-----------------------------------------------------------------------------
To unsubscribe, send email to [EMAIL PROTECTED]
-----------------------------------------------------------------------------