Fossil SCM
Proposed fix for out-of-order output when calling th1 render function from a th-doc page body. DO NOT MERGE: this is being checked in so that it can be deployed on a test server.
Commit
a381a8102b6819b965b79e4981a1b8e3a6f97334cd18eef172a57368d7548cf6
Parent
12b5eed944b70f7…
1 file changed
+20
-9
+20
-9
| --- src/th_main.c | ||
| +++ src/th_main.c | ||
| @@ -361,11 +361,11 @@ | ||
| 361 | 361 | static Blob * pThOut = 0; |
| 362 | 362 | /* |
| 363 | 363 | ** Sets the th1-internal output-redirection blob and returns the |
| 364 | 364 | ** previous value. That blob is used by certain output-generation |
| 365 | 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 | |
| 366 | +** a routine can temporarily replace the buffer with its own and | |
| 367 | 367 | ** restore it when it's done. |
| 368 | 368 | */ |
| 369 | 369 | Blob * Th_SetOutputBlob(Blob * pOut){ |
| 370 | 370 | Blob * tmp = pThOut; |
| 371 | 371 | pThOut = pOut; |
| @@ -2834,17 +2834,18 @@ | ||
| 2834 | 2834 | #define TH_R2B_MASK ((u32)0x0f000) |
| 2835 | 2835 | #define TH_R2B_NO_VARS ((u32)0x01000) /* Disables eval of $vars and $<vars> */ |
| 2836 | 2836 | #endif |
| 2837 | 2837 | |
| 2838 | 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. | |
| 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. | |
| 2846 | 2847 | */ |
| 2847 | 2848 | int Th_RenderToBlob(const char *z, Blob * pOut, u32 mFlags){ |
| 2848 | 2849 | int i = 0; |
| 2849 | 2850 | int n; |
| 2850 | 2851 | int rc = TH_OK; |
| @@ -2917,11 +2918,21 @@ | ||
| 2917 | 2918 | ** This routine processes the template and writes the results to one |
| 2918 | 2919 | ** of stdout, CGI, or an internal blob which was set up via a prior |
| 2919 | 2920 | ** call to Th_SetOutputBlob(). |
| 2920 | 2921 | */ |
| 2921 | 2922 | int Th_Render(const char *z){ |
| 2922 | - return Th_RenderToBlob(z, 0, 0); | |
| 2923 | + return Th_RenderToBlob(z, pThOut, 0) | |
| 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. | |
| 2933 | + */; | |
| 2923 | 2934 | } |
| 2924 | 2935 | |
| 2925 | 2936 | /* |
| 2926 | 2937 | ** COMMAND: test-th-render |
| 2927 | 2938 | ** |
| 2928 | 2939 |
| --- src/th_main.c | |
| +++ src/th_main.c | |
| @@ -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,21 @@ | |
| 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 | |
| @@ -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,21 @@ | |
| 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, 0) |
| 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. |
| 2933 | */; |
| 2934 | } |
| 2935 | |
| 2936 | /* |
| 2937 | ** COMMAND: test-th-render |
| 2938 | ** |
| 2939 |