Index: Makefile.msc ================================================================== --- Makefile.msc +++ Makefile.msc @@ -310,16 +310,16 @@ # to how the Tcl library functions are declared and exported (i.e. without # an explicit calling convention, which results in "cdecl"). # !IF $(USE_STDCALL)!=0 !IF "$(PLATFORM)"=="x86" -CORE_CCONV_OPTS = -Gz -DSQLITE_CDECL=__cdecl -SHELL_CCONV_OPTS = -Gz -DSQLITE_CDECL=__cdecl +CORE_CCONV_OPTS = -Gz -DSQLITE_CDECL=__cdecl -DSQLITE_STDCALL=__stdcall +SHELL_CCONV_OPTS = -Gz -DSQLITE_CDECL=__cdecl -DSQLITE_STDCALL=__stdcall !ELSE !IFNDEF PLATFORM -CORE_CCONV_OPTS = -Gz -DSQLITE_CDECL=__cdecl -SHELL_CCONV_OPTS = -Gz -DSQLITE_CDECL=__cdecl +CORE_CCONV_OPTS = -Gz -DSQLITE_CDECL=__cdecl -DSQLITE_STDCALL=__stdcall +SHELL_CCONV_OPTS = -Gz -DSQLITE_CDECL=__cdecl -DSQLITE_STDCALL=__stdcall !ELSE CORE_CCONV_OPTS = SHELL_CCONV_OPTS = !ENDIF !ENDIF Index: src/sqlite.h.in ================================================================== --- src/sqlite.h.in +++ src/sqlite.h.in @@ -41,22 +41,24 @@ extern "C" { #endif /* -** Add the ability to override 'extern' +** Provide the ability to override linkage features of the interface. */ #ifndef SQLITE_EXTERN # define SQLITE_EXTERN extern #endif - -/* -** Add the ability to override 'cdecl' -*/ +#ifndef SQLITE_API +# define SQLITE_API +#endif #ifndef SQLITE_CDECL # define SQLITE_CDECL #endif +#ifndef SQLITE_STDCALL +# define SQLITE_STDCALL +#endif /* ** These no-op macros are used in front of interfaces to mark those ** interfaces as either deprecated or experimental. New applications ** should not use deprecated interfaces - they are supported for backwards Index: tool/mksqlite3c-noext.tcl ================================================================== --- tool/mksqlite3c-noext.tcl +++ tool/mksqlite3c-noext.tcl @@ -78,13 +78,10 @@ #define SQLITE_AMALGAMATION 1}] if {$addstatic} { puts $out \ {#ifndef SQLITE_PRIVATE # define SQLITE_PRIVATE static -#endif -#ifndef SQLITE_API -# define SQLITE_API #endif} } # These are the header files used by SQLite. The first time any of these # files are seen in a #include statement in the C code, include the complete @@ -104,22 +101,42 @@ os_win.h os.h pager.h parse.h pcache.h + pragma.h sqlite3ext.h sqlite3.h sqliteicu.h sqliteInt.h sqliteLimit.h vdbe.h vdbeInt.h + vxworks.h wal.h + whereInt.h } { set available_hdr($hdr) 1 } set available_hdr(sqliteInt.h) 0 + +# These headers should be copied into the amalgamation without modifying any +# of their function declarations or definitions. +set varonly_hdr(sqlite3.h) 1 + +# These are the functions that accept a variable number of arguments. They +# always need to use the "cdecl" calling convention even when another calling +# convention (e.g. "stcall") is being used for the rest of the library. +set cdecllist { + sqlite3_config + sqlite3_db_config + sqlite3_log + sqlite3_mprintf + sqlite3_snprintf + sqlite3_test_control + sqlite3_vtab_config +} # 78 stars used for comment formatting. set s78 \ {*****************************************************************************} @@ -133,25 +150,25 @@ puts $out "/************** $text $stars/" } # Read the source file named $filename and write it into the # sqlite3.c output file. If any #include statements are seen, -# process them approprately. +# process them appropriately. # proc copy_file {filename} { - global seen_hdr available_hdr out addstatic linemacros + global seen_hdr available_hdr varonly_hdr cdecllist out addstatic linemacros set ln 0 set tail [file tail $filename] section_comment "Begin file $tail" if {$linemacros} {puts $out "#line 1 \"$filename\""} set in [open $filename r] set varpattern {^[a-zA-Z][a-zA-Z_0-9 *]+(sqlite3[_a-zA-Z0-9]+)(\[|;| =)} - set declpattern {[a-zA-Z][a-zA-Z_0-9 ]+ \**(sqlite3[_a-zA-Z0-9]+)\(} + set declpattern {([a-zA-Z][a-zA-Z_0-9 ]+ \**)(sqlite3[_a-zA-Z0-9]+)(\(.*)} if {[file extension $filename]==".h"} { set declpattern " *$declpattern" } - set declpattern ^$declpattern + set declpattern ^$declpattern\$ while {![eof $in]} { set line [gets $in] incr ln if {[regexp {^\s*#\s*include\s+["<]([^">]+)[">]} $line all hdr]} { if {[info exists available_hdr($hdr)]} { @@ -163,46 +180,71 @@ copy_file tsrc/$hdr section_comment "Continuing where we left off in $tail" if {$linemacros} {puts $out "#line [expr {$ln+1}] \"$filename\""} } } elseif {![info exists seen_hdr($hdr)]} { - set seen_hdr($hdr) 1 + if {![regexp {/\*\s+amalgamator:\s+dontcache\s+\*/} $line]} { + set seen_hdr($hdr) 1 + } + puts $out $line + } elseif {[regexp {/\*\s+amalgamator:\s+keep\s+\*/} $line]} { + # This include file must be kept because there was a "keep" + # directive inside of a line comment. puts $out $line } else { - puts $out "/* $line */" + # Comment out the entire line, replacing any nested comment + # begin/end markers with the harmless substring "**". + puts $out "/* [string map [list /* ** */ **] $line] */" } } elseif {[regexp {^#ifdef __cplusplus} $line]} { puts $out "#if 0" } elseif {!$linemacros && [regexp {^#line} $line]} { # Skip #line directives. } elseif {$addstatic && ![regexp {^(static|typedef)} $line]} { - regsub {^SQLITE_API } $line {} line - if {[regexp $declpattern $line all funcname]} { + # Skip adding the SQLITE_PRIVATE or SQLITE_API keyword before + # functions if this header file does not need it. + if {![info exists varonly_hdr($tail)] + && [regexp $declpattern $line all rettype funcname rest]} { + regsub {^SQLITE_API } $line {} line # Add the SQLITE_PRIVATE or SQLITE_API keyword before functions. # so that linkage can be modified at compile-time. if {[regexp {^sqlite3_} $funcname]} { - puts $out "SQLITE_API $line" + set line SQLITE_API + append line " " [string trim $rettype] + if {[string index $rettype end] ne "*"} { + append line " " + } + if {[lsearch -exact $cdecllist $funcname] >= 0} { + append line SQLITE_CDECL + } else { + append line SQLITE_STDCALL + } + append line " " $funcname $rest + puts $out $line } else { puts $out "SQLITE_PRIVATE $line" } } elseif {[regexp $varpattern $line all varname]} { - # Add the SQLITE_PRIVATE before variable declarations or - # definitions for internal use - if {![regexp {^sqlite3_} $varname]} { - regsub {^extern } $line {} line - puts $out "SQLITE_PRIVATE $line" - } else { - if {[regexp {const char sqlite3_version\[\];} $line]} { - set line {const char sqlite3_version[] = SQLITE_VERSION;} - } - regsub {^SQLITE_EXTERN } $line {} line - puts $out "SQLITE_API $line" - } - } elseif {[regexp {^(SQLITE_EXTERN )?void \(\*sqlite3IoTrace\)} $line]} { - regsub {^SQLITE_EXTERN } $line {} line - puts $out "SQLITE_PRIVATE $line" - } elseif {[regexp {^void \(\*sqlite3Os} $line]} { + # Add the SQLITE_PRIVATE before variable declarations or + # definitions for internal use + regsub {^SQLITE_API } $line {} line + if {![regexp {^sqlite3_} $varname]} { + regsub {^extern } $line {} line + puts $out "SQLITE_PRIVATE $line" + } else { + if {[regexp {const char sqlite3_version\[\];} $line]} { + set line {const char sqlite3_version[] = SQLITE_VERSION;} + } + regsub {^SQLITE_EXTERN } $line {} line + puts $out "SQLITE_API $line" + } + } elseif {[regexp {^(SQLITE_EXTERN )?void \(\*sqlite3IoTrace\)} $line]} { + regsub {^SQLITE_API } $line {} line + regsub {^SQLITE_EXTERN } $line {} line + puts $out $line + } elseif {[regexp {^void \(\*sqlite3Os} $line]} { + regsub {^SQLITE_API } $line {} line puts $out "SQLITE_PRIVATE $line" } else { puts $out $line } } else { Index: tool/mksqlite3c.tcl ================================================================== --- tool/mksqlite3c.tcl +++ tool/mksqlite3c.tcl @@ -78,13 +78,10 @@ #define SQLITE_AMALGAMATION 1}] if {$addstatic} { puts $out \ {#ifndef SQLITE_PRIVATE # define SQLITE_PRIVATE static -#endif -#ifndef SQLITE_API -# define SQLITE_API #endif} } # These are the header files used by SQLite. The first time any of these # files are seen in a #include statement in the C code, include the complete @@ -124,10 +121,27 @@ whereInt.h } { set available_hdr($hdr) 1 } set available_hdr(sqliteInt.h) 0 + +# These headers should be copied into the amalgamation without modifying any +# of their function declarations or definitions. +set varonly_hdr(sqlite3.h) 1 + +# These are the functions that accept a variable number of arguments. They +# always need to use the "cdecl" calling convention even when another calling +# convention (e.g. "stcall") is being used for the rest of the library. +set cdecllist { + sqlite3_config + sqlite3_db_config + sqlite3_log + sqlite3_mprintf + sqlite3_snprintf + sqlite3_test_control + sqlite3_vtab_config +} # 78 stars used for comment formatting. set s78 \ {*****************************************************************************} @@ -144,22 +158,22 @@ # Read the source file named $filename and write it into the # sqlite3.c output file. If any #include statements are seen, # process them appropriately. # proc copy_file {filename} { - global seen_hdr available_hdr out addstatic linemacros + global seen_hdr available_hdr varonly_hdr cdecllist out addstatic linemacros set ln 0 set tail [file tail $filename] section_comment "Begin file $tail" if {$linemacros} {puts $out "#line 1 \"$filename\""} set in [open $filename r] set varpattern {^[a-zA-Z][a-zA-Z_0-9 *]+(sqlite3[_a-zA-Z0-9]+)(\[|;| =)} - set declpattern {[a-zA-Z][a-zA-Z_0-9 ]+ \**(sqlite3[_a-zA-Z0-9]+)\(} + set declpattern {([a-zA-Z][a-zA-Z_0-9 ]+ \**)(sqlite3[_a-zA-Z0-9]+)(\(.*)} if {[file extension $filename]==".h"} { set declpattern " *$declpattern" } - set declpattern ^$declpattern + set declpattern ^$declpattern\$ while {![eof $in]} { set line [gets $in] incr ln if {[regexp {^\s*#\s*include\s+["<]([^">]+)[">]} $line all hdr]} { if {[info exists available_hdr($hdr)]} { @@ -189,36 +203,53 @@ } elseif {[regexp {^#ifdef __cplusplus} $line]} { puts $out "#if 0" } elseif {!$linemacros && [regexp {^#line} $line]} { # Skip #line directives. } elseif {$addstatic && ![regexp {^(static|typedef)} $line]} { - regsub {^SQLITE_API } $line {} line - if {[regexp $declpattern $line all funcname]} { + # Skip adding the SQLITE_PRIVATE or SQLITE_API keyword before + # functions if this header file does not need it. + if {![info exists varonly_hdr($tail)] + && [regexp $declpattern $line all rettype funcname rest]} { + regsub {^SQLITE_API } $line {} line # Add the SQLITE_PRIVATE or SQLITE_API keyword before functions. # so that linkage can be modified at compile-time. if {[regexp {^sqlite3_} $funcname]} { - puts $out "SQLITE_API $line" + set line SQLITE_API + append line " " [string trim $rettype] + if {[string index $rettype end] ne "*"} { + append line " " + } + if {[lsearch -exact $cdecllist $funcname] >= 0} { + append line SQLITE_CDECL + } else { + append line SQLITE_STDCALL + } + append line " " $funcname $rest + puts $out $line } else { puts $out "SQLITE_PRIVATE $line" } } elseif {[regexp $varpattern $line all varname]} { - # Add the SQLITE_PRIVATE before variable declarations or - # definitions for internal use - if {![regexp {^sqlite3_} $varname]} { - regsub {^extern } $line {} line - puts $out "SQLITE_PRIVATE $line" - } else { - if {[regexp {const char sqlite3_version\[\];} $line]} { - set line {const char sqlite3_version[] = SQLITE_VERSION;} - } - regsub {^SQLITE_EXTERN } $line {} line - puts $out "SQLITE_API $line" - } - } elseif {[regexp {^(SQLITE_EXTERN )?void \(\*sqlite3IoTrace\)} $line]} { + # Add the SQLITE_PRIVATE before variable declarations or + # definitions for internal use + regsub {^SQLITE_API } $line {} line + if {![regexp {^sqlite3_} $varname]} { + regsub {^extern } $line {} line + puts $out "SQLITE_PRIVATE $line" + } else { + if {[regexp {const char sqlite3_version\[\];} $line]} { + set line {const char sqlite3_version[] = SQLITE_VERSION;} + } + regsub {^SQLITE_EXTERN } $line {} line + puts $out "SQLITE_API $line" + } + } elseif {[regexp {^(SQLITE_EXTERN )?void \(\*sqlite3IoTrace\)} $line]} { + regsub {^SQLITE_API } $line {} line regsub {^SQLITE_EXTERN } $line {} line puts $out $line } elseif {[regexp {^void \(\*sqlite3Os} $line]} { + regsub {^SQLITE_API } $line {} line puts $out "SQLITE_PRIVATE $line" } else { puts $out $line } } else { Index: tool/mksqlite3h.tcl ================================================================== --- tool/mksqlite3h.tcl +++ tool/mksqlite3h.tcl @@ -61,19 +61,32 @@ close $in # Set up patterns for recognizing API declarations. # set varpattern {^[a-zA-Z][a-zA-Z_0-9 *]+sqlite3_[_a-zA-Z0-9]+(\[|;| =)} -set declpattern {^ *[a-zA-Z][a-zA-Z_0-9 ]+ \**sqlite3_[_a-zA-Z0-9]+\(} +set declpattern {^ *([a-zA-Z][a-zA-Z_0-9 ]+ \**)(sqlite3_[_a-zA-Z0-9]+)(\(.*)$} # Force the output to use unix line endings, even on Windows. fconfigure stdout -translation lf set filelist [subst { $TOP/src/sqlite.h.in $TOP/ext/rtree/sqlite3rtree.h }] + +# These are the functions that accept a variable number of arguments. They +# always need to use the "cdecl" calling convention even when another calling +# convention (e.g. "stcall") is being used for the rest of the library. +set cdecllist { + sqlite3_config + sqlite3_db_config + sqlite3_log + sqlite3_mprintf + sqlite3_snprintf + sqlite3_test_control + sqlite3_vtab_config +} # Process the source files. # foreach file $filelist { set in [open $file] @@ -87,25 +100,27 @@ if {[string match {*#include**} $line]} continue regsub -- --VERS-- $line $zVersion line regsub -- --VERSION-NUMBER-- $line $nVersion line regsub -- --SOURCE-ID-- $line "$zDate $zUuid" line - - if {[regexp {define SQLITE_EXTERN extern} $line]} { - puts $line - puts [gets $in] - puts "" - puts "#ifndef SQLITE_API" - puts "# define SQLITE_API" - puts "#endif" - set line "" - } - - if {([regexp $varpattern $line] && ![regexp {^ *typedef} $line]) - || ([regexp $declpattern $line]) - } { + + if {[regexp $varpattern $line] && ![regexp {^ *typedef} $line]} { set line "SQLITE_API $line" + } else { + if {[regexp $declpattern $line all rettype funcname rest]} { + set line SQLITE_API + append line " " [string trim $rettype] + if {[string index $rettype end] ne "*"} { + append line " " + } + if {[lsearch -exact $cdecllist $funcname] >= 0} { + append line SQLITE_CDECL + } else { + append line SQLITE_STDCALL + } + append line " " $funcname $rest + } } puts $line } close $in }