Fix a use-after-free that could occur following an OOM introduced by [d8cedbe0].
[sqlite.git] / ext / lsm1 / tool / mklsm1c.tcl
blobd4a317b7003238e49ebc5d9ce521d86200cf877b
1 #!/bin/sh
2 # restart with tclsh \
3 exec tclsh "$0" "$@"
5 set srcdir [file dirname [file dirname [info script]]]
6 set G(src) [string map [list %dir% $srcdir] {
7 %dir%/lsm.h
8 %dir%/lsmInt.h
9 %dir%/lsm_vtab.c
10 %dir%/lsm_ckpt.c
11 %dir%/lsm_file.c
12 %dir%/lsm_log.c
13 %dir%/lsm_main.c
14 %dir%/lsm_mem.c
15 %dir%/lsm_mutex.c
16 %dir%/lsm_shared.c
17 %dir%/lsm_sorted.c
18 %dir%/lsm_str.c
19 %dir%/lsm_tree.c
20 %dir%/lsm_unix.c
21 %dir%/lsm_varint.c
22 %dir%/lsm_win32.c
25 set G(hdr) {
27 #if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_LSM1)
29 #if !defined(NDEBUG) && !defined(SQLITE_DEBUG)
30 # define NDEBUG 1
31 #endif
32 #if defined(NDEBUG) && defined(SQLITE_DEBUG)
33 # undef NDEBUG
34 #endif
38 set G(footer) {
40 #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_LSM1) */
43 #-------------------------------------------------------------------------
44 # Read and return the entire contents of text file $zFile from disk.
46 proc readfile {zFile} {
47 set fd [open $zFile]
48 set data [read $fd]
49 close $fd
50 return $data
53 proc lsm1c_init {zOut} {
54 global G
55 set G(fd) stdout
56 set G(fd) [open $zOut w]
58 puts -nonewline $G(fd) $G(hdr)
61 proc lsm1c_printfile {zIn} {
62 global G
63 set data [readfile $zIn]
64 set zTail [file tail $zIn]
65 puts $G(fd) "#line 1 \"$zTail\""
67 foreach line [split $data "\n"] {
68 if {[regexp {^# *include.*lsm} $line]} {
69 set line "/* $line */"
70 } elseif { [regexp {^(const )?[a-zA-Z][a-zA-Z0-9]* [*]?lsm[^_]} $line] } {
71 set line "static $line"
73 puts $G(fd) $line
77 proc lsm1c_close {} {
78 global G
79 puts -nonewline $G(fd) $G(footer)
80 if {$G(fd)!="stdout"} {
81 close $G(fd)
86 lsm1c_init lsm1.c
87 foreach f $G(src) { lsm1c_printfile $f }
88 lsm1c_close