From 376a79a36718ad598fbf54da18b1d2875158b08c Mon Sep 17 00:00:00 2001 From: Peter da Silva Date: Fri, 21 Jan 2022 23:27:55 +0000 Subject: [PATCH 1/3] Pass additional arguments to pg_listen payload. --- generic/pgtclId.c | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/generic/pgtclId.c b/generic/pgtclId.c index a8022ae..45b1e6d 100644 --- a/generic/pgtclId.c +++ b/generic/pgtclId.c @@ -1136,7 +1136,6 @@ Pg_Notify_EventProc(Tcl_Event *evPtr, int flags) NotifyEvent *event = (NotifyEvent *) evPtr; Pg_TclNotifies *notifies; char *callback; - char *svcallback; /* We classify SQL notifies as Tcl file events. */ if (!(flags & TCL_FILE_EVENTS)) @@ -1199,18 +1198,28 @@ Pg_Notify_EventProc(Tcl_Event *evPtr, int flags) if (callback == NULL) continue; /* nothing to do for this interpreter */ - /* - * We have to copy the callback string in case the user executes a - * new pg_listen or pg_on_connection_loss during the callback. + /* Create a Tcl List Object containing the callback with the channel name + * (relname) and the PID of the notifying backend. This will also copy the callback + * string in case the user executes a new pg_listen or pg_on_connection_loss + * during the callback + */ + Tcl_Obj *callbackList = Tcl_NewListObj(0, NULL); + Tcl_ListObjAppendElement(NULL, callbackList, Tcl_NewStringObj(callback, -1)); + Tcl_ListObjAppendElement(NULL, callbackList, Tcl_NewStringObj(event->notify->relname, -1)); + Tcl_ListObjAppendElement(NULL, callbackList, Tcl_NewIntObj(event->notify->be_pid)); + /* In case there is a payload, add it to the callback as a + * further element to the list. */ - svcallback = (char *)ckalloc((unsigned)(strlen(callback) + 1)); - strcpy(svcallback, callback); + if (event->notify->extra[0]) { + Tcl_ListObjAppendElement (NULL, callbackList, Tcl_NewStringObj(event->notify->extra, -1)); + } /* * Execute the callback. */ + Tcl_IncrRefCount(callbackList); Tcl_Preserve((ClientData)interp); - if (Tcl_GlobalEval(interp, svcallback) != TCL_OK) + if (Tcl_EvalObjEx(interp, callbackList, TCL_EVAL_GLOBAL) != TCL_OK) { if (event->notify) Tcl_AddErrorInfo(interp, "\n (\"pg_listen\" script)"); @@ -1219,7 +1228,7 @@ Pg_Notify_EventProc(Tcl_Event *evPtr, int flags) Tcl_BackgroundError(interp); } Tcl_Release((ClientData)interp); - ckfree(svcallback); + Tcl_DecrRefCount(callbackList); /* * Check for the possibility that the callback closed the From fcc5c8fa4cbf2f9876b1b5c532b83f50f56eefb6 Mon Sep 17 00:00:00 2001 From: Peter da Silva Date: Fri, 4 Feb 2022 10:59:53 -0600 Subject: [PATCH 2/3] Check for event->notify in case of disconnect. --- generic/pgtclId.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/generic/pgtclId.c b/generic/pgtclId.c index 45b1e6d..9f8522c 100644 --- a/generic/pgtclId.c +++ b/generic/pgtclId.c @@ -1205,13 +1205,15 @@ Pg_Notify_EventProc(Tcl_Event *evPtr, int flags) */ Tcl_Obj *callbackList = Tcl_NewListObj(0, NULL); Tcl_ListObjAppendElement(NULL, callbackList, Tcl_NewStringObj(callback, -1)); - Tcl_ListObjAppendElement(NULL, callbackList, Tcl_NewStringObj(event->notify->relname, -1)); - Tcl_ListObjAppendElement(NULL, callbackList, Tcl_NewIntObj(event->notify->be_pid)); - /* In case there is a payload, add it to the callback as a - * further element to the list. - */ - if (event->notify->extra[0]) { - Tcl_ListObjAppendElement (NULL, callbackList, Tcl_NewStringObj(event->notify->extra, -1)); + if (event->notify) { + Tcl_ListObjAppendElement(NULL, callbackList, Tcl_NewStringObj(event->notify->relname, -1)); + Tcl_ListObjAppendElement(NULL, callbackList, Tcl_NewIntObj(event->notify->be_pid)); + /* In case there is a payload, add it to the callback as a + * further element to the list. + */ + if (event->notify->extra[0]) { + Tcl_ListObjAppendElement (NULL, callbackList, Tcl_NewStringObj(event->notify->extra, -1)); + } } /* From af54a6ae85fdac85121145cd041173b1a4e8755c Mon Sep 17 00:00:00 2001 From: Jeff Lawson Date: Tue, 8 Feb 2022 18:13:29 -0600 Subject: [PATCH 3/3] fix Mac CI breakage --- .github/workflows/mac-ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/mac-ci.yml b/.github/workflows/mac-ci.yml index a3b96e7..4569381 100644 --- a/.github/workflows/mac-ci.yml +++ b/.github/workflows/mac-ci.yml @@ -19,6 +19,7 @@ jobs: brew install tcl-tk || true sudo mkdir -p /usr/local sudo ln -sf /usr/local/opt/tcl-tk/include /usr/local/include/tcl8.6 + sudo rm -f /usr/local/lib/libtcl* || true sudo cp /usr/local/opt/tcl-tk/lib/libtcl* /usr/local/lib sudo ln -sf /usr/local/opt/tcl-tk/bin/tclsh8.6 /usr/local/bin/tclsh sudo ln -sf /usr/local/opt/tcl-tk/bin/tclsh8.6 /usr/local/bin/tclsh8.6