Fossil SCM

Resolved problems with recursive invocation of th1's render command.

stephan 2021-07-05 16:55 trunk merge
Commit a5f00e0a71c9fc7d28d2a93da91752325e5623168a0ee2d0a31eb65563804ee3
1 file changed +25 -12
+25 -12
--- src/th_main.c
+++ src/th_main.c
@@ -46,13 +46,13 @@
4646
4747
/*
4848
** Flags set by functions in this file to keep track of integration state
4949
** information. These flags should not be used outside of this file.
5050
*/
51
-#define TH_STATE_CONFIG ((u32)0x00000020) /* We opened the config. */
52
-#define TH_STATE_REPOSITORY ((u32)0x00000040) /* We opened the repository. */
53
-#define TH_STATE_MASK ((u32)0x00000060) /* All possible state flags. */
51
+#define TH_STATE_CONFIG ((u32)0x00000200) /* We opened the config. */
52
+#define TH_STATE_REPOSITORY ((u32)0x00000400) /* We opened the repository. */
53
+#define TH_STATE_MASK ((u32)0x00000600) /* All possible state flags. */
5454
5555
#ifdef FOSSIL_ENABLE_TH1_HOOKS
5656
/*
5757
** These are the "well-known" TH1 error messages that occur when no hook is
5858
** registered to be called prior to executing a command or processing a web
@@ -361,11 +361,11 @@
361361
static Blob * pThOut = 0;
362362
/*
363363
** Sets the th1-internal output-redirection blob and returns the
364364
** previous value. That blob is used by certain output-generation
365365
** routines to emit its output. It returns the previous value so that
366
-** a routing can temporarily replace the buffer with its own and
366
+** a routine can temporarily replace the buffer with its own and
367367
** restore it when it's done.
368368
*/
369369
Blob * Th_SetOutputBlob(Blob * pOut){
370370
Blob * tmp = pThOut;
371371
pThOut = pOut;
@@ -2834,17 +2834,18 @@
28342834
#define TH_R2B_MASK ((u32)0x0f000)
28352835
#define TH_R2B_NO_VARS ((u32)0x01000) /* Disables eval of $vars and $<vars> */
28362836
#endif
28372837
28382838
/*
2839
-** If pOut is NULL, this works identically to Th_Render(), else it
2840
-** works just like that function but appends any TH1-generated output
2841
-** to the given blob. A bitmask of TH_R2B_xxx and/or TH_INIT_xxx flags
2842
-** may be passed as the 3rd argument, or 0 for default options. Note
2843
-** that this function necessarily calls Th_FossilInit(), which may
2844
-** unset flags used on previous calls unless mFlags is explicitly
2845
-** passed in.
2839
+** If pOut is NULL, this works identically to Th_Render() and sends
2840
+** any TH1-generated output to stdin (in CLI mode) or the CGI buffer
2841
+** (in CGI mode), else it works just like that function but appends
2842
+** any TH1-generated output to the given blob. A bitmask of TH_R2B_xxx
2843
+** and/or TH_INIT_xxx flags may be passed as the 3rd argument, or 0
2844
+** for default options. Note that this function necessarily calls
2845
+** Th_FossilInit(), which may unset flags used on previous calls
2846
+** unless mFlags is explicitly passed in.
28462847
*/
28472848
int Th_RenderToBlob(const char *z, Blob * pOut, u32 mFlags){
28482849
int i = 0;
28492850
int n;
28502851
int rc = TH_OK;
@@ -2917,11 +2918,23 @@
29172918
** This routine processes the template and writes the results to one
29182919
** of stdout, CGI, or an internal blob which was set up via a prior
29192920
** call to Th_SetOutputBlob().
29202921
*/
29212922
int Th_Render(const char *z){
2922
- return Th_RenderToBlob(z, 0, 0);
2923
+ return Th_RenderToBlob(z, pThOut, g.th1Flags)
2924
+ /* Maintenance reminder: on most calls to Th_Render(), e.g. for
2925
+ ** outputing the site skin, pThOut will be 0, which means that
2926
+ ** Th_RenderToBlob() will output directly to the CGI buffer (in
2927
+ ** CGI mode) or stdout (in CLI mode). Recursive calls, however,
2928
+ ** e.g. via the "render" script function binding, need to use the
2929
+ ** pThOut blob in order to avoid out-of-order output if
2930
+ ** Th_SetOutputBlob() has been called. If it has not been called,
2931
+ ** pThOut will be 0, which will redirect the output to CGI/stdout,
2932
+ ** as appropriate. We need to pass on g.th1Flags for the case of
2933
+ ** recursive calls, so that, e.g., TH_INIT_NO_ENCODE does not get
2934
+ ** inadvertently toggled off by a recursive call.
2935
+ */;
29232936
}
29242937
29252938
/*
29262939
** COMMAND: test-th-render
29272940
**
29282941
--- src/th_main.c
+++ src/th_main.c
@@ -46,13 +46,13 @@
46
47 /*
48 ** Flags set by functions in this file to keep track of integration state
49 ** information. These flags should not be used outside of this file.
50 */
51 #define TH_STATE_CONFIG ((u32)0x00000020) /* We opened the config. */
52 #define TH_STATE_REPOSITORY ((u32)0x00000040) /* We opened the repository. */
53 #define TH_STATE_MASK ((u32)0x00000060) /* All possible state flags. */
54
55 #ifdef FOSSIL_ENABLE_TH1_HOOKS
56 /*
57 ** These are the "well-known" TH1 error messages that occur when no hook is
58 ** registered to be called prior to executing a command or processing a web
@@ -361,11 +361,11 @@
361 static Blob * pThOut = 0;
362 /*
363 ** Sets the th1-internal output-redirection blob and returns the
364 ** previous value. That blob is used by certain output-generation
365 ** routines to emit its output. It returns the previous value so that
366 ** a routing can temporarily replace the buffer with its own and
367 ** restore it when it's done.
368 */
369 Blob * Th_SetOutputBlob(Blob * pOut){
370 Blob * tmp = pThOut;
371 pThOut = pOut;
@@ -2834,17 +2834,18 @@
2834 #define TH_R2B_MASK ((u32)0x0f000)
2835 #define TH_R2B_NO_VARS ((u32)0x01000) /* Disables eval of $vars and $<vars> */
2836 #endif
2837
2838 /*
2839 ** If pOut is NULL, this works identically to Th_Render(), else it
2840 ** works just like that function but appends any TH1-generated output
2841 ** to the given blob. A bitmask of TH_R2B_xxx and/or TH_INIT_xxx flags
2842 ** may be passed as the 3rd argument, or 0 for default options. Note
2843 ** that this function necessarily calls Th_FossilInit(), which may
2844 ** unset flags used on previous calls unless mFlags is explicitly
2845 ** passed in.
 
2846 */
2847 int Th_RenderToBlob(const char *z, Blob * pOut, u32 mFlags){
2848 int i = 0;
2849 int n;
2850 int rc = TH_OK;
@@ -2917,11 +2918,23 @@
2917 ** This routine processes the template and writes the results to one
2918 ** of stdout, CGI, or an internal blob which was set up via a prior
2919 ** call to Th_SetOutputBlob().
2920 */
2921 int Th_Render(const char *z){
2922 return Th_RenderToBlob(z, 0, 0);
 
 
 
 
 
 
 
 
 
 
 
 
2923 }
2924
2925 /*
2926 ** COMMAND: test-th-render
2927 **
2928
--- src/th_main.c
+++ src/th_main.c
@@ -46,13 +46,13 @@
46
47 /*
48 ** Flags set by functions in this file to keep track of integration state
49 ** information. These flags should not be used outside of this file.
50 */
51 #define TH_STATE_CONFIG ((u32)0x00000200) /* We opened the config. */
52 #define TH_STATE_REPOSITORY ((u32)0x00000400) /* We opened the repository. */
53 #define TH_STATE_MASK ((u32)0x00000600) /* All possible state flags. */
54
55 #ifdef FOSSIL_ENABLE_TH1_HOOKS
56 /*
57 ** These are the "well-known" TH1 error messages that occur when no hook is
58 ** registered to be called prior to executing a command or processing a web
@@ -361,11 +361,11 @@
361 static Blob * pThOut = 0;
362 /*
363 ** Sets the th1-internal output-redirection blob and returns the
364 ** previous value. That blob is used by certain output-generation
365 ** routines to emit its output. It returns the previous value so that
366 ** a routine can temporarily replace the buffer with its own and
367 ** restore it when it's done.
368 */
369 Blob * Th_SetOutputBlob(Blob * pOut){
370 Blob * tmp = pThOut;
371 pThOut = pOut;
@@ -2834,17 +2834,18 @@
2834 #define TH_R2B_MASK ((u32)0x0f000)
2835 #define TH_R2B_NO_VARS ((u32)0x01000) /* Disables eval of $vars and $<vars> */
2836 #endif
2837
2838 /*
2839 ** If pOut is NULL, this works identically to Th_Render() and sends
2840 ** any TH1-generated output to stdin (in CLI mode) or the CGI buffer
2841 ** (in CGI mode), else it works just like that function but appends
2842 ** any TH1-generated output to the given blob. A bitmask of TH_R2B_xxx
2843 ** and/or TH_INIT_xxx flags may be passed as the 3rd argument, or 0
2844 ** for default options. Note that this function necessarily calls
2845 ** Th_FossilInit(), which may unset flags used on previous calls
2846 ** unless mFlags is explicitly passed in.
2847 */
2848 int Th_RenderToBlob(const char *z, Blob * pOut, u32 mFlags){
2849 int i = 0;
2850 int n;
2851 int rc = TH_OK;
@@ -2917,11 +2918,23 @@
2918 ** This routine processes the template and writes the results to one
2919 ** of stdout, CGI, or an internal blob which was set up via a prior
2920 ** call to Th_SetOutputBlob().
2921 */
2922 int Th_Render(const char *z){
2923 return Th_RenderToBlob(z, pThOut, g.th1Flags)
2924 /* Maintenance reminder: on most calls to Th_Render(), e.g. for
2925 ** outputing the site skin, pThOut will be 0, which means that
2926 ** Th_RenderToBlob() will output directly to the CGI buffer (in
2927 ** CGI mode) or stdout (in CLI mode). Recursive calls, however,
2928 ** e.g. via the "render" script function binding, need to use the
2929 ** pThOut blob in order to avoid out-of-order output if
2930 ** Th_SetOutputBlob() has been called. If it has not been called,
2931 ** pThOut will be 0, which will redirect the output to CGI/stdout,
2932 ** as appropriate. We need to pass on g.th1Flags for the case of
2933 ** recursive calls, so that, e.g., TH_INIT_NO_ENCODE does not get
2934 ** inadvertently toggled off by a recursive call.
2935 */;
2936 }
2937
2938 /*
2939 ** COMMAND: test-th-render
2940 **
2941

Keyboard Shortcuts

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