@@ -28,11 +28,9 @@ static PyObject *PLyObject_FromJsonbContainer(JsonbContainer *jsonb);
28
28
static JsonbValue * PLyObject_ToJsonbValue (PyObject * obj ,
29
29
JsonbParseState * * jsonb_state , bool is_elem );
30
30
31
- #if PY_MAJOR_VERSION >= 3
32
31
typedef PyObject * (* PLyUnicode_FromStringAndSize_t )
33
32
(const char * s , Py_ssize_t size );
34
33
static PLyUnicode_FromStringAndSize_t PLyUnicode_FromStringAndSize_p ;
35
- #endif
36
34
37
35
/*
38
36
* Module initialize function: fetch function pointers for cross-module calls.
@@ -45,13 +43,10 @@ _PG_init(void)
45
43
PLyObject_AsString_p = (PLyObject_AsString_t )
46
44
load_external_function ("$libdir/" PLPYTHON_LIBNAME , "PLyObject_AsString" ,
47
45
true, NULL );
48
- #if PY_MAJOR_VERSION >= 3
49
46
AssertVariableIsOfType (& PLyUnicode_FromStringAndSize , PLyUnicode_FromStringAndSize_t );
50
47
PLyUnicode_FromStringAndSize_p = (PLyUnicode_FromStringAndSize_t )
51
48
load_external_function ("$libdir/" PLPYTHON_LIBNAME , "PLyUnicode_FromStringAndSize" ,
52
49
true, NULL );
53
- #endif
54
-
55
50
AssertVariableIsOfType (& PLy_elog_impl , PLy_elog_impl_t );
56
51
PLy_elog_impl_p = (PLy_elog_impl_t )
57
52
load_external_function ("$libdir/" PLPYTHON_LIBNAME , "PLy_elog_impl" ,
@@ -65,25 +60,25 @@ _PG_init(void)
65
60
#define PLy_elog (PLy_elog_impl_p)
66
61
67
62
/*
68
- * PLyString_FromJsonbValue
63
+ * PLyUnicode_FromJsonbValue
69
64
*
70
65
* Transform string JsonbValue to Python string.
71
66
*/
72
67
static PyObject *
73
- PLyString_FromJsonbValue (JsonbValue * jbv )
68
+ PLyUnicode_FromJsonbValue (JsonbValue * jbv )
74
69
{
75
70
Assert (jbv -> type == jbvString );
76
71
77
- return PyString_FromStringAndSize (jbv -> val .string .val , jbv -> val .string .len );
72
+ return PLyUnicode_FromStringAndSize (jbv -> val .string .val , jbv -> val .string .len );
78
73
}
79
74
80
75
/*
81
- * PLyString_ToJsonbValue
76
+ * PLyUnicode_ToJsonbValue
82
77
*
83
78
* Transform Python string to JsonbValue.
84
79
*/
85
80
static void
86
- PLyString_ToJsonbValue (PyObject * obj , JsonbValue * jbvElem )
81
+ PLyUnicode_ToJsonbValue (PyObject * obj , JsonbValue * jbvElem )
87
82
{
88
83
jbvElem -> type = jbvString ;
89
84
jbvElem -> val .string .val = PLyObject_AsString (obj );
@@ -118,7 +113,7 @@ PLyObject_FromJsonbValue(JsonbValue *jsonbValue)
118
113
}
119
114
120
115
case jbvString :
121
- return PLyString_FromJsonbValue (jsonbValue );
116
+ return PLyUnicode_FromJsonbValue (jsonbValue );
122
117
123
118
case jbvBool :
124
119
if (jsonbValue -> val .boolean )
@@ -210,7 +205,7 @@ PLyObject_FromJsonbContainer(JsonbContainer *jsonb)
210
205
if (r != WJB_KEY )
211
206
continue ;
212
207
213
- key = PLyString_FromJsonbValue (& v );
208
+ key = PLyUnicode_FromJsonbValue (& v );
214
209
if (!key )
215
210
{
216
211
Py_XDECREF (result_v );
@@ -298,7 +293,7 @@ PLyMapping_ToJsonbValue(PyObject *obj, JsonbParseState **jsonb_state)
298
293
else
299
294
{
300
295
/* All others types of keys we serialize to string */
301
- PLyString_ToJsonbValue (key , & jbvKey );
296
+ PLyUnicode_ToJsonbValue (key , & jbvKey );
302
297
}
303
298
304
299
(void ) pushJsonbValue (jsonb_state , WJB_KEY , & jbvKey );
@@ -415,7 +410,7 @@ PLyObject_ToJsonbValue(PyObject *obj, JsonbParseState **jsonb_state, bool is_ele
415
410
{
416
411
JsonbValue * out ;
417
412
418
- if (!( PyString_Check ( obj ) || PyUnicode_Check (obj ) ))
413
+ if (!PyUnicode_Check (obj ))
419
414
{
420
415
if (PySequence_Check (obj ))
421
416
return PLySequence_ToJsonbValue (obj , jsonb_state );
@@ -427,8 +422,8 @@ PLyObject_ToJsonbValue(PyObject *obj, JsonbParseState **jsonb_state, bool is_ele
427
422
428
423
if (obj == Py_None )
429
424
out -> type = jbvNull ;
430
- else if (PyString_Check ( obj ) || PyUnicode_Check (obj ))
431
- PLyString_ToJsonbValue (obj , out );
425
+ else if (PyUnicode_Check (obj ))
426
+ PLyUnicode_ToJsonbValue (obj , out );
432
427
433
428
/*
434
429
* PyNumber_Check() returns true for booleans, so boolean check should
0 commit comments