/ Check-in [f2caff87]
Login

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

Overview
Comment:Fix the amalgamation so that it works with -DSQLITE_ENABLE_REDEF_IO. Change tclsqlite.c so that it can be appended to the amalgamation. Create a new amalgamation of header files for use by projects that want to redefine their own I/O interface using -DSQLITE_ENABLE_REDEF_IO. (CVS 3817)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: f2caff870c81c08ec85aae72986c231ee986b251
User & Date: drh 2007-04-05 21:58:33
Context
2007-04-06
01:03
Make sure the sqlite3BtreePrevious() routine terminates properly if the table is deleted out from under it. Ticket #2286. This bug was discovered while trying to increase test coverage from 98.5% to 99% - once again showing the value of full coverage testing. (CVS 3818) check-in: bebf8d2f user: drh tags: trunk
2007-04-05
21:58
Fix the amalgamation so that it works with -DSQLITE_ENABLE_REDEF_IO. Change tclsqlite.c so that it can be appended to the amalgamation. Create a new amalgamation of header files for use by projects that want to redefine their own I/O interface using -DSQLITE_ENABLE_REDEF_IO. (CVS 3817) check-in: f2caff87 user: drh tags: trunk
18:34
Add a target to the autoconf-generated makefile for amalgamation. (CVS 3816) check-in: 204e7d38 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to main.mk.

   250    250   	rm -rf tsrc
   251    251   	mkdir tsrc
   252    252   	cp -f $(SRC) $(TOP)/src/*.h tsrc 2>/dev/null
   253    253   	rm tsrc/sqlite.h.in tsrc/parse.y
   254    254   
   255    255   sqlite3.c:	target_source $(TOP)/tool/mksqlite3c.tcl
   256    256   	tclsh $(TOP)/tool/mksqlite3c.tcl
          257  +	cp sqlite3.c tclsqlite3.c
          258  +	cat $(TOP)/src/tclsqlite.c >>tclsqlite3.c
          259  +	tclsh $(TOP)/tool/mksqlite3internalh.tcl
   257    260   
   258    261   # Rules to build the LEMON compiler generator
   259    262   #
   260    263   lemon:	$(TOP)/tool/lemon.c $(TOP)/tool/lempar.c
   261    264   	$(BCC) -o lemon $(TOP)/tool/lemon.c
   262    265   	cp $(TOP)/tool/lempar.c .
   263    266   

Changes to src/os.c.

    12     12   **
    13     13   ** This file contains OS interface code that is common to all
    14     14   ** architectures.
    15     15   */
    16     16   #define _SQLITE_OS_C_ 1
    17     17   #include "sqliteInt.h"
    18     18   #include "os.h"
           19  +#undef _SQLITE_OS_C_
    19     20   
    20     21   /*
    21     22   ** The following routines are convenience wrappers around methods
    22     23   ** of the OsFile object.  This is mostly just syntactic sugar.  All
    23     24   ** of this would be completely automatic if SQLite were coded using
    24     25   ** C++ instead of plain old C.
    25     26   */

Changes to src/os.h.

   443    443   #ifdef SQLITE_OMIT_LOAD_EXTENSION
   444    444   # define IF_DLOPEN(X)  0
   445    445   #else
   446    446   # define IF_DLOPEN(X)  X
   447    447   #endif
   448    448   
   449    449   
   450         -#ifdef _SQLITE_OS_C_
          450  +#if defined(_SQLITE_OS_C_) || defined(SQLITE_AMALGAMATION)
   451    451     /*
   452    452     ** The os.c file implements the global virtual function table.
          453  +  ** We have to put this file here because the initializers
          454  +  ** (ex: sqlite3OsRandomSeed) are macros that are about to be
          455  +  ** redefined.
   453    456     */
   454    457     struct sqlite3OsVtbl sqlite3Os = {
   455    458       IF_DISKIO( sqlite3OsOpenReadWrite ),
   456    459       IF_DISKIO( sqlite3OsOpenExclusive ),
   457    460       IF_DISKIO( sqlite3OsOpenReadOnly ),
   458    461       IF_DISKIO( sqlite3OsDelete ),
   459    462       IF_DISKIO( sqlite3OsFileExists ),

Changes to src/tclsqlite.c.

     5      5   ** a legal notice, here is a blessing:
     6      6   **
     7      7   **    May you do good and not evil.
     8      8   **    May you find forgiveness for yourself and forgive others.
     9      9   **    May you share freely, never taking more than you give.
    10     10   **
    11     11   *************************************************************************
    12         -** A TCL Interface to SQLite
           12  +** A TCL Interface to SQLite.  Append this file to sqlite3.c and
           13  +** compile the whole thing to build a TCL-enabled version of SQLite.
    13     14   **
    14         -** $Id: tclsqlite.c,v 1.177 2007/03/29 12:19:12 danielk1977 Exp $
           15  +** $Id: tclsqlite.c,v 1.178 2007/04/05 21:58:33 drh Exp $
    15     16   */
    16         -#ifndef NO_TCL     /* Omit this whole file if TCL is unavailable */
    17         -
    18         -#include "sqliteInt.h"
    19         -#include "hash.h"
    20     17   #include "tcl.h"
    21         -#include <stdlib.h>
    22         -#include <string.h>
    23         -#include <assert.h>
    24         -#include <ctype.h>
           18  +
           19  +/*
           20  +** Some additional include files are needed if this file is not
           21  +** appended to the amalgamation.
           22  +*/
           23  +#ifndef SQLITE_AMALGAMATION
           24  +# include "sqliteInt.h"
           25  +# include "hash.h"
           26  +# include <stdlib.h>
           27  +# include <string.h>
           28  +# include <assert.h>
           29  +# include <ctype.h>
           30  +#endif
    25     31   
    26     32   /*
    27     33    * Windows needs to know which symbols to export.  Unix does not.
    28     34    * BUILD_sqlite should be undefined for Unix.
    29     35    */
    30     36   #ifdef BUILD_sqlite
    31     37   #undef TCL_STORAGE_CLASS
................................................................................
  2252   2258     }
  2253   2259     if( argc<=1 || TCLSH==2 ){
  2254   2260       Tcl_GlobalEval(interp, zMainloop);
  2255   2261     }
  2256   2262     return 0;
  2257   2263   }
  2258   2264   #endif /* TCLSH */
  2259         -
  2260         -#endif /* !defined(NO_TCL) */

Changes to tool/mksqlite3c.tcl.

    59     59   ** $cnt lines past this header comment.)  Additional code files may be
    60     60   ** needed if you want a wrapper to interface SQLite with your choice of
    61     61   ** programming language.  The code for the "sqlite3" command-line shell
    62     62   ** is also in a separate file.  This file contains only code for the core
    63     63   ** SQLite library.
    64     64   **
    65     65   ** This amalgamation was generated on $today.
    66         -*/}]
           66  +*/
           67  +#define SQLITE_AMALGAMATION 1}]
    67     68   
    68     69   # These are the header files used by SQLite.  The first time any of these 
    69     70   # files are seen in a #include statement in the C code, include the complete
    70     71   # text of the file in-line.  The file only needs to be included once.
    71     72   #
    72     73   foreach hdr {
    73     74      btree.h

Added tool/mksqlite3internalh.tcl.

            1  +#!/usr/bin/tclsh
            2  +#
            3  +# To build a single huge source file holding all of SQLite (or at
            4  +# least the core components - the test harness, shell, and TCL 
            5  +# interface are omitted.) first do
            6  +#
            7  +#      make target_source
            8  +#
            9  +# The make target above moves all of the source code files into
           10  +# a subdirectory named "tsrc".  (This script expects to find the files
           11  +# there and will not work if they are not found.)  There are a few
           12  +# generated C code files that are also added to the tsrc directory.
           13  +# For example, the "parse.c" and "parse.h" files to implement the
           14  +# the parser are derived from "parse.y" using lemon.  And the 
           15  +# "keywordhash.h" files is generated by a program named "mkkeywordhash".
           16  +#
           17  +# After the "tsrc" directory has been created and populated, run
           18  +# this script:
           19  +#
           20  +#      tclsh mksqlite3c.tcl
           21  +#
           22  +# The amalgamated SQLite code will be written into sqlite3.c
           23  +#
           24  +
           25  +# Begin by reading the "sqlite3.h" header file.  Count the number of lines
           26  +# in this file and extract the version number.  That information will be
           27  +# needed in order to generate the header of the amalgamation.
           28  +#
           29  +set in [open tsrc/sqlite3.h]
           30  +set cnt 0
           31  +set VERSION ?????
           32  +while {![eof $in]} {
           33  +  set line [gets $in]
           34  +  if {$line=="" && [eof $in]} break
           35  +  incr cnt
           36  +  regexp {#define\s+SQLITE_VERSION\s+"(.*)"} $line all VERSION
           37  +}
           38  +close $in
           39  +
           40  +# Open the output file and write a header comment at the beginning
           41  +# of the file.
           42  +#
           43  +set out [open sqlite3internal.h w]
           44  +set today [clock format [clock seconds] -format "%Y-%m-%d %H:%M:%S UTC" -gmt 1]
           45  +puts $out [subst \
           46  +{/******************************************************************************
           47  +** This file is an amalgamation of many private header files from SQLite
           48  +** version $VERSION. 
           49  +*/}]
           50  +
           51  +# These are the header files used by SQLite.  The first time any of these 
           52  +# files are seen in a #include statement in the C code, include the complete
           53  +# text of the file in-line.  The file only needs to be included once.
           54  +#
           55  +foreach hdr {
           56  +   btree.h
           57  +   hash.h
           58  +   keywordhash.h
           59  +   opcodes.h
           60  +   os_common.h
           61  +   os.h
           62  +   os_os2.h
           63  +   pager.h
           64  +   parse.h
           65  +   sqlite3ext.h
           66  +   sqlite3.h
           67  +   sqliteInt.h
           68  +   vdbe.h
           69  +   vdbeInt.h
           70  +} {
           71  +  set available_hdr($hdr) 1
           72  +}
           73  +
           74  +# 78 stars used for comment formatting.
           75  +set s78 \
           76  +{*****************************************************************************}
           77  +
           78  +# Insert a comment into the code
           79  +#
           80  +proc section_comment {text} {
           81  +  global out s78
           82  +  set n [string length $text]
           83  +  set nstar [expr {60 - $n}]
           84  +  set stars [string range $s78 0 $nstar]
           85  +  puts $out "/************** $text $stars/"
           86  +}
           87  +
           88  +# Read the source file named $filename and write it into the
           89  +# sqlite3.c output file.  If any #include statements are seen,
           90  +# process them approprately.
           91  +#
           92  +proc copy_file {filename} {
           93  +  global seen_hdr available_hdr out
           94  +  set tail [file tail $filename]
           95  +  section_comment "Begin file $tail"
           96  +  set in [open $filename r]
           97  +  while {![eof $in]} {
           98  +    set line [gets $in]
           99  +    if {[regexp {^#\s*include\s+["<]([^">]+)[">]} $line all hdr]} {
          100  +      if {[info exists available_hdr($hdr)]} {
          101  +        if {$available_hdr($hdr)} {
          102  +          section_comment "Include $hdr in the middle of $tail"
          103  +          copy_file tsrc/$hdr
          104  +          section_comment "Continuing where we left off in $tail"
          105  +        }
          106  +      } elseif {![info exists seen_hdr($hdr)]} {
          107  +        set seen_hdr($hdr) 1
          108  +        puts $out $line
          109  +      }
          110  +    } elseif {[regexp {^#ifdef __cplusplus} $line]} {
          111  +      puts $out "#if 0"
          112  +    } elseif {[regexp {^#line} $line]} {
          113  +      # Skip #line directives.
          114  +    } else {
          115  +      puts $out $line
          116  +    }
          117  +  }
          118  +  close $in
          119  +  section_comment "End of $tail"
          120  +}
          121  +
          122  +
          123  +# Process the source files.  Process files containing commonly
          124  +# used subroutines first in order to help the compiler find
          125  +# inlining opportunities.
          126  +#
          127  +foreach file {
          128  +   sqliteInt.h
          129  +   sqlite3.h
          130  +   btree.h
          131  +   hash.h
          132  +   os.h
          133  +   pager.h
          134  +   parse.h
          135  +   sqlite3ext.h
          136  +   vdbe.h
          137  +} {
          138  +  if {$available_hdr($file)} {
          139  +    copy_file tsrc/$file
          140  +  }
          141  +}
          142  +
          143  +close $out