/ Check-in [860fc393]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Make "test_regexp.c" into a loadable extension and move it over to ext/misc/regexp.c. Add the "load_static_extension" command for testing purposes.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | std-ext
Files: files | file ages | folders
SHA1:860fc393bff27045e0593c3c51bf5577accd0b79
User & Date: drh 2013-04-23 20:10:13
Context
2013-04-25
11:58
Make test_wholenumber.c into a loadable extension and move it to ext/misc/wholenumber.c. check-in: efcc9dd0 user: drh tags: std-ext
2013-04-23
20:10
Make "test_regexp.c" into a loadable extension and move it over to ext/misc/regexp.c. Add the "load_static_extension" command for testing purposes. check-in: 860fc393 user: drh tags: std-ext
2013-04-22
23:38
Fix harmless compiler warnings. check-in: 1a1cf5aa user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Name change from src/test_regexp.c to ext/misc/regexp.c.

    45     45   ** exhibits exponential behavior.  Note that the X{p,q} operator expands
    46     46   ** to p copies of X following by q-p copies of X? and that the size of the
    47     47   ** regular expression in the O(N*M) performance bound is computed after
    48     48   ** this expansion.
    49     49   */
    50     50   #include <string.h>
    51     51   #include <stdlib.h>
    52         -#include "sqlite3.h"
           52  +#include "sqlite3ext.h"
           53  +SQLITE_EXTENSION_INIT1
           54  +
           55  +/*
           56  +** The following #defines change the names of some functions implemented in
           57  +** this file to prevent name collisions with C-library functions of the
           58  +** same name.
           59  +*/
           60  +#define re_match   sqlite3re_match
           61  +#define re_compile sqlite3re_compile
           62  +#define re_free    sqlite3re_free
    53     63   
    54     64   /* The end-of-input character */
    55     65   #define RE_EOF            0    /* End of input */
    56     66   
    57     67   /* The NFA is implemented as sequence of opcodes taken from the following
    58     68   ** set.  Each opcode has a single integer argument.
    59     69   */
................................................................................
   171    181   static int re_space_char(int c){
   172    182     return c==' ' || c=='\t' || c=='\n' || c=='\r' || c=='\v' || c=='\f';
   173    183   }
   174    184   
   175    185   /* Run a compiled regular expression on the zero-terminated input
   176    186   ** string zIn[].  Return true on a match and false if there is no match.
   177    187   */
   178         -int re_match(ReCompiled *pRe, const unsigned char *zIn, int nIn){
          188  +static int re_match(ReCompiled *pRe, const unsigned char *zIn, int nIn){
   179    189     ReStateSet aStateSet[2], *pThis, *pNext;
   180    190     ReStateNumber aSpace[100];
   181    191     ReStateNumber *pToFree;
   182    192     unsigned int i = 0;
   183    193     unsigned int iSwap = 0;
   184    194     int c = RE_EOF+1;
   185    195     int cPrev = 0;
................................................................................
   714    724     zStr = (const unsigned char*)sqlite3_value_text(argv[1]);
   715    725     if( zStr!=0 ){
   716    726       sqlite3_result_int(context, re_match(pRe, zStr, -1));
   717    727     }
   718    728   }
   719    729   
   720    730   /*
   721         -** Invoke this routine in order to install the REGEXP function in an
          731  +** Invoke this routine to register the regexp() function with the
   722    732   ** SQLite database connection.
   723         -**
   724         -** Use:
   725         -**
   726         -**      sqlite3_auto_extension(sqlite3_add_regexp_func);
   727         -**
   728         -** to cause this extension to be automatically loaded into each new
   729         -** database connection.
   730    733   */
   731         -int sqlite3_add_regexp_func(sqlite3 *db){
   732         -  return sqlite3_create_function(db, "regexp", 2, SQLITE_UTF8, 0,
          734  +#ifdef _WIN32
          735  +__declspec(dllexport)
          736  +#endif
          737  +int sqlite3_regexp_init(
          738  +  sqlite3 *db, 
          739  +  char **pzErrMsg, 
          740  +  const sqlite3_api_routines *pApi
          741  +){
          742  +  int rc = SQLITE_OK;
          743  +  SQLITE_EXTENSION_INIT2(pApi);
          744  +  rc = sqlite3_create_function(db, "regexp", 2, SQLITE_UTF8, 0,
   733    745                                    re_sql_func, 0, 0);
          746  +  return rc;
   734    747   }
   735         -
   736         -
   737         -/***************************** Test Code ***********************************/
   738         -#ifdef SQLITE_TEST
   739         -#include <tcl.h>
   740         -extern int getDbPointer(Tcl_Interp *interp, const char *zA, sqlite3 **ppDb);
   741         -
   742         -/* Implementation of the TCL command:
   743         -**
   744         -**      sqlite3_add_regexp_func $DB
   745         -*/
   746         -static int tclSqlite3AddRegexpFunc(
   747         -  void * clientData,
   748         -  Tcl_Interp *interp,
   749         -  int objc,
   750         -  Tcl_Obj *CONST objv[]
   751         -){
   752         -  sqlite3 *db;
   753         -  if( objc!=2 ){
   754         -    Tcl_WrongNumArgs(interp, 1, objv, "DB");
   755         -    return TCL_ERROR;
   756         -  }
   757         -  if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR;
   758         -  sqlite3_add_regexp_func(db);
   759         -  return TCL_OK;
   760         -}
   761         -
   762         -/* Register the sqlite3_add_regexp_func TCL command with the TCL interpreter.
   763         -*/
   764         -int Sqlitetestregexp_Init(Tcl_Interp *interp){
   765         -  Tcl_CreateObjCommand(interp, "sqlite3_add_regexp_func",
   766         -                       tclSqlite3AddRegexpFunc, 0, 0);
   767         -  return TCL_OK;
   768         -}
   769         -#endif /* SQLITE_TEST */
   770         -/**************************** End Of Test Code *******************************/

Changes to main.mk.

   252    252     $(TOP)/src/test_malloc.c \
   253    253     $(TOP)/src/test_multiplex.c \
   254    254     $(TOP)/src/test_mutex.c \
   255    255     $(TOP)/src/test_onefile.c \
   256    256     $(TOP)/src/test_osinst.c \
   257    257     $(TOP)/src/test_pcache.c \
   258    258     $(TOP)/src/test_quota.c \
   259         -  $(TOP)/src/test_regexp.c \
          259  +  $(TOP)/ext/misc/regexp.c \
   260    260     $(TOP)/src/test_rtree.c \
   261    261     $(TOP)/src/test_schema.c \
   262    262     $(TOP)/src/test_server.c \
   263    263     $(TOP)/src/test_stat.c \
   264    264     $(TOP)/src/test_sqllog.c \
   265    265     $(TOP)/src/test_superlock.c \
   266    266     $(TOP)/src/test_syscall.c \

Changes to src/tclsqlite.c.

  3681   3681       extern int Sqlitetestrtree_Init(Tcl_Interp*);
  3682   3682       extern int Sqlitequota_Init(Tcl_Interp*);
  3683   3683       extern int Sqlitemultiplex_Init(Tcl_Interp*);
  3684   3684       extern int SqliteSuperlock_Init(Tcl_Interp*);
  3685   3685       extern int SqlitetestSyscall_Init(Tcl_Interp*);
  3686   3686       extern int Sqlitetestfuzzer_Init(Tcl_Interp*);
  3687   3687       extern int Sqlitetestwholenumber_Init(Tcl_Interp*);
  3688         -    extern int Sqlitetestregexp_Init(Tcl_Interp*);
  3689   3688   
  3690   3689   #if defined(SQLITE_ENABLE_FTS3) || defined(SQLITE_ENABLE_FTS4)
  3691   3690       extern int Sqlitetestfts3_Init(Tcl_Interp *interp);
  3692   3691   #endif
  3693   3692   
  3694   3693   #ifdef SQLITE_ENABLE_ZIPVFS
  3695   3694       extern int Zipvfs_Init(Tcl_Interp*);
................................................................................
  3726   3725       Sqlitetestrtree_Init(interp);
  3727   3726       Sqlitequota_Init(interp);
  3728   3727       Sqlitemultiplex_Init(interp);
  3729   3728       SqliteSuperlock_Init(interp);
  3730   3729       SqlitetestSyscall_Init(interp);
  3731   3730       Sqlitetestfuzzer_Init(interp);
  3732   3731       Sqlitetestwholenumber_Init(interp);
  3733         -    Sqlitetestregexp_Init(interp);
  3734   3732   
  3735   3733   #if defined(SQLITE_ENABLE_FTS3) || defined(SQLITE_ENABLE_FTS4)
  3736   3734       Sqlitetestfts3_Init(interp);
  3737   3735   #endif
  3738   3736   
  3739   3737       Tcl_CreateObjCommand(
  3740   3738           interp, "load_testfixture_extensions", init_all_cmd, 0, 0

Changes to src/test1.c.

  6040   6040         Tcl_AppendResult(interp, " ", aOpt[i].zOptName);
  6041   6041       }
  6042   6042       return TCL_ERROR;
  6043   6043     }
  6044   6044     sqlite3_test_control(SQLITE_TESTCTRL_OPTIMIZATIONS, db, mask);
  6045   6045     return TCL_OK;
  6046   6046   }
         6047  +
         6048  +typedef struct sqlite3_api_routines sqlite3_api_routines;
         6049  +/*
         6050  +**     load_static_extension DB NAME
         6051  +**
         6052  +** Load an extension that is statically linked.
         6053  +*/
         6054  +static int tclLoadStaticExtensionCmd(
         6055  +  void * clientData,
         6056  +  Tcl_Interp *interp,
         6057  +  int objc,
         6058  +  Tcl_Obj *CONST objv[]
         6059  +){
         6060  +  extern int sqlite3_regexp_init(sqlite3*,char**,const sqlite3_api_routines*);
         6061  +  static const struct {
         6062  +    const char *zExtName;
         6063  +    int (*pInit)(sqlite3*,char**,const sqlite3_api_routines*);
         6064  +  } aExtension[] = {
         6065  +    {  "regexp",    sqlite3_regexp_init },
         6066  +  };
         6067  +  sqlite3 *db;
         6068  +  const char *zName;
         6069  +  int i, rc;
         6070  +  char *zErrMsg = 0;
         6071  +  if( objc!=3 ){
         6072  +    Tcl_WrongNumArgs(interp, 1, objv, "DB NAME");
         6073  +    return TCL_ERROR;
         6074  +  }
         6075  +  if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR;
         6076  +  zName = Tcl_GetString(objv[2]);
         6077  +  for(i=0; i<ArraySize(aExtension); i++){
         6078  +    if( strcmp(zName, aExtension[i].zExtName)==0 ) break;
         6079  +  }
         6080  +  if( i>=ArraySize(aExtension) ){
         6081  +    Tcl_AppendResult(interp, "no such extension: ", zName, (char*)0);
         6082  +    return TCL_ERROR;
         6083  +  }
         6084  +  rc = aExtension[i].pInit(db, &zErrMsg, 0);
         6085  +  if( rc!=SQLITE_OK || zErrMsg ){
         6086  +    Tcl_AppendResult(interp, "initialization of ", zName, " failed: ", zErrMsg,
         6087  +                     (char*)0);
         6088  +    sqlite3_free(zErrMsg);
         6089  +    return TCL_ERROR;
         6090  +  }
         6091  +  return TCL_OK;
         6092  +}
         6093  +
  6047   6094   
  6048   6095   /*
  6049   6096   ** Register commands with the TCL interpreter.
  6050   6097   */
  6051   6098   int Sqlitetest1_Init(Tcl_Interp *interp){
  6052   6099     extern int sqlite3_search_count;
  6053   6100     extern int sqlite3_found_count;
................................................................................
  6262   6309   #ifndef SQLITE_OMIT_EXPLAIN
  6263   6310        { "print_explain_query_plan", test_print_eqp, 0  },
  6264   6311   #endif
  6265   6312        { "sqlite3_test_control", test_test_control },
  6266   6313   #if SQLITE_OS_UNIX
  6267   6314        { "getrusage", test_getrusage },
  6268   6315   #endif
         6316  +     { "load_static_extension", tclLoadStaticExtensionCmd },
  6269   6317     };
  6270   6318     static int bitmask_size = sizeof(Bitmask)*8;
  6271   6319     int i;
  6272   6320     extern int sqlite3_sync_count, sqlite3_fullsync_count;
  6273   6321     extern int sqlite3_opentemp_count;
  6274   6322     extern int sqlite3_like_count;
  6275   6323     extern int sqlite3_xferopt_count;

Changes to test/regexp1.test.

    12     12   # This file implements test for the REGEXP operator in test_regexp.c.
    13     13   #
    14     14   
    15     15   set testdir [file dirname $argv0]
    16     16   source $testdir/tester.tcl
    17     17   
    18     18   do_test regexp1-1.1 {
    19         -  sqlite3_add_regexp_func db
           19  +  load_static_extension db regexp
    20     20     db eval {
    21     21       CREATE TABLE t1(x INTEGER PRIMARY KEY, y TEXT);
    22     22       INSERT INTO t1 VALUES(1, 'For since by man came death,');
    23     23       INSERT INTO t1 VALUES(2, 'by man came also the resurrection of the dead.');
    24     24       INSERT INTO t1 VALUES(3, 'For as in Adam all die,');
    25     25       INSERT INTO t1 VALUES(4, 'even so in Christ shall all be made alive.');
    26     26