1313#include <unistd.h>
1414#include <fcntl.h>
1515
16- /* Hack to deal with Tcl 8.4 const-ification without losing compatibility */
17- #ifndef CONST84
18- #define CONST84
19- #endif
20-
21- /* ... and for Tcl 8.6. */
22- #ifndef CONST86
23- #define CONST86
24- #endif
25-
2616#include "access/htup_details.h"
2717#include "access/xact.h"
2818#include "catalog/pg_proc.h"
4737((TCL_MAJOR_VERSION > maj) || \
4838 (TCL_MAJOR_VERSION == maj && TCL_MINOR_VERSION >= min))
4939
50- /* Insist on Tcl >= 8.0 */
51- #if !HAVE_TCL_VERSION (8 ,0 )
52- #error PostgreSQL only supports Tcl 8.0 or later.
40+ /* Insist on Tcl >= 8.4 */
41+ #if !HAVE_TCL_VERSION (8 ,4 )
42+ #error PostgreSQL only supports Tcl 8.4 or later.
43+ #endif
44+
45+ /* Hack to deal with Tcl 8.6 const-ification without losing compatibility */
46+ #ifndef CONST86
47+ #define CONST86
5348#endif
5449
5550/* define our text domain for translations */
5651#undef TEXTDOMAIN
5752#define TEXTDOMAIN PG_TEXTDOMAIN("pltcl")
5853
59- #if defined(UNICODE_CONVERSION )&& HAVE_TCL_VERSION ( 8 , 1 )
54+ #if defined(UNICODE_CONVERSION )
6055
6156#include "mb/pg_wchar.h"
6257
@@ -223,7 +218,7 @@ static int pltcl_returnnull(ClientData cdata, Tcl_Interp *interp,
223218static int pltcl_SPI_execute (ClientData cdata ,Tcl_Interp * interp ,
224219int objc ,Tcl_Obj * const objv []);
225220static int pltcl_process_SPI_result (Tcl_Interp * interp ,
226- CONST84 char * arrayname ,
221+ const char * arrayname ,
227222Tcl_Obj * loop_body ,
228223int spi_rc ,
229224SPITupleTable * tuptable ,
@@ -235,7 +230,7 @@ static int pltcl_SPI_execute_plan(ClientData cdata, Tcl_Interp *interp,
235230static int pltcl_SPI_lastoid (ClientData cdata ,Tcl_Interp * interp ,
236231int objc ,Tcl_Obj * const objv []);
237232
238- static void pltcl_set_tuple_values (Tcl_Interp * interp ,CONST84 char * arrayname ,
233+ static void pltcl_set_tuple_values (Tcl_Interp * interp ,const char * arrayname ,
239234int tupno ,HeapTuple tuple ,TupleDesc tupdesc );
240235static Tcl_Obj * pltcl_build_tuple_argument (HeapTuple tuple ,TupleDesc tupdesc );
241236
@@ -250,10 +245,7 @@ static Tcl_Obj *pltcl_build_tuple_argument(HeapTuple tuple, TupleDesc tupdesc);
250245 * from Postgres, so the notifier capabilities are initialized, but never
251246 * used. Only InitNotifier and DeleteFileHandler ever seem to get called
252247 * within Postgres, but we implement all the functions for completeness.
253- * We can only fix this with Tcl >= 8.4, when Tcl_SetNotifier() appeared.
254248 */
255- #if HAVE_TCL_VERSION (8 ,4 )
256-
257249static ClientData
258250pltcl_InitNotifier (void )
259251{
@@ -298,7 +290,6 @@ pltcl_WaitForEvent(CONST86 Tcl_Time *timePtr)
298290{
299291return 0 ;
300292}
301- #endif /* HAVE_TCL_VERSION(8,4) */
302293
303294
304295/*
@@ -329,6 +320,7 @@ perm_fmgr_info(Oid functionId, FmgrInfo *finfo)
329320void
330321_PG_init (void )
331322{
323+ Tcl_NotifierProcs notifier ;
332324HASHCTL hash_ctl ;
333325
334326/* Be sure we do initialization only once (should be redundant now) */
@@ -342,25 +334,18 @@ _PG_init(void)
342334Tcl_FindExecutable ("" );
343335#endif
344336
345- #if HAVE_TCL_VERSION (8 ,4 )
346-
347337/*
348338 * Override the functions in the Notifier subsystem. See comments above.
349339 */
350- {
351- Tcl_NotifierProcs notifier ;
352-
353- notifier .setTimerProc = pltcl_SetTimer ;
354- notifier .waitForEventProc = pltcl_WaitForEvent ;
355- notifier .createFileHandlerProc = pltcl_CreateFileHandler ;
356- notifier .deleteFileHandlerProc = pltcl_DeleteFileHandler ;
357- notifier .initNotifierProc = pltcl_InitNotifier ;
358- notifier .finalizeNotifierProc = pltcl_FinalizeNotifier ;
359- notifier .alertNotifierProc = pltcl_AlertNotifier ;
360- notifier .serviceModeHookProc = pltcl_ServiceModeHook ;
361- Tcl_SetNotifier (& notifier );
362- }
363- #endif
340+ notifier .setTimerProc = pltcl_SetTimer ;
341+ notifier .waitForEventProc = pltcl_WaitForEvent ;
342+ notifier .createFileHandlerProc = pltcl_CreateFileHandler ;
343+ notifier .deleteFileHandlerProc = pltcl_DeleteFileHandler ;
344+ notifier .initNotifierProc = pltcl_InitNotifier ;
345+ notifier .finalizeNotifierProc = pltcl_FinalizeNotifier ;
346+ notifier .alertNotifierProc = pltcl_AlertNotifier ;
347+ notifier .serviceModeHookProc = pltcl_ServiceModeHook ;
348+ Tcl_SetNotifier (& notifier );
364349
365350/************************************************************
366351 * Create the dummy hold interpreter to prevent close of
@@ -853,8 +838,8 @@ pltcl_trigger_handler(PG_FUNCTION_ARGS, bool pltrusted)
853838Datum * modvalues ;
854839char * modnulls ;
855840int ret_numvals ;
856- CONST84 char * result ;
857- CONST84 char * * ret_values ;
841+ const char * result ;
842+ const char * * ret_values ;
858843
859844/* Connect to SPI manager */
860845if (SPI_connect ()!= SPI_OK_CONNECT )
@@ -1093,8 +1078,8 @@ pltcl_trigger_handler(PG_FUNCTION_ARGS, bool pltrusted)
10931078
10941079for (i = 0 ;i < ret_numvals ;i += 2 )
10951080{
1096- CONST84 char * ret_name = ret_values [i ];
1097- CONST84 char * ret_value = ret_values [i + 1 ];
1081+ const char * ret_name = ret_values [i ];
1082+ const char * ret_value = ret_values [i + 1 ];
10981083int attnum ;
10991084Oid typinput ;
11001085Oid typioparam ;
@@ -1620,12 +1605,12 @@ pltcl_elog(ClientData cdata, Tcl_Interp *interp,
16201605MemoryContext oldcontext ;
16211606int priIndex ;
16221607
1623- static CONST84 char * logpriorities []= {
1608+ static const char * logpriorities []= {
16241609"DEBUG" ,"LOG" ,"INFO" ,"NOTICE" ,
1625- "WARNING" ,"ERROR" ,"FATAL" , (char * )NULL
1610+ "WARNING" ,"ERROR" ,"FATAL" , (const char * )NULL
16261611};
16271612
1628- static CONST84 int loglevels []= {
1613+ static const int loglevels []= {
16291614DEBUG2 ,LOG ,INFO ,NOTICE ,
16301615WARNING ,ERROR ,FATAL
16311616};
@@ -1934,7 +1919,7 @@ pltcl_SPI_execute(ClientData cdata, Tcl_Interp *interp,
19341919int i ;
19351920int optIndex ;
19361921int count = 0 ;
1937- CONST84 char * volatile arrayname = NULL ;
1922+ const char * volatile arrayname = NULL ;
19381923Tcl_Obj * volatile loop_body = NULL ;
19391924MemoryContext oldcontext = CurrentMemoryContext ;
19401925ResourceOwner oldowner = CurrentResourceOwner ;
@@ -1944,8 +1929,8 @@ pltcl_SPI_execute(ClientData cdata, Tcl_Interp *interp,
19441929OPT_ARRAY ,OPT_COUNT
19451930};
19461931
1947- static CONST84 char * options []= {
1948- "-array" ,"-count" , (char * )NULL
1932+ static const char * options []= {
1933+ "-array" ,"-count" , (const char * )NULL
19491934};
19501935
19511936/************************************************************
@@ -2035,7 +2020,7 @@ pltcl_SPI_execute(ClientData cdata, Tcl_Interp *interp,
20352020 */
20362021static int
20372022pltcl_process_SPI_result (Tcl_Interp * interp ,
2038- CONST84 char * arrayname ,
2023+ const char * arrayname ,
20392024Tcl_Obj * loop_body ,
20402025int spi_rc ,
20412026SPITupleTable * tuptable ,
@@ -2282,7 +2267,7 @@ pltcl_SPI_execute_plan(ClientData cdata, Tcl_Interp *interp,
22822267Tcl_HashEntry * hashent ;
22832268pltcl_query_desc * qdesc ;
22842269const char * nulls = NULL ;
2285- CONST84 char * arrayname = NULL ;
2270+ const char * arrayname = NULL ;
22862271Tcl_Obj * loop_body = NULL ;
22872272int count = 0 ;
22882273int callObjc ;
@@ -2297,8 +2282,8 @@ pltcl_SPI_execute_plan(ClientData cdata, Tcl_Interp *interp,
22972282OPT_ARRAY ,OPT_COUNT ,OPT_NULLS
22982283};
22992284
2300- static CONST84 char * options []= {
2301- "-array" ,"-count" ,"-nulls" , (char * )NULL
2285+ static const char * options []= {
2286+ "-array" ,"-count" ,"-nulls" , (const char * )NULL
23022287};
23032288
23042289/************************************************************
@@ -2500,19 +2485,19 @@ pltcl_SPI_lastoid(ClientData cdata, Tcl_Interp *interp,
25002485 * of a given tuple
25012486 **********************************************************************/
25022487static void
2503- pltcl_set_tuple_values (Tcl_Interp * interp ,CONST84 char * arrayname ,
2488+ pltcl_set_tuple_values (Tcl_Interp * interp ,const char * arrayname ,
25042489int tupno ,HeapTuple tuple ,TupleDesc tupdesc )
25052490{
25062491int i ;
25072492char * outputstr ;
25082493Datum attr ;
25092494bool isnull ;
2510- CONST84 char * attname ;
2495+ const char * attname ;
25112496Oid typoutput ;
25122497bool typisvarlena ;
2513- CONST84 char * * arrptr ;
2514- CONST84 char * * nameptr ;
2515- CONST84 char * nullname = NULL ;
2498+ const char * * arrptr ;
2499+ const char * * nameptr ;
2500+ const char * nullname = NULL ;
25162501
25172502/************************************************************
25182503 * Prepare pointers for Tcl_SetVar2() below and in array