@@ -1130,7 +1130,7 @@ srf_vpcinit(PG_FUNCTION_ARGS)
1130
1130
{
1131
1131
int r ;
1132
1132
1133
- r = PySet_Add ( TransactionScope , fn_info -> fi_internal_state );
1133
+ r = Py_XACTREF ( fn_info -> fi_internal_state );
1134
1134
Py_DECREF (fn_info -> fi_internal_state );
1135
1135
if (r == -1 )
1136
1136
{
@@ -1180,8 +1180,7 @@ srf_vpcnext(PG_FUNCTION_ARGS)
1180
1180
* This can cause a success to fail.
1181
1181
* If it fails on top of an existing exception, fine.
1182
1182
*/
1183
- PySet_Discard (TransactionScope , fn_info -> fi_internal_state );
1184
-
1183
+ Py_DEXTREF (fn_info -> fi_internal_state );
1185
1184
fn_info -> fi_internal_state = NULL ;
1186
1185
fcinfo -> isnull = true;
1187
1186
@@ -1376,7 +1375,7 @@ initialize(PG_FUNCTION_ARGS)
1376
1375
module = run_PyPgFunction_module (func ); /* ereport's on failure */
1377
1376
else
1378
1377
{
1379
- r = PySet_Add ( TransactionScope , module );
1378
+ r = Py_XACTREF ( module );
1380
1379
Py_DECREF (module );
1381
1380
if (r == -1 )
1382
1381
{
@@ -1389,7 +1388,7 @@ initialize(PG_FUNCTION_ARGS)
1389
1388
* Add func to the transaction scope now.
1390
1389
* func has been ACQUIRE'd by the handler, so don't DECREF.
1391
1390
*/
1392
- r = PySet_Add ( TransactionScope , func );
1391
+ r = Py_XACTREF ( func );
1393
1392
if (r == -1 )
1394
1393
{
1395
1394
PyErr_ThrowPostgresError (
@@ -1421,7 +1420,7 @@ initialize(PG_FUNCTION_ARGS)
1421
1420
if (td == NULL )
1422
1421
PyErr_ThrowPostgresError ("could not create Postgres.TriggerData object" );
1423
1422
1424
- r = PySet_Add ( TransactionScope , td );
1423
+ r = Py_XACTREF ( td );
1425
1424
Py_DECREF (td );
1426
1425
if (r == -1 )
1427
1426
PyErr_ThrowPostgresError ("could not add trigger data to transaction scope" );
@@ -1489,7 +1488,7 @@ initialize(PG_FUNCTION_ARGS)
1489
1488
*/
1490
1489
if (pinput != fn_info -> fi_input )
1491
1490
{
1492
- r = PySet_Add ( TransactionScope , pinput );
1491
+ r = Py_XACTREF ( pinput );
1493
1492
Py_DECREF (pinput );
1494
1493
1495
1494
if (r == -1 )
@@ -1507,7 +1506,7 @@ initialize(PG_FUNCTION_ARGS)
1507
1506
*/
1508
1507
if (poutput != fn_info -> fi_output )
1509
1508
{
1510
- r = PySet_Add ( TransactionScope , poutput );
1509
+ r = Py_XACTREF ( poutput );
1511
1510
Py_DECREF (poutput );
1512
1511
1513
1512
if (r == -1 )
@@ -1549,7 +1548,7 @@ initialize(PG_FUNCTION_ARGS)
1549
1548
PyErr_ThrowPostgresError (
1550
1549
"could not construct expected result type" );
1551
1550
1552
- r = PySet_Add ( TransactionScope , output );
1551
+ r = Py_XACTREF ( output );
1553
1552
Py_DECREF (output );
1554
1553
if (r == -1 )
1555
1554
{
@@ -1705,10 +1704,15 @@ pl_handler(PG_FUNCTION_ARGS)
1705
1704
1706
1705
pl_execution_context = previous ;
1707
1706
1707
+ /*
1708
+ * Restore the caller's memory context.
1709
+ */
1710
+ MemoryContextSwitchTo (current_exec_state .return_memory_context );
1711
+
1708
1712
/*
1709
1713
* Special case relays as there is a Python exception available
1710
1714
* for us to use. This failure case happens when DatumNew causes
1711
- * a Python exception.
1715
+ * a * Python* exception.
1712
1716
*/
1713
1717
if (_PG_ERROR_IS_RELAY ())
1714
1718
{
@@ -1721,7 +1725,6 @@ pl_handler(PG_FUNCTION_ARGS)
1721
1725
FlushErrorState ();
1722
1726
1723
1727
/* Restore the caller's memory context. */
1724
- MemoryContextSwitchTo (current_exec_state .return_memory_context );
1725
1728
PyErr_ThrowPostgresErrorWithContext (
1726
1729
ERRCODE_PYTHON_EXCEPTION ,
1727
1730
"function raised a Python exception" ,
@@ -1735,11 +1738,6 @@ pl_handler(PG_FUNCTION_ARGS)
1735
1738
1736
1739
_PYRO_DEALLOCATE (); /* release references held by owner and pop */
1737
1740
1738
- /*
1739
- * Restore the caller's memory context.
1740
- */
1741
- MemoryContextSwitchTo (current_exec_state .return_memory_context );
1742
-
1743
1741
/*
1744
1742
* Should have been converted by now.
1745
1743
*/
0 commit comments