Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit c714e5c

Browse files
committed
Fix plpython to work (or at least pass its regression tests) with
python 2.5. This involves fixing several violations of the published spec for creating PyTypeObjects, and adding another regression test expected output for yet another variation of error message spelling.
1 parent a48e92e commit c714e5c

File tree

2 files changed

+48
-6
lines changed

2 files changed

+48
-6
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
-- test error handling, i forgot to restore Warn_restart in
2+
-- the trigger handler once. the errors and subsequent core dump were
3+
-- interesting.
4+
SELECT invalid_type_uncaught('rick');
5+
WARNING: plpython: in function invalid_type_uncaught:
6+
DETAIL: <class 'plpy.SPIError'>: Unknown error in PLy_spi_prepare
7+
ERROR: type "test" does not exist
8+
SELECT invalid_type_caught('rick');
9+
WARNING: plpython: in function invalid_type_caught:
10+
DETAIL: <class 'plpy.SPIError'>: Unknown error in PLy_spi_prepare
11+
ERROR: type "test" does not exist
12+
SELECT invalid_type_reraised('rick');
13+
WARNING: plpython: in function invalid_type_reraised:
14+
DETAIL: <class 'plpy.SPIError'>: Unknown error in PLy_spi_prepare
15+
ERROR: type "test" does not exist
16+
SELECT valid_type('rick');
17+
valid_type
18+
------------
19+
20+
(1 row)
21+
22+
--
23+
-- Test Unicode error handling.
24+
--
25+
SELECT unicode_return_error();
26+
ERROR: plpython: function "unicode_return_error" could not create return value
27+
DETAIL: <type 'exceptions.UnicodeEncodeError'>: 'ascii' codec can't encode character u'\x80' in position 0: ordinal not in range(128)
28+
INSERT INTO unicode_test (testvalue) VALUES ('test');
29+
ERROR: plpython: function "unicode_trigger_error" could not modify tuple
30+
DETAIL: <type 'exceptions.UnicodeEncodeError'>: 'ascii' codec can't encode character u'\x80' in position 0: ordinal not in range(128)
31+
SELECT unicode_plan_error1();
32+
WARNING: plpython: in function unicode_plan_error1:
33+
DETAIL: <class 'plpy.Error'>: Unknown error in PLy_spi_execute_plan
34+
ERROR: plpython: function "unicode_plan_error1" could not execute plan
35+
DETAIL: <type 'exceptions.UnicodeEncodeError'>: 'ascii' codec can't encode character u'\x80' in position 0: ordinal not in range(128)
36+
SELECT unicode_plan_error2();
37+
ERROR: plpython: function "unicode_plan_error2" could not execute plan
38+
DETAIL: <type 'exceptions.UnicodeEncodeError'>: 'ascii' codec can't encode character u'\x80' in position 0: ordinal not in range(128)

src/pl/plpython/plpython.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**********************************************************************
22
* plpython.c - python as a procedural language for PostgreSQL
33
*
4-
* $PostgreSQL: pgsql/src/pl/plpython/plpython.c,v 1.89 2006/10/04 00:30:14 momjian Exp $
4+
* $PostgreSQL: pgsql/src/pl/plpython/plpython.c,v 1.90 2006/11/21 21:51:05 tgl Exp $
55
*
66
*********************************************************************
77
*/
@@ -1981,7 +1981,7 @@ static PyTypeObject PLy_PlanType = {
19811981
0, /* tp_getattro */
19821982
0, /* tp_setattro */
19831983
0, /* tp_as_buffer */
1984-
0, /* tp_xxx4 */
1984+
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
19851985
PLy_plan_doc, /* tp_doc */
19861986
};
19871987

@@ -2026,7 +2026,7 @@ static PyTypeObject PLy_ResultType = {
20262026
0, /* tp_getattro */
20272027
0, /* tp_setattro */
20282028
0, /* tp_as_buffer */
2029-
0, /* tp_xxx4 */
2029+
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
20302030
PLy_result_doc, /* tp_doc */
20312031
};
20322032

@@ -2098,7 +2098,7 @@ PLy_plan_dealloc(PyObject * arg)
20982098
PLy_free(ob->args);
20992099
}
21002100

2101-
PyMem_DEL(arg);
2101+
arg->ob_type->tp_free(arg);
21022102
}
21032103

21042104

@@ -2152,7 +2152,7 @@ PLy_result_dealloc(PyObject * arg)
21522152
Py_XDECREF(ob->rows);
21532153
Py_XDECREF(ob->status);
21542154

2155-
PyMem_DEL(ob);
2155+
arg->ob_type->tp_free(arg);
21562156
}
21572157

21582158
static PyObject *
@@ -2701,7 +2701,11 @@ PLy_init_plpy(void)
27012701
/*
27022702
* initialize plpy module
27032703
*/
2704-
PLy_PlanType.ob_type = PLy_ResultType.ob_type = &PyType_Type;
2704+
if (PyType_Ready(&PLy_PlanType) < 0)
2705+
elog(ERROR, "could not init PLy_PlanType");
2706+
if (PyType_Ready(&PLy_ResultType) < 0)
2707+
elog(ERROR, "could not init PLy_ResultType");
2708+
27052709
plpy = Py_InitModule("plpy", PLy_methods);
27062710
plpy_dict = PyModule_GetDict(plpy);
27072711

0 commit comments

Comments
 (0)