Skip to content

Commit c15e4c1

Browse files
committed
Use the connection's PGresult to pass results through calls
1 parent 5957a7e commit c15e4c1

File tree

4 files changed

+113
-132
lines changed

4 files changed

+113
-132
lines changed

psycopg/connection_int.c

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -651,7 +651,6 @@ conn_is_datestyle_ok(PGconn *pgconn)
651651
RAISES_NEG int
652652
conn_setup(connectionObject *self, PGconn *pgconn)
653653
{
654-
PGresult *pgres = NULL;
655654
char *error = NULL;
656655
int rv = -1;
657656

@@ -678,11 +677,10 @@ conn_setup(connectionObject *self, PGconn *pgconn)
678677
if (!dsn_has_replication(self->dsn) && !conn_is_datestyle_ok(self->pgconn)) {
679678
int res;
680679
Py_UNBLOCK_THREADS;
681-
res = pq_set_guc_locked(self, "datestyle", "ISO",
682-
&pgres, &error, &_save);
680+
res = pq_set_guc_locked(self, "datestyle", "ISO", &error, &_save);
683681
Py_BLOCK_THREADS;
684682
if (res < 0) {
685-
pq_complete_error(self, &pgres, &error);
683+
pq_complete_error(self, &error);
686684
goto unlock;
687685
}
688686
}
@@ -1225,7 +1223,6 @@ conn_set_session(connectionObject *self, int autocommit,
12251223
int isolevel, int readonly, int deferrable)
12261224
{
12271225
int rv = -1;
1228-
PGresult *pgres = NULL;
12291226
char *error = NULL;
12301227
int want_autocommit = autocommit == SRV_STATE_UNCHANGED ?
12311228
self->autocommit : autocommit;
@@ -1256,21 +1253,21 @@ conn_set_session(connectionObject *self, int autocommit,
12561253
if (isolevel != SRV_STATE_UNCHANGED) {
12571254
if (0 > pq_set_guc_locked(self,
12581255
"default_transaction_isolation", srv_isolevels[isolevel],
1259-
&pgres, &error, &_save)) {
1256+
&error, &_save)) {
12601257
goto endlock;
12611258
}
12621259
}
12631260
if (readonly != SRV_STATE_UNCHANGED) {
12641261
if (0 > pq_set_guc_locked(self,
12651262
"default_transaction_read_only", srv_state_guc[readonly],
1266-
&pgres, &error, &_save)) {
1263+
&error, &_save)) {
12671264
goto endlock;
12681265
}
12691266
}
12701267
if (deferrable != SRV_STATE_UNCHANGED) {
12711268
if (0 > pq_set_guc_locked(self,
12721269
"default_transaction_deferrable", srv_state_guc[deferrable],
1273-
&pgres, &error, &_save)) {
1270+
&error, &_save)) {
12741271
goto endlock;
12751272
}
12761273
}
@@ -1281,21 +1278,21 @@ conn_set_session(connectionObject *self, int autocommit,
12811278
if (self->isolevel != ISOLATION_LEVEL_DEFAULT) {
12821279
if (0 > pq_set_guc_locked(self,
12831280
"default_transaction_isolation", "default",
1284-
&pgres, &error, &_save)) {
1281+
&error, &_save)) {
12851282
goto endlock;
12861283
}
12871284
}
12881285
if (self->readonly != STATE_DEFAULT) {
12891286
if (0 > pq_set_guc_locked(self,
12901287
"default_transaction_read_only", "default",
1291-
&pgres, &error, &_save)) {
1288+
&error, &_save)) {
12921289
goto endlock;
12931290
}
12941291
}
12951292
if (self->server_version >= 90100 && self->deferrable != STATE_DEFAULT) {
12961293
if (0 > pq_set_guc_locked(self,
12971294
"default_transaction_deferrable", "default",
1298-
&pgres, &error, &_save)) {
1295+
&error, &_save)) {
12991296
goto endlock;
13001297
}
13011298
}
@@ -1320,7 +1317,7 @@ conn_set_session(connectionObject *self, int autocommit,
13201317
Py_END_ALLOW_THREADS;
13211318

13221319
if (rv < 0) {
1323-
pq_complete_error(self, &pgres, &error);
1320+
pq_complete_error(self, &error);
13241321
goto exit;
13251322
}
13261323

@@ -1339,7 +1336,6 @@ conn_set_session(connectionObject *self, int autocommit,
13391336
RAISES_NEG int
13401337
conn_set_client_encoding(connectionObject *self, const char *pgenc)
13411338
{
1342-
PGresult *pgres = NULL;
13431339
char *error = NULL;
13441340
int res = -1;
13451341
char *clean_enc = NULL;
@@ -1356,12 +1352,12 @@ conn_set_client_encoding(connectionObject *self, const char *pgenc)
13561352

13571353
/* abort the current transaction, to set the encoding ouside of
13581354
transactions */
1359-
if ((res = pq_abort_locked(self, &pgres, &error, &_save))) {
1355+
if ((res = pq_abort_locked(self, &error, &_save))) {
13601356
goto endlock;
13611357
}
13621358

13631359
if ((res = pq_set_guc_locked(self, "client_encoding", clean_enc,
1364-
&pgres, &error, &_save))) {
1360+
&error, &_save))) {
13651361
goto endlock;
13661362
}
13671363

@@ -1370,7 +1366,7 @@ conn_set_client_encoding(connectionObject *self, const char *pgenc)
13701366
Py_END_ALLOW_THREADS;
13711367

13721368
if (res < 0) {
1373-
pq_complete_error(self, &pgres, &error);
1369+
pq_complete_error(self, &error);
13741370
goto exit;
13751371
}
13761372

@@ -1396,18 +1392,17 @@ conn_set_client_encoding(connectionObject *self, const char *pgenc)
13961392
RAISES_NEG int
13971393
conn_tpc_begin(connectionObject *self, xidObject *xid)
13981394
{
1399-
PGresult *pgres = NULL;
14001395
char *error = NULL;
14011396

14021397
Dprintf("conn_tpc_begin: starting transaction");
14031398

14041399
Py_BEGIN_ALLOW_THREADS;
14051400
pthread_mutex_lock(&self->lock);
14061401

1407-
if (pq_begin_locked(self, &pgres, &error, &_save) < 0) {
1402+
if (pq_begin_locked(self, &error, &_save) < 0) {
14081403
pthread_mutex_unlock(&(self->lock));
14091404
Py_BLOCK_THREADS;
1410-
pq_complete_error(self, &pgres, &error);
1405+
pq_complete_error(self, &error);
14111406
return -1;
14121407
}
14131408

@@ -1430,7 +1425,6 @@ conn_tpc_begin(connectionObject *self, xidObject *xid)
14301425
RAISES_NEG int
14311426
conn_tpc_command(connectionObject *self, const char *cmd, xidObject *xid)
14321427
{
1433-
PGresult *pgres = NULL;
14341428
char *error = NULL;
14351429
PyObject *tid = NULL;
14361430
const char *ctid;
@@ -1446,10 +1440,10 @@ conn_tpc_command(connectionObject *self, const char *cmd, xidObject *xid)
14461440
pthread_mutex_lock(&self->lock);
14471441

14481442
if (0 > (rv = pq_tpc_command_locked(self, cmd, ctid,
1449-
&pgres, &error, &_save))) {
1443+
&error, &_save))) {
14501444
pthread_mutex_unlock(&self->lock);
14511445
Py_BLOCK_THREADS;
1452-
pq_complete_error(self, &pgres, &error);
1446+
pq_complete_error(self, &error);
14531447
goto exit;
14541448
}
14551449

psycopg/lobject_int.c

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,6 @@ lobject_open(lobjectObject *self, connectionObject *conn,
150150
Oid oid, const char *smode, Oid new_oid, const char *new_file)
151151
{
152152
int retvalue = -1;
153-
PGresult *pgres = NULL;
154153
char *error = NULL;
155154
int pgmode = 0;
156155
int mode;
@@ -162,7 +161,7 @@ lobject_open(lobjectObject *self, connectionObject *conn,
162161
Py_BEGIN_ALLOW_THREADS;
163162
pthread_mutex_lock(&(self->conn->lock));
164163

165-
retvalue = pq_begin_locked(self->conn, &pgres, &error, &_save);
164+
retvalue = pq_begin_locked(self->conn, &error, &_save);
166165
if (retvalue < 0)
167166
goto end;
168167

@@ -228,7 +227,7 @@ lobject_open(lobjectObject *self, connectionObject *conn,
228227
Py_END_ALLOW_THREADS;
229228

230229
if (retvalue < 0)
231-
pq_complete_error(self->conn, &pgres, &error);
230+
pq_complete_error(self->conn, &error);
232231
/* if retvalue > 0, an exception is already set */
233232

234233
return retvalue;
@@ -272,7 +271,6 @@ lobject_close_locked(lobjectObject *self, char **error)
272271
RAISES_NEG int
273272
lobject_close(lobjectObject *self)
274273
{
275-
PGresult *pgres = NULL;
276274
char *error = NULL;
277275
int retvalue;
278276

@@ -285,7 +283,7 @@ lobject_close(lobjectObject *self)
285283
Py_END_ALLOW_THREADS;
286284

287285
if (retvalue < 0)
288-
pq_complete_error(self->conn, &pgres, &error);
286+
pq_complete_error(self->conn, &error);
289287
return retvalue;
290288
}
291289

@@ -294,14 +292,13 @@ lobject_close(lobjectObject *self)
294292
RAISES_NEG int
295293
lobject_unlink(lobjectObject *self)
296294
{
297-
PGresult *pgres = NULL;
298295
char *error = NULL;
299296
int retvalue = -1;
300297

301298
Py_BEGIN_ALLOW_THREADS;
302299
pthread_mutex_lock(&(self->conn->lock));
303300

304-
retvalue = pq_begin_locked(self->conn, &pgres, &error, &_save);
301+
retvalue = pq_begin_locked(self->conn, &error, &_save);
305302
if (retvalue < 0)
306303
goto end;
307304

@@ -319,7 +316,7 @@ lobject_unlink(lobjectObject *self)
319316
Py_END_ALLOW_THREADS;
320317

321318
if (retvalue < 0)
322-
pq_complete_error(self->conn, &pgres, &error);
319+
pq_complete_error(self->conn, &error);
323320
return retvalue;
324321
}
325322

@@ -329,7 +326,6 @@ RAISES_NEG Py_ssize_t
329326
lobject_write(lobjectObject *self, const char *buf, size_t len)
330327
{
331328
Py_ssize_t written;
332-
PGresult *pgres = NULL;
333329
char *error = NULL;
334330

335331
Dprintf("lobject_writing: fd = %d, len = " FORMAT_CODE_SIZE_T,
@@ -346,7 +342,7 @@ lobject_write(lobjectObject *self, const char *buf, size_t len)
346342
Py_END_ALLOW_THREADS;
347343

348344
if (written < 0)
349-
pq_complete_error(self->conn, &pgres, &error);
345+
pq_complete_error(self->conn, &error);
350346
return written;
351347
}
352348

@@ -356,7 +352,6 @@ RAISES_NEG Py_ssize_t
356352
lobject_read(lobjectObject *self, char *buf, size_t len)
357353
{
358354
Py_ssize_t n_read;
359-
PGresult *pgres = NULL;
360355
char *error = NULL;
361356

362357
Py_BEGIN_ALLOW_THREADS;
@@ -370,7 +365,7 @@ lobject_read(lobjectObject *self, char *buf, size_t len)
370365
Py_END_ALLOW_THREADS;
371366

372367
if (n_read < 0)
373-
pq_complete_error(self->conn, &pgres, &error);
368+
pq_complete_error(self->conn, &error);
374369
return n_read;
375370
}
376371

@@ -379,7 +374,6 @@ lobject_read(lobjectObject *self, char *buf, size_t len)
379374
RAISES_NEG Py_ssize_t
380375
lobject_seek(lobjectObject *self, Py_ssize_t pos, int whence)
381376
{
382-
PGresult *pgres = NULL;
383377
char *error = NULL;
384378
Py_ssize_t where;
385379

@@ -406,7 +400,7 @@ lobject_seek(lobjectObject *self, Py_ssize_t pos, int whence)
406400
Py_END_ALLOW_THREADS;
407401

408402
if (where < 0)
409-
pq_complete_error(self->conn, &pgres, &error);
403+
pq_complete_error(self->conn, &error);
410404
return where;
411405
}
412406

@@ -415,7 +409,6 @@ lobject_seek(lobjectObject *self, Py_ssize_t pos, int whence)
415409
RAISES_NEG Py_ssize_t
416410
lobject_tell(lobjectObject *self)
417411
{
418-
PGresult *pgres = NULL;
419412
char *error = NULL;
420413
Py_ssize_t where;
421414

@@ -441,7 +434,7 @@ lobject_tell(lobjectObject *self)
441434
Py_END_ALLOW_THREADS;
442435

443436
if (where < 0)
444-
pq_complete_error(self->conn, &pgres, &error);
437+
pq_complete_error(self->conn, &error);
445438
return where;
446439
}
447440

@@ -450,14 +443,13 @@ lobject_tell(lobjectObject *self)
450443
RAISES_NEG int
451444
lobject_export(lobjectObject *self, const char *filename)
452445
{
453-
PGresult *pgres = NULL;
454446
char *error = NULL;
455447
int retvalue;
456448

457449
Py_BEGIN_ALLOW_THREADS;
458450
pthread_mutex_lock(&(self->conn->lock));
459451

460-
retvalue = pq_begin_locked(self->conn, &pgres, &error, &_save);
452+
retvalue = pq_begin_locked(self->conn, &error, &_save);
461453
if (retvalue < 0)
462454
goto end;
463455

@@ -470,15 +462,14 @@ lobject_export(lobjectObject *self, const char *filename)
470462
Py_END_ALLOW_THREADS;
471463

472464
if (retvalue < 0)
473-
pq_complete_error(self->conn, &pgres, &error);
465+
pq_complete_error(self->conn, &error);
474466
return retvalue;
475467
}
476468

477469
RAISES_NEG int
478470
lobject_truncate(lobjectObject *self, size_t len)
479471
{
480472
int retvalue;
481-
PGresult *pgres = NULL;
482473
char *error = NULL;
483474

484475
Dprintf("lobject_truncate: fd = %d, len = " FORMAT_CODE_SIZE_T,
@@ -504,7 +495,7 @@ lobject_truncate(lobjectObject *self, size_t len)
504495
Py_END_ALLOW_THREADS;
505496

506497
if (retvalue < 0)
507-
pq_complete_error(self->conn, &pgres, &error);
498+
pq_complete_error(self->conn, &error);
508499
return retvalue;
509500

510501
}

0 commit comments

Comments
 (0)