Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb516466

Browse files
committed
someone added pg_listen and pg_notifies to libpgtcl. But first
these routines try to use the old pointer casting stuff to get the connection id, second the notification hash table should be part of the cliendData. Otherwise, one interpreter might eat up the notifies for another one. Please apply the patch below to the current 6.0 tree.Submitted by: wieck@sapserv.debis.de
1 parent9d81f52 commitb516466

File tree

3 files changed

+20
-31
lines changed

3 files changed

+20
-31
lines changed

‎src/interfaces/libpgtcl/pgtcl.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
*
1111
* IDENTIFICATION
12-
* $Header: /cvsroot/pgsql/src/interfaces/libpgtcl/Attic/pgtcl.c,v 1.6 1996/12/19 05:02:47 scrappy Exp $
12+
* $Header: /cvsroot/pgsql/src/interfaces/libpgtcl/Attic/pgtcl.c,v 1.7 1997/01/03 18:48:28 scrappy Exp $
1313
*
1414
*-------------------------------------------------------------------------
1515
*/
@@ -49,6 +49,7 @@ Pgtcl_AtExit (ClientData cData)
4949

5050
Tcl_DeleteHashTable(&(cd->dbh_hash));
5151
Tcl_DeleteHashTable(&(cd->res_hash));
52+
Tcl_DeleteHashTable(&(cd->notify_hash));
5253

5354
Tcl_DeleteExitHandler(Pgtcl_AtExit,cData);
5455
}
@@ -71,6 +72,7 @@ Pgtcl_Init (Tcl_Interp *interp)
7172
cd= (Pg_clientData*)ckalloc(sizeof(Pg_clientData));
7273
Tcl_InitHashTable(&(cd->dbh_hash),TCL_STRING_KEYS);
7374
Tcl_InitHashTable(&(cd->res_hash),TCL_STRING_KEYS);
75+
Tcl_InitHashTable(&(cd->notify_hash),TCL_STRING_KEYS);
7476
cd->dbh_count=0L;
7577
cd->res_count=0L;
7678

@@ -162,12 +164,12 @@ Pgtcl_Init (Tcl_Interp *interp)
162164
Tcl_CreateCommand(interp,
163165
"pg_listen",
164166
Pg_listen,
165-
(ClientData)NULL, (Tcl_CmdDeleteProc*)NULL);
167+
(ClientData)cd, (Tcl_CmdDeleteProc*)NULL);
166168

167169
Tcl_CreateCommand(interp,
168170
"pg_notifies",
169171
Pg_notifies,
170-
(ClientData)NULL, (Tcl_CmdDeleteProc*)NULL);
172+
(ClientData)cd, (Tcl_CmdDeleteProc*)NULL);
171173

172174
Tcl_PkgProvide(interp,"Pgtcl","1.0");
173175

‎src/interfaces/libpgtcl/pgtclCmds.c

Lines changed: 13 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/interfaces/libpgtcl/Attic/pgtclCmds.c,v 1.8 1996/12/19 05:02:49 scrappy Exp $
10+
* $Header: /cvsroot/pgsql/src/interfaces/libpgtcl/Attic/pgtclCmds.c,v 1.9 1997/01/03 18:48:30 scrappy Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -24,8 +24,6 @@
2424
#include"pgtclCmds.h"
2525
#include"pgtclId.h"
2626

27-
staticTcl_HashTablenotifyTable= {NULL };
28-
2927
#ifdefTCL_ARRAYS
3028
#defineISOCTAL(c)(((c) >= '0') && ((c) <= '7'))
3129
#defineDIGIT(c)((c) - '0')
@@ -1215,6 +1213,7 @@ Pg_select(ClientData cData, Tcl_Interp *interp, int argc, char **argv)
12151213
int
12161214
Pg_listen(ClientDatacData,Tcl_Interp*interp,intargc,char*argv[])
12171215
{
1216+
Pg_clientData*cd= (Pg_clientData*)cData;
12181217
intnew;
12191218
char*relname;
12201219
char*callback=NULL;
@@ -1228,22 +1227,15 @@ Pg_listen(ClientData cData, Tcl_Interp *interp, int argc, char* argv[])
12281227
returnTCL_ERROR;
12291228
}
12301229

1231-
/*
1232-
* Initialize the notify hash table if not already done.
1233-
*/
1234-
if (notifyTable.buckets==NULL) {
1235-
Tcl_InitHashTable(&notifyTable,TCL_STRING_KEYS);
1236-
}
1237-
12381230
/*
12391231
* Get the command arguments. Note that relname will copied by
12401232
* Tcl_CreateHashEntry while callback must be allocated.
12411233
*/
1242-
if (!PgValidId(argv[1])) {
1243-
Tcl_AppendResult(interp,"not a valid connection\n",0);
1234+
conn= (PGconn*)PgGetConnectionId(cd,argv[1]);
1235+
if (conn== (PGconn*)NULL) {
1236+
Tcl_AppendResult(interp,"First argument is not a valid connection\n",0);
12441237
returnTCL_ERROR;
12451238
}
1246-
conn= (PGconn*)PgGetId(argv[1]);
12471239
relname=argv[2];
12481240
if ((argc>3)&&*argv[3]) {
12491241
callback= (char*)ckalloc((unsigned) (strlen(argv[3])+1));
@@ -1254,7 +1246,7 @@ Pg_listen(ClientData cData, Tcl_Interp *interp, int argc, char* argv[])
12541246
* Set or update a callback for a relation;
12551247
*/
12561248
if (callback) {
1257-
entry=Tcl_CreateHashEntry(&notifyTable,relname,&new);
1249+
entry=Tcl_CreateHashEntry(&(cd->notify_hash),relname,&new);
12581250
if (new) {
12591251
/* New callback, execute a listen command on the relation */
12601252
char*cmd= (char*)ckalloc((unsigned) (strlen(argv[2])+8));
@@ -1284,7 +1276,7 @@ Pg_listen(ClientData cData, Tcl_Interp *interp, int argc, char* argv[])
12841276
* the notify hash table.
12851277
*/
12861278
if (callback==NULL) {
1287-
entry=Tcl_FindHashEntry(&notifyTable,relname);
1279+
entry=Tcl_FindHashEntry(&(cd->notify_hash),relname);
12881280
if (entry==NULL) {
12891281
Tcl_AppendResult(interp,"not listening on ",relname,0);
12901282
returnTCL_ERROR;
@@ -1296,11 +1288,12 @@ Pg_listen(ClientData cData, Tcl_Interp *interp, int argc, char* argv[])
12961288
returnTCL_OK;
12971289
}
12981290

1291+
int
12991292
Pg_notifies(ClientDatacData,Tcl_Interp*interp,intargc,char*argv[])
13001293
{
1294+
Pg_clientData*cd= (Pg_clientData*)cData;
13011295
intcount;
13021296
charbuff[12];
1303-
char*relname;
13041297
char*callback;
13051298
Tcl_HashEntry*entry;
13061299
PGconn*conn;
@@ -1313,21 +1306,14 @@ Pg_notifies(ClientData cData, Tcl_Interp *interp, int argc, char* argv[])
13131306
returnTCL_ERROR;
13141307
}
13151308

1316-
/*
1317-
* Initialize the notify hash table if not already done.
1318-
*/
1319-
if (notifyTable.buckets==NULL) {
1320-
Tcl_InitHashTable(&notifyTable,TCL_STRING_KEYS);
1321-
}
1322-
13231309
/*
13241310
* Get the connection argument.
13251311
*/
1326-
if (!PgValidId(argv[1])) {
1327-
Tcl_AppendResult(interp,"not a valid connection\n",0);
1312+
conn= (PGconn*)PgGetConnectionId(cd,argv[1]);
1313+
if (conn== (PGconn*)NULL) {
1314+
Tcl_AppendResult(interp,"First argument is not a valid connection\n",0);
13281315
returnTCL_ERROR;
13291316
}
1330-
conn= (PGconn*)PgGetId(argv[1]);
13311317

13321318
/* Execute an empty command to retrieve asynchronous notifications */
13331319
result=PQexec(conn," ");
@@ -1347,7 +1333,7 @@ Pg_notifies(ClientData cData, Tcl_Interp *interp, int argc, char* argv[])
13471333
if (notify==NULL) {
13481334
break;
13491335
}
1350-
entry=Tcl_FindHashEntry(&notifyTable,notify->relname);
1336+
entry=Tcl_FindHashEntry(&(cd->notify_hash),notify->relname);
13511337
if (entry!=NULL) {
13521338
callback=Tcl_GetHashValue(entry);
13531339
if (callback) {

‎src/interfaces/libpgtcl/pgtclCmds.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*
66
* Copyright (c) 1994, Regents of the University of California
77
*
8-
* $Id: pgtclCmds.h,v 1.5 1996/12/19 05:02:51 scrappy Exp $
8+
* $Id: pgtclCmds.h,v 1.6 1997/01/03 18:48:31 scrappy Exp $
99
*
1010
*-------------------------------------------------------------------------
1111
*/
@@ -21,6 +21,7 @@
2121
typedefstructPg_clientData_s {
2222
Tcl_HashTabledbh_hash;
2323
Tcl_HashTableres_hash;
24+
Tcl_HashTablenotify_hash;
2425
longdbh_count;
2526
longres_count;
2627
}Pg_clientData;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp