--- generic/pgtclId.c +++ generic/pgtclId.c @@ -1035,10 +1035,11 @@ PgDelResultId(Tcl_Interp *interp, const char *id) { Pg_ConnectionId *connid; Pg_resultid *resultid; int resid; + char pid[10]; resid = getresid(interp, id, &connid); if (resid == -1) return; @@ -1201,12 +1202,29 @@ /* * We have to copy the callback string in case the user executes a * new pg_listen or pg_on_connection_loss during the callback. */ - svcallback = (char *)ckalloc((unsigned)(strlen(callback) + 1)); - strcpy(svcallback, callback); + /* Create a Tcl Object with a string containing the callback + * with the channel name (relname) and the PID of the notifying + * backend. + */ + Tcl_Obj *callbackObj = Tcl_NewStringObj(callback, -1); + sprintf (pid, "%d", event->notify->be_pid); + Tcl_AppendStringsToObj ( + callbackObj, " ", + event->notify->relname, " ", + pid, NULL + ); + /* In case there is a payload, add it to the callback as a + * string in braces. Make sure that the payload has balanced + * braces, if any. + */ + if (event->notify->extra[0]) { + Tcl_AppendStringsToObj (callbackObj, " {", event->notify->extra, "}", NULL); + } + svcallback = Tcl_GetString(callbackObj); /* * Execute the callback. */ Tcl_Preserve((ClientData)interp);