Fossil SCM

Made a few more functions static. th1 ob doc additions.

stephan 2012-07-15 12:52 th1-query-api
Commit 8027581c5e9e8754d9a629bc94b3baa7980d9e61
2 files changed +8 -8 +19 -8
+8 -8
--- src/th_main.c
+++ src/th_main.c
@@ -851,27 +851,27 @@
851851
** by this function.
852852
**
853853
** If interp is destroyed before all statements are finalized,
854854
** it will finalize them but may emit a warning message.
855855
*/
856
-int Th_AddStmt(Th_Interp *interp, sqlite3_stmt * pStmt);
856
+static int Th_AddStmt(Th_Interp *interp, sqlite3_stmt * pStmt);
857857
858858
/*
859859
** Expects stmtId to be a statement identifier returned by
860860
** Th_AddStmt(). On success, finalizes the statement and returns 0.
861861
** On error (statement not found) non-0 is returned. After this
862862
** call, some subsequent call to Th_AddStmt() may return the
863863
** same statement ID.
864864
*/
865
-int Th_FinalizeStmt(Th_Interp *interp, int stmtId);
865
+static int Th_FinalizeStmt(Th_Interp *interp, int stmtId);
866866
867867
/*
868868
** Fetches the statement with the given ID, as returned by
869869
** Th_AddStmt(). Returns NULL if stmtId does not refer (or no longer
870870
** refers) to a statement added via Th_AddStmt().
871871
*/
872
-sqlite3_stmt * Th_GetStmt(Th_Interp *interp, int stmtId);
872
+static sqlite3_stmt * Th_GetStmt(Th_Interp *interp, int stmtId);
873873
874874
875875
struct Th_Sqlite {
876876
sqlite3_stmt ** aStmt;
877877
int nStmt;
@@ -882,11 +882,11 @@
882882
static Th_Sqlite * Th_sqlite_manager( Th_Interp * interp ){
883883
void * p = Th_Data_Get( interp, Th_Sqlite_KEY );
884884
return p ? (Th_Sqlite*)p : NULL;
885885
}
886886
887
-int Th_AddStmt(Th_Interp *interp, sqlite3_stmt * pStmt){
887
+static int Th_AddStmt(Th_Interp *interp, sqlite3_stmt * pStmt){
888888
Th_Sqlite * sq = Th_sqlite_manager(interp);
889889
int i, x;
890890
sqlite3_stmt * s;
891891
sqlite3_stmt ** list = sq->aStmt;
892892
for( i = 0; i < sq->nStmt; ++i ){
@@ -907,11 +907,11 @@
907907
sq->aStmt = list;
908908
return x + 1;
909909
}
910910
911911
912
-int Th_FinalizeStmt(Th_Interp *interp, int stmtId){
912
+static int Th_FinalizeStmt(Th_Interp *interp, int stmtId){
913913
Th_Sqlite * sq = Th_sqlite_manager(interp);
914914
sqlite3_stmt * st;
915915
int rc = 0;
916916
assert( stmtId>0 && stmtId<=sq->nStmt );
917917
st = sq->aStmt[stmtId-1];
@@ -922,30 +922,30 @@
922922
}else{
923923
return 1;
924924
}
925925
}
926926
927
-sqlite3_stmt * Th_GetStmt(Th_Interp *interp, int stmtId){
927
+static sqlite3_stmt * Th_GetStmt(Th_Interp *interp, int stmtId){
928928
Th_Sqlite * sq = Th_sqlite_manager(interp);
929929
return ((stmtId<1) || (stmtId > sq->nStmt))
930930
? NULL
931931
: sq->aStmt[stmtId-1];
932932
}
933933
934934
935935
static void finalizerSqlite( Th_Interp * interp, void * p ){
936
- Th_Sqlite * sq = Th_sqlite_manager( interp );
936
+ Th_Sqlite * sq = (Th_Sqlite *)p;
937937
int i;
938938
sqlite3_stmt * st = NULL;
939939
if(!sq) {
940940
fossil_warning("Got a finalizer call for a NULL Th_Sqlite.");
941941
return;
942942
}
943943
for( i = 0; i < sq->nStmt; ++i ){
944944
st = sq->aStmt[i];
945945
if(NULL != st){
946
- fossil_warning("Auto-finalizing unfinalized query_prepare "
946
+ fossil_warning("Auto-finalizing unfinalized "
947947
"statement id #%d: %s",
948948
i+1, sqlite3_sql(st));
949949
Th_FinalizeStmt( interp, i+1 );
950950
}
951951
}
952952
--- src/th_main.c
+++ src/th_main.c
@@ -851,27 +851,27 @@
851 ** by this function.
852 **
853 ** If interp is destroyed before all statements are finalized,
854 ** it will finalize them but may emit a warning message.
855 */
856 int Th_AddStmt(Th_Interp *interp, sqlite3_stmt * pStmt);
857
858 /*
859 ** Expects stmtId to be a statement identifier returned by
860 ** Th_AddStmt(). On success, finalizes the statement and returns 0.
861 ** On error (statement not found) non-0 is returned. After this
862 ** call, some subsequent call to Th_AddStmt() may return the
863 ** same statement ID.
864 */
865 int Th_FinalizeStmt(Th_Interp *interp, int stmtId);
866
867 /*
868 ** Fetches the statement with the given ID, as returned by
869 ** Th_AddStmt(). Returns NULL if stmtId does not refer (or no longer
870 ** refers) to a statement added via Th_AddStmt().
871 */
872 sqlite3_stmt * Th_GetStmt(Th_Interp *interp, int stmtId);
873
874
875 struct Th_Sqlite {
876 sqlite3_stmt ** aStmt;
877 int nStmt;
@@ -882,11 +882,11 @@
882 static Th_Sqlite * Th_sqlite_manager( Th_Interp * interp ){
883 void * p = Th_Data_Get( interp, Th_Sqlite_KEY );
884 return p ? (Th_Sqlite*)p : NULL;
885 }
886
887 int Th_AddStmt(Th_Interp *interp, sqlite3_stmt * pStmt){
888 Th_Sqlite * sq = Th_sqlite_manager(interp);
889 int i, x;
890 sqlite3_stmt * s;
891 sqlite3_stmt ** list = sq->aStmt;
892 for( i = 0; i < sq->nStmt; ++i ){
@@ -907,11 +907,11 @@
907 sq->aStmt = list;
908 return x + 1;
909 }
910
911
912 int Th_FinalizeStmt(Th_Interp *interp, int stmtId){
913 Th_Sqlite * sq = Th_sqlite_manager(interp);
914 sqlite3_stmt * st;
915 int rc = 0;
916 assert( stmtId>0 && stmtId<=sq->nStmt );
917 st = sq->aStmt[stmtId-1];
@@ -922,30 +922,30 @@
922 }else{
923 return 1;
924 }
925 }
926
927 sqlite3_stmt * Th_GetStmt(Th_Interp *interp, int stmtId){
928 Th_Sqlite * sq = Th_sqlite_manager(interp);
929 return ((stmtId<1) || (stmtId > sq->nStmt))
930 ? NULL
931 : sq->aStmt[stmtId-1];
932 }
933
934
935 static void finalizerSqlite( Th_Interp * interp, void * p ){
936 Th_Sqlite * sq = Th_sqlite_manager( interp );
937 int i;
938 sqlite3_stmt * st = NULL;
939 if(!sq) {
940 fossil_warning("Got a finalizer call for a NULL Th_Sqlite.");
941 return;
942 }
943 for( i = 0; i < sq->nStmt; ++i ){
944 st = sq->aStmt[i];
945 if(NULL != st){
946 fossil_warning("Auto-finalizing unfinalized query_prepare "
947 "statement id #%d: %s",
948 i+1, sqlite3_sql(st));
949 Th_FinalizeStmt( interp, i+1 );
950 }
951 }
952
--- src/th_main.c
+++ src/th_main.c
@@ -851,27 +851,27 @@
851 ** by this function.
852 **
853 ** If interp is destroyed before all statements are finalized,
854 ** it will finalize them but may emit a warning message.
855 */
856 static int Th_AddStmt(Th_Interp *interp, sqlite3_stmt * pStmt);
857
858 /*
859 ** Expects stmtId to be a statement identifier returned by
860 ** Th_AddStmt(). On success, finalizes the statement and returns 0.
861 ** On error (statement not found) non-0 is returned. After this
862 ** call, some subsequent call to Th_AddStmt() may return the
863 ** same statement ID.
864 */
865 static int Th_FinalizeStmt(Th_Interp *interp, int stmtId);
866
867 /*
868 ** Fetches the statement with the given ID, as returned by
869 ** Th_AddStmt(). Returns NULL if stmtId does not refer (or no longer
870 ** refers) to a statement added via Th_AddStmt().
871 */
872 static sqlite3_stmt * Th_GetStmt(Th_Interp *interp, int stmtId);
873
874
875 struct Th_Sqlite {
876 sqlite3_stmt ** aStmt;
877 int nStmt;
@@ -882,11 +882,11 @@
882 static Th_Sqlite * Th_sqlite_manager( Th_Interp * interp ){
883 void * p = Th_Data_Get( interp, Th_Sqlite_KEY );
884 return p ? (Th_Sqlite*)p : NULL;
885 }
886
887 static int Th_AddStmt(Th_Interp *interp, sqlite3_stmt * pStmt){
888 Th_Sqlite * sq = Th_sqlite_manager(interp);
889 int i, x;
890 sqlite3_stmt * s;
891 sqlite3_stmt ** list = sq->aStmt;
892 for( i = 0; i < sq->nStmt; ++i ){
@@ -907,11 +907,11 @@
907 sq->aStmt = list;
908 return x + 1;
909 }
910
911
912 static int Th_FinalizeStmt(Th_Interp *interp, int stmtId){
913 Th_Sqlite * sq = Th_sqlite_manager(interp);
914 sqlite3_stmt * st;
915 int rc = 0;
916 assert( stmtId>0 && stmtId<=sq->nStmt );
917 st = sq->aStmt[stmtId-1];
@@ -922,30 +922,30 @@
922 }else{
923 return 1;
924 }
925 }
926
927 static sqlite3_stmt * Th_GetStmt(Th_Interp *interp, int stmtId){
928 Th_Sqlite * sq = Th_sqlite_manager(interp);
929 return ((stmtId<1) || (stmtId > sq->nStmt))
930 ? NULL
931 : sq->aStmt[stmtId-1];
932 }
933
934
935 static void finalizerSqlite( Th_Interp * interp, void * p ){
936 Th_Sqlite * sq = (Th_Sqlite *)p;
937 int i;
938 sqlite3_stmt * st = NULL;
939 if(!sq) {
940 fossil_warning("Got a finalizer call for a NULL Th_Sqlite.");
941 return;
942 }
943 for( i = 0; i < sq->nStmt; ++i ){
944 st = sq->aStmt[i];
945 if(NULL != st){
946 fossil_warning("Auto-finalizing unfinalized "
947 "statement id #%d: %s",
948 i+1, sqlite3_sql(st));
949 Th_FinalizeStmt( interp, i+1 );
950 }
951 }
952
+19 -8
--- www/th1_ob.wiki
+++ www/th1_ob.wiki
@@ -11,11 +11,11 @@
1111
Example usage:
1212
1313
<nowiki><pre>
1414
&lt;th1>
1515
puts "this is unbuffered"
16
-ob start
16
+ob push # or: ob start (same thing)
1717
# all output until the next ob start|end gets collected
1818
# in a buffer...
1919
&lt;/th1>
2020
2121
this is buffered
@@ -23,31 +23,37 @@
2323
&lt;th1>
2424
puts "current buffer level = " [ob level] "\n"
2525
puts "this part is also collected in the buffer."
2626
2727
# Collect the buffer's contents:
28
-set buf [ob get end]
28
+set buf [ob get pop]
2929
# That is equivalent to:
3030
# set buf [ob get]
31
-# ob end
31
+# ob pop
3232
3333
puts "\nThis is now unbuffered, but we buffered: $buf\n"
3434
&lt;/th1>
3535
</pre></nowiki>
3636
3737
The functions are summarized below...
3838
39
-<h2>ob start</h2>
39
+<h2>ob push|start</h2>
40
+
41
+<tt>push</tt> and <tt>start</tt> are aliases ("start" comes from the PHP API, but
42
+"push" is probably more natural to those working with th1).
4043
4144
<tt>ob start</tt> pushes a level of buffering onto the buffer stack, such that
4245
future calls which generate output through the th1-internal mechanism will have it
4346
transparently redirected to the current buffer.
4447
4548
It is important that every call to <tt>ob start</tt> be followed up (eventually)
4649
by either <tt>ob end</tt> or <tt>ob get end</tt>.
4750
48
-<h2>ob end</h2>
51
+<h2>ob pop|end</h2>
52
+
53
+<tt>pop</tt> and <tt>end</tt> are aliases ("end" comes from the PHP API, but
54
+"pop" is probably more natural to those working with th1).
4955
5056
This discards any current buffered contents and reverts the output state to
5157
the one it had before the previous <tt>ob start</tt>. i.e. that might be another
5258
buffering level or it might be the th1-normal output mechanism.
5359
@@ -61,15 +67,15 @@
6167
does not change the buffer stack level.
6268
6369
<h2>ob get</h2>
6470
6571
This fetches the current contents as a string. It optionally accepts
66
-either <tt>end</tt> or <tt>clean</tt>, in which cases it behaves like
67
-either <tt>ob end</tt> or <tt>ob clean</tt>, respectively, in addition
72
+either <tt>end</tt> (or its alias <tt>pop</tt>) or <tt>clean</tt>, in which cases it behaves like
73
+either <tt>ob end|pop</tt> or <tt>ob clean</tt>, respectively, in addition
6874
to returning the buffer contents. i.e. <tt>ob get clean</tt> will
6975
fetch the contents and clean up the buffer, but does not change the
70
-buffering level, whereas <tt>ob get end</tt> pops the buffer off the
76
+buffering level, whereas <tt>ob get end|pop</tt> pops the buffer off the
7177
stack after fetching its contents.
7278
7379
<h2>ob level</h2>
7480
7581
Returns the current buffering level (0 if not buffering).
@@ -81,5 +87,10 @@
8187
fetched the buffer state (<tt>ob get</tt>), reverted TH1 to its
8288
previous output mechanism, push the buffer state to TH1, revert TH1
8389
<em>back</em> to the current buffering state, and then clear the
8490
current buffer contents (like <tt>ob clean</tt>). This does not change
8591
the buffering level, though it temporarily behaves as if it does.
92
+
93
+In other words, this function pushes the current buffer contents to the
94
+next-lower output mechanism (which may be another ob buffering level,
95
+fossil's internal CGI output buffer, or it might be be
96
+<tt>fwrite(stdout)</tt>).
8697
--- www/th1_ob.wiki
+++ www/th1_ob.wiki
@@ -11,11 +11,11 @@
11 Example usage:
12
13 <nowiki><pre>
14 &lt;th1>
15 puts "this is unbuffered"
16 ob start
17 # all output until the next ob start|end gets collected
18 # in a buffer...
19 &lt;/th1>
20
21 this is buffered
@@ -23,31 +23,37 @@
23 &lt;th1>
24 puts "current buffer level = " [ob level] "\n"
25 puts "this part is also collected in the buffer."
26
27 # Collect the buffer's contents:
28 set buf [ob get end]
29 # That is equivalent to:
30 # set buf [ob get]
31 # ob end
32
33 puts "\nThis is now unbuffered, but we buffered: $buf\n"
34 &lt;/th1>
35 </pre></nowiki>
36
37 The functions are summarized below...
38
39 <h2>ob start</h2>
 
 
 
40
41 <tt>ob start</tt> pushes a level of buffering onto the buffer stack, such that
42 future calls which generate output through the th1-internal mechanism will have it
43 transparently redirected to the current buffer.
44
45 It is important that every call to <tt>ob start</tt> be followed up (eventually)
46 by either <tt>ob end</tt> or <tt>ob get end</tt>.
47
48 <h2>ob end</h2>
 
 
 
49
50 This discards any current buffered contents and reverts the output state to
51 the one it had before the previous <tt>ob start</tt>. i.e. that might be another
52 buffering level or it might be the th1-normal output mechanism.
53
@@ -61,15 +67,15 @@
61 does not change the buffer stack level.
62
63 <h2>ob get</h2>
64
65 This fetches the current contents as a string. It optionally accepts
66 either <tt>end</tt> or <tt>clean</tt>, in which cases it behaves like
67 either <tt>ob end</tt> or <tt>ob clean</tt>, respectively, in addition
68 to returning the buffer contents. i.e. <tt>ob get clean</tt> will
69 fetch the contents and clean up the buffer, but does not change the
70 buffering level, whereas <tt>ob get end</tt> pops the buffer off the
71 stack after fetching its contents.
72
73 <h2>ob level</h2>
74
75 Returns the current buffering level (0 if not buffering).
@@ -81,5 +87,10 @@
81 fetched the buffer state (<tt>ob get</tt>), reverted TH1 to its
82 previous output mechanism, push the buffer state to TH1, revert TH1
83 <em>back</em> to the current buffering state, and then clear the
84 current buffer contents (like <tt>ob clean</tt>). This does not change
85 the buffering level, though it temporarily behaves as if it does.
 
 
 
 
 
86
--- www/th1_ob.wiki
+++ www/th1_ob.wiki
@@ -11,11 +11,11 @@
11 Example usage:
12
13 <nowiki><pre>
14 &lt;th1>
15 puts "this is unbuffered"
16 ob push # or: ob start (same thing)
17 # all output until the next ob start|end gets collected
18 # in a buffer...
19 &lt;/th1>
20
21 this is buffered
@@ -23,31 +23,37 @@
23 &lt;th1>
24 puts "current buffer level = " [ob level] "\n"
25 puts "this part is also collected in the buffer."
26
27 # Collect the buffer's contents:
28 set buf [ob get pop]
29 # That is equivalent to:
30 # set buf [ob get]
31 # ob pop
32
33 puts "\nThis is now unbuffered, but we buffered: $buf\n"
34 &lt;/th1>
35 </pre></nowiki>
36
37 The functions are summarized below...
38
39 <h2>ob push|start</h2>
40
41 <tt>push</tt> and <tt>start</tt> are aliases ("start" comes from the PHP API, but
42 "push" is probably more natural to those working with th1).
43
44 <tt>ob start</tt> pushes a level of buffering onto the buffer stack, such that
45 future calls which generate output through the th1-internal mechanism will have it
46 transparently redirected to the current buffer.
47
48 It is important that every call to <tt>ob start</tt> be followed up (eventually)
49 by either <tt>ob end</tt> or <tt>ob get end</tt>.
50
51 <h2>ob pop|end</h2>
52
53 <tt>pop</tt> and <tt>end</tt> are aliases ("end" comes from the PHP API, but
54 "pop" is probably more natural to those working with th1).
55
56 This discards any current buffered contents and reverts the output state to
57 the one it had before the previous <tt>ob start</tt>. i.e. that might be another
58 buffering level or it might be the th1-normal output mechanism.
59
@@ -61,15 +67,15 @@
67 does not change the buffer stack level.
68
69 <h2>ob get</h2>
70
71 This fetches the current contents as a string. It optionally accepts
72 either <tt>end</tt> (or its alias <tt>pop</tt>) or <tt>clean</tt>, in which cases it behaves like
73 either <tt>ob end|pop</tt> or <tt>ob clean</tt>, respectively, in addition
74 to returning the buffer contents. i.e. <tt>ob get clean</tt> will
75 fetch the contents and clean up the buffer, but does not change the
76 buffering level, whereas <tt>ob get end|pop</tt> pops the buffer off the
77 stack after fetching its contents.
78
79 <h2>ob level</h2>
80
81 Returns the current buffering level (0 if not buffering).
@@ -81,5 +87,10 @@
87 fetched the buffer state (<tt>ob get</tt>), reverted TH1 to its
88 previous output mechanism, push the buffer state to TH1, revert TH1
89 <em>back</em> to the current buffering state, and then clear the
90 current buffer contents (like <tt>ob clean</tt>). This does not change
91 the buffering level, though it temporarily behaves as if it does.
92
93 In other words, this function pushes the current buffer contents to the
94 next-lower output mechanism (which may be another ob buffering level,
95 fossil's internal CGI output buffer, or it might be be
96 <tt>fwrite(stdout)</tt>).
97

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button