11/**********************************************************************
22 * plpython.c - python as a procedural language for PostgreSQL
33 *
4- *$PostgreSQL: pgsql/src/pl/plpython/plpython.c,v 1.101 2007/05/31 15:13:05 petere Exp $
4+ *$PostgreSQL: pgsql/src/pl/plpython/plpython.c,v 1.102 2007/07/13 04:57:59 tgl Exp $
55 *
66 *********************************************************************
77 */
@@ -1714,7 +1714,7 @@ PLyMapping_ToTuple(PLyTypeInfo * info, PyObject * mapping)
17141714HeapTuple tuple ;
17151715Datum * values ;
17161716char * nulls ;
1717- int i ;
1717+ volatile int i ;
17181718
17191719Assert (PyMapping_Check (mapping ));
17201720
@@ -1729,8 +1729,8 @@ PLyMapping_ToTuple(PLyTypeInfo * info, PyObject * mapping)
17291729for (i = 0 ;i < desc -> natts ;++ i )
17301730{
17311731char * key ;
1732- PyObject * value ,
1733- * so ;
1732+ PyObject * volatile value ,
1733+ * volatile so ;
17341734
17351735key = NameStr (desc -> attrs [i ]-> attname );
17361736value = so = NULL ;
@@ -1794,7 +1794,7 @@ PLySequence_ToTuple(PLyTypeInfo * info, PyObject * sequence)
17941794HeapTuple tuple ;
17951795Datum * values ;
17961796char * nulls ;
1797- int i ;
1797+ volatile int i ;
17981798
17991799Assert (PySequence_Check (sequence ));
18001800
@@ -1818,8 +1818,8 @@ PLySequence_ToTuple(PLyTypeInfo * info, PyObject * sequence)
18181818nulls = palloc (sizeof (char )* desc -> natts );
18191819for (i = 0 ;i < desc -> natts ;++ i )
18201820{
1821- PyObject * value ,
1822- * so ;
1821+ PyObject * volatile value ,
1822+ * volatile so ;
18231823
18241824value = so = NULL ;
18251825PG_TRY ();
@@ -1876,7 +1876,7 @@ PLyObject_ToTuple(PLyTypeInfo * info, PyObject * object)
18761876HeapTuple tuple ;
18771877Datum * values ;
18781878char * nulls ;
1879- int i ;
1879+ volatile int i ;
18801880
18811881desc = lookup_rowtype_tupdesc (info -> out .d .typoid ,-1 );
18821882if (info -> is_rowtype == 2 )
@@ -1889,8 +1889,8 @@ PLyObject_ToTuple(PLyTypeInfo * info, PyObject * object)
18891889for (i = 0 ;i < desc -> natts ;++ i )
18901890{
18911891char * key ;
1892- PyObject * value ,
1893- * so ;
1892+ PyObject * volatile value ,
1893+ * volatile so ;
18941894
18951895key = NameStr (desc -> attrs [i ]-> attname );
18961896value = so = NULL ;
@@ -2473,13 +2473,14 @@ PLy_spi_execute_plan(PyObject * ob, PyObject * list, long limit)
24732473PG_TRY ();
24742474{
24752475char * nulls = palloc (nargs * sizeof (char ));
2476+ volatile int j ;
24762477
2477- for (i = 0 ;i < nargs ;i ++ )
2478+ for (j = 0 ;j < nargs ;j ++ )
24782479{
24792480PyObject * elem ,
24802481* so ;
24812482
2482- elem = PySequence_GetItem (list ,i );
2483+ elem = PySequence_GetItem (list ,j );
24832484if (elem != Py_None )
24842485{
24852486so = PyObject_Str (elem );
@@ -2492,10 +2493,10 @@ PLy_spi_execute_plan(PyObject * ob, PyObject * list, long limit)
24922493{
24932494char * sv = PyString_AsString (so );
24942495
2495- plan -> values [i ]=
2496- InputFunctionCall (& (plan -> args [i ].out .d .typfunc ),
2496+ plan -> values [j ]=
2497+ InputFunctionCall (& (plan -> args [j ].out .d .typfunc ),
24972498sv ,
2498- plan -> args [i ].out .d .typioparam ,
2499+ plan -> args [j ].out .d .typioparam ,
24992500-1 );
25002501}
25012502PG_CATCH ();
@@ -2506,17 +2507,17 @@ PLy_spi_execute_plan(PyObject * ob, PyObject * list, long limit)
25062507PG_END_TRY ();
25072508
25082509Py_DECREF (so );
2509- nulls [i ]= ' ' ;
2510+ nulls [j ]= ' ' ;
25102511}
25112512else
25122513{
25132514Py_DECREF (elem );
2514- plan -> values [i ]=
2515- InputFunctionCall (& (plan -> args [i ].out .d .typfunc ),
2515+ plan -> values [j ]=
2516+ InputFunctionCall (& (plan -> args [j ].out .d .typfunc ),
25162517NULL ,
2517- plan -> args [i ].out .d .typioparam ,
2518+ plan -> args [j ].out .d .typioparam ,
25182519-1 );
2519- nulls [i ]= 'n' ;
2520+ nulls [j ]= 'n' ;
25202521}
25212522}
25222523
@@ -2527,20 +2528,22 @@ PLy_spi_execute_plan(PyObject * ob, PyObject * list, long limit)
25272528}
25282529PG_CATCH ();
25292530{
2531+ int k ;
2532+
25302533MemoryContextSwitchTo (oldcontext );
25312534PLy_error_in_progress = CopyErrorData ();
25322535FlushErrorState ();
25332536
25342537/*
25352538 * cleanup plan->values array
25362539 */
2537- for (i = 0 ;i < nargs ;i ++ )
2540+ for (k = 0 ;k < nargs ;k ++ )
25382541{
2539- if (!plan -> args [i ].out .d .typbyval &&
2540- (plan -> values [i ]!= PointerGetDatum (NULL )))
2542+ if (!plan -> args [k ].out .d .typbyval &&
2543+ (plan -> values [k ]!= PointerGetDatum (NULL )))
25412544{
2542- pfree (DatumGetPointer (plan -> values [i ]));
2543- plan -> values [i ]= PointerGetDatum (NULL );
2545+ pfree (DatumGetPointer (plan -> values [k ]));
2546+ plan -> values [k ]= PointerGetDatum (NULL );
25442547}
25452548}
25462549