/ Check-in [05e3cced]
Login

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

Overview
Comment:Change the way the sqlite3_analyzer executable is built.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 05e3cced8a884e8bca6f208d2f09e335d3929eac
User & Date: dan 2011-09-21 16:43:07
Context
2011-09-21
17:04
Fix the sqlite3_analyzer target in the configure-generated Makefile. check-in: 256cdbdc user: drh tags: trunk
16:43
Change the way the sqlite3_analyzer executable is built. check-in: 05e3cced user: dan tags: trunk
2011-09-19
20:56
Minor comment change in the description of the different memory allocator options. No changes to code. check-in: 36be31ff user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to main.mk.

   514    514   
   515    515   # Rules for building test programs and for running tests
   516    516   #
   517    517   tclsqlite3:	$(TOP)/src/tclsqlite.c libsqlite3.a
   518    518   	$(TCCX) $(TCL_FLAGS) -DTCLSH=1 -o tclsqlite3 \
   519    519   		$(TOP)/src/tclsqlite.c libsqlite3.a $(LIBTCL) $(THREADLIB)
   520    520   
          521  +sqlite3_analyzer.c: sqlite3.c $(TOP)/src/test_stat.c $(TOP)/src/tclsqlite.c $(TOP)/tool/spaceanal.tcl
          522  +	echo "#define TCLSH 2" > $@
          523  +	cat sqlite3.c $(TOP)/src/test_stat.c $(TOP)/src/tclsqlite.c >> $@
          524  +	echo "static const char *tclsh_main_loop(void){" >> $@
          525  +	echo "static const char *zMainloop = " >> $@
          526  +	$(NAWK) -f $(TOP)/tool/tostr.awk $(TOP)/tool/spaceanal.tcl >> $@
          527  +	echo "; return zMainloop; }" >> $@
          528  +
          529  +sqlite3_analyzer$(EXE): sqlite3_analyzer.c spaceanal_tcl.h
          530  +	$(TCCX) $(TCL_FLAGS) sqlite3_analyzer.c -o $@ $(LIBTCL) $(THREADLIB) 
   521    531   
   522    532   # Rules to build the 'testfixture' application.
   523    533   #
   524    534   TESTFIXTURE_FLAGS  = -DSQLITE_TEST=1 -DSQLITE_CRASH_TEST=1
   525    535   TESTFIXTURE_FLAGS += -DSQLITE_SERVER=1 -DSQLITE_PRIVATE="" -DSQLITE_CORE 
   526    536   
   527    537   testfixture$(EXE): $(TESTSRC2) libsqlite3.a $(TESTSRC) $(TOP)/src/tclsqlite.c
................................................................................
   556    566   threadtest3$(EXE): sqlite3.o $(TOP)/test/threadtest3.c $(TOP)/test/tt3_checkpoint.c
   557    567   	$(TCCX) -O2 sqlite3.o $(TOP)/test/threadtest3.c \
   558    568   		-o threadtest3$(EXE) $(THREADLIB)
   559    569   
   560    570   threadtest: threadtest3$(EXE)
   561    571   	./threadtest3$(EXE)
   562    572   
   563         -sqlite3_analyzer$(EXE):	$(TOP)/src/tclsqlite.c sqlite3.c $(TESTSRC) \
   564         -			$(TOP)/tool/spaceanal.tcl
   565         -	$(NAWK) -f $(TOP)/tool/tostr.awk $(TOP)/tool/spaceanal.tcl \
   566         -		 >spaceanal_tcl.h
   567         -	$(TCCX) $(TCL_FLAGS) -DTCLSH=2 $(TESTFIXTURE_FLAGS)                    \
   568         -		-DSQLITE_TEST=1 -DSQLITE_PRIVATE=""                            \
   569         -		$(TESTSRC) $(TOP)/src/tclsqlite.c sqlite3.c                    \
   570         -		-o sqlite3_analyzer$(EXE)                                      \
   571         -		$(LIBTCL) $(THREADLIB)
   572         -
   573    573   TEST_EXTENSION = $(SHPREFIX)testloadext.$(SO)
   574    574   $(TEST_EXTENSION): $(TOP)/src/test_loadext.c
   575    575   	$(MKSHLIB) $(TOP)/src/test_loadext.c -o $(TEST_EXTENSION)
   576    576   
   577    577   extensiontest: testfixture$(EXE) $(TEST_EXTENSION)
   578    578   	./testfixture$(EXE) $(TOP)/test/loadext.test
   579    579   

Changes to src/tclsqlite.c.

  3535   3535   /*
  3536   3536   ** If the macro TCLSH is one, then put in code this for the
  3537   3537   ** "main" routine that will initialize Tcl and take input from
  3538   3538   ** standard input, or if a file is named on the command line
  3539   3539   ** the TCL interpreter reads and evaluates that file.
  3540   3540   */
  3541   3541   #if TCLSH==1
  3542         -static char zMainloop[] =
  3543         -  "set line {}\n"
  3544         -  "while {![eof stdin]} {\n"
  3545         -    "if {$line!=\"\"} {\n"
  3546         -      "puts -nonewline \"> \"\n"
  3547         -    "} else {\n"
  3548         -      "puts -nonewline \"% \"\n"
  3549         -    "}\n"
  3550         -    "flush stdout\n"
  3551         -    "append line [gets stdin]\n"
  3552         -    "if {[info complete $line]} {\n"
  3553         -      "if {[catch {uplevel #0 $line} result]} {\n"
  3554         -        "puts stderr \"Error: $result\"\n"
  3555         -      "} elseif {$result!=\"\"} {\n"
  3556         -        "puts $result\n"
         3542  +static const char *tclsh_main_loop(void){
         3543  +  static const char zMainloop[] =
         3544  +    "set line {}\n"
         3545  +    "while {![eof stdin]} {\n"
         3546  +      "if {$line!=\"\"} {\n"
         3547  +        "puts -nonewline \"> \"\n"
         3548  +      "} else {\n"
         3549  +        "puts -nonewline \"% \"\n"
         3550  +      "}\n"
         3551  +      "flush stdout\n"
         3552  +      "append line [gets stdin]\n"
         3553  +      "if {[info complete $line]} {\n"
         3554  +        "if {[catch {uplevel #0 $line} result]} {\n"
         3555  +          "puts stderr \"Error: $result\"\n"
         3556  +        "} elseif {$result!=\"\"} {\n"
         3557  +          "puts $result\n"
         3558  +        "}\n"
         3559  +        "set line {}\n"
         3560  +      "} else {\n"
         3561  +        "append line \\n\n"
  3557   3562         "}\n"
  3558         -      "set line {}\n"
  3559         -    "} else {\n"
  3560         -      "append line \\n\n"
  3561   3563       "}\n"
  3562         -  "}\n"
  3563         -;
         3564  +  ;
         3565  +  return zMainloop;
         3566  +}
  3564   3567   #endif
  3565   3568   #if TCLSH==2
  3566         -static char zMainloop[] = 
  3567         -#include "spaceanal_tcl.h"
  3568         -;
         3569  +static const char *tclsh_main_loop(void);
  3569   3570   #endif
  3570   3571   
  3571   3572   #ifdef SQLITE_TEST
  3572   3573   static void init_all(Tcl_Interp *);
  3573   3574   static int init_all_cmd(
  3574   3575     ClientData cd,
  3575   3576     Tcl_Interp *interp,
................................................................................
  3644   3645   */
  3645   3646   static void init_all(Tcl_Interp *interp){
  3646   3647     Sqlite3_Init(interp);
  3647   3648   
  3648   3649   #if defined(SQLITE_TEST) || defined(SQLITE_TCLMD5)
  3649   3650     Md5_Init(interp);
  3650   3651   #endif
         3652  +
         3653  +  /* Install the [register_dbstat_vtab] command to access the implementation
         3654  +  ** of virtual table dbstat (source file test_stat.c). This command is
         3655  +  ** required for testfixture and sqlite3_analyzer, but not by the production
         3656  +  ** Tcl extension.  */
         3657  +#if defined(SQLITE_TEST) || TCLSH==2
         3658  +  {
         3659  +    extern int SqlitetestStat_Init(Tcl_Interp*);
         3660  +    SqlitetestStat_Init(interp);
         3661  +  }
         3662  +#endif
  3651   3663   
  3652   3664   #ifdef SQLITE_TEST
  3653   3665     {
  3654   3666       extern int Sqliteconfig_Init(Tcl_Interp*);
  3655   3667       extern int Sqlitetest1_Init(Tcl_Interp*);
  3656   3668       extern int Sqlitetest2_Init(Tcl_Interp*);
  3657   3669       extern int Sqlitetest3_Init(Tcl_Interp*);
................................................................................
  3674   3686       extern int Sqlitetesttclvar_Init(Tcl_Interp*);
  3675   3687       extern int SqlitetestThread_Init(Tcl_Interp*);
  3676   3688       extern int SqlitetestOnefile_Init();
  3677   3689       extern int SqlitetestOsinst_Init(Tcl_Interp*);
  3678   3690       extern int Sqlitetestbackup_Init(Tcl_Interp*);
  3679   3691       extern int Sqlitetestintarray_Init(Tcl_Interp*);
  3680   3692       extern int Sqlitetestvfs_Init(Tcl_Interp *);
  3681         -    extern int SqlitetestStat_Init(Tcl_Interp*);
  3682   3693       extern int Sqlitetestrtree_Init(Tcl_Interp*);
  3683   3694       extern int Sqlitequota_Init(Tcl_Interp*);
  3684   3695       extern int Sqlitemultiplex_Init(Tcl_Interp*);
  3685   3696       extern int SqliteSuperlock_Init(Tcl_Interp*);
  3686   3697       extern int SqlitetestSyscall_Init(Tcl_Interp*);
  3687   3698       extern int Sqlitetestfuzzer_Init(Tcl_Interp*);
  3688   3699       extern int Sqlitetestwholenumber_Init(Tcl_Interp*);
................................................................................
  3718   3729       Sqlitetesttclvar_Init(interp);
  3719   3730       SqlitetestThread_Init(interp);
  3720   3731       SqlitetestOnefile_Init(interp);
  3721   3732       SqlitetestOsinst_Init(interp);
  3722   3733       Sqlitetestbackup_Init(interp);
  3723   3734       Sqlitetestintarray_Init(interp);
  3724   3735       Sqlitetestvfs_Init(interp);
  3725         -    SqlitetestStat_Init(interp);
  3726   3736       Sqlitetestrtree_Init(interp);
  3727   3737       Sqlitequota_Init(interp);
  3728   3738       Sqlitemultiplex_Init(interp);
  3729   3739       SqliteSuperlock_Init(interp);
  3730   3740       SqlitetestSyscall_Init(interp);
  3731   3741       Sqlitetestfuzzer_Init(interp);
  3732   3742       Sqlitetestwholenumber_Init(interp);
................................................................................
  3754   3764     Tcl_Interp *interp;
  3755   3765     
  3756   3766     /* Call sqlite3_shutdown() once before doing anything else. This is to
  3757   3767     ** test that sqlite3_shutdown() can be safely called by a process before
  3758   3768     ** sqlite3_initialize() is. */
  3759   3769     sqlite3_shutdown();
  3760   3770   
         3771  +  Tcl_FindExecutable(argv[0]);
         3772  +  interp = Tcl_CreateInterp();
         3773  +
  3761   3774   #if TCLSH==2
  3762   3775     sqlite3_config(SQLITE_CONFIG_SINGLETHREAD);
  3763   3776   #endif
  3764         -  Tcl_FindExecutable(argv[0]);
  3765   3777   
  3766         -  interp = Tcl_CreateInterp();
  3767   3778     init_all(interp);
  3768   3779     if( argc>=2 ){
  3769   3780       int i;
  3770   3781       char zArgc[32];
  3771   3782       sqlite3_snprintf(sizeof(zArgc), zArgc, "%d", argc-(3-TCLSH));
  3772   3783       Tcl_SetVar(interp,"argc", zArgc, TCL_GLOBAL_ONLY);
  3773   3784       Tcl_SetVar(interp,"argv0",argv[1],TCL_GLOBAL_ONLY);
................................................................................
  3780   3791         const char *zInfo = Tcl_GetVar(interp, "errorInfo", TCL_GLOBAL_ONLY);
  3781   3792         if( zInfo==0 ) zInfo = Tcl_GetStringResult(interp);
  3782   3793         fprintf(stderr,"%s: %s\n", *argv, zInfo);
  3783   3794         return 1;
  3784   3795       }
  3785   3796     }
  3786   3797     if( TCLSH==2 || argc<=1 ){
  3787         -    Tcl_GlobalEval(interp, zMainloop);
         3798  +    Tcl_GlobalEval(interp, tclsh_main_loop());
  3788   3799     }
  3789   3800     return 0;
  3790   3801   }
  3791   3802   #endif /* TCLSH */

Changes to src/test_stat.c.

    14     14   **
    15     15   ** The dbstat virtual table is used to extract low-level formatting
    16     16   ** information from an SQLite database in order to implement the
    17     17   ** "sqlite3_analyzer" utility.  See the ../tool/spaceanal.tcl script
    18     18   ** for an example implementation.
    19     19   */
    20     20   
    21         -#include "sqliteInt.h"
           21  +#ifndef SQLITE_AMALGAMATION
           22  +# include "sqliteInt.h"
           23  +#endif
    22     24   
    23     25   #ifndef SQLITE_OMIT_VIRTUALTABLE
    24     26   
    25     27   /*
    26     28   ** Page paths:
    27     29   ** 
    28     30   **   The value of the 'path' column describes the path taken from the 
................................................................................
   564    566     };
   565    567     sqlite3_create_module(db, "dbstat", &dbstat_module, 0);
   566    568     return SQLITE_OK;
   567    569   }
   568    570   
   569    571   #endif
   570    572   
   571         -#ifdef SQLITE_TEST
          573  +#if defined(SQLITE_TEST) || TCLSH==2
   572    574   #include <tcl.h>
   573    575   
   574    576   static int test_dbstat(
   575    577     void *clientData,
   576    578     Tcl_Interp *interp,
   577    579     int objc,
   578    580     Tcl_Obj *CONST objv[]
................................................................................
   600    602   #endif
   601    603   }
   602    604   
   603    605   int SqlitetestStat_Init(Tcl_Interp *interp){
   604    606     Tcl_CreateObjCommand(interp, "register_dbstat_vtab", test_dbstat, 0, 0);
   605    607     return TCL_OK;
   606    608   }
   607         -#endif
          609  +#endif /* if defined(SQLITE_TEST) || TCLSH==2 */
          610  +