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

Commit 490ed1e

Browse files
committed
Fix hstore_plpython for Python 3.
In commit d51924b, I overlooked the need to provide linkage for PLyUnicode_FromStringAndSize, because that's only used (and indeed only exists) in Python 3 builds. In light of the need to #if this item, rearrange the ordering of the code related to each function pointer, so as not to need more #if's than absolutely necessary. Per buildfarm.
1 parent c86c2d9 commit 490ed1e

File tree

1 file changed

+21
-13
lines changed

1 file changed

+21
-13
lines changed

contrib/hstore_plpython/hstore_plpython.c

+21-13
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,22 @@ extern void _PG_init(void);
1111

1212
/* Linkage to functions in plpython module */
1313
typedef char *(*PLyObject_AsString_t) (PyObject *plrv);
14-
1514
static PLyObject_AsString_t PLyObject_AsString_p;
15+
#if PY_MAJOR_VERSION >= 3
16+
typedef PyObject *(*PLyUnicode_FromStringAndSize_t) (const char *s, Py_ssize_t size);
17+
static PLyUnicode_FromStringAndSize_t PLyUnicode_FromStringAndSize_p;
18+
#endif
1619

1720
/* Linkage to functions in hstore module */
1821
typedef HStore *(*hstoreUpgrade_t) (Datum orig);
19-
typedef int (*hstoreUniquePairs_t) (Pairs *a, int32 l, int32 *buflen);
20-
typedef HStore *(*hstorePairs_t) (Pairs *pairs, int32 pcount, int32 buflen);
21-
typedef size_t (*hstoreCheckKeyLen_t) (size_t len);
22-
typedef size_t (*hstoreCheckValLen_t) (size_t len);
23-
2422
static hstoreUpgrade_t hstoreUpgrade_p;
23+
typedef int (*hstoreUniquePairs_t) (Pairs *a, int32 l, int32 *buflen);
2524
static hstoreUniquePairs_t hstoreUniquePairs_p;
25+
typedef HStore *(*hstorePairs_t) (Pairs *pairs, int32 pcount, int32 buflen);
2626
static hstorePairs_t hstorePairs_p;
27+
typedef size_t (*hstoreCheckKeyLen_t) (size_t len);
2728
static hstoreCheckKeyLen_t hstoreCheckKeyLen_p;
29+
typedef size_t (*hstoreCheckValLen_t) (size_t len);
2830
static hstoreCheckValLen_t hstoreCheckValLen_p;
2931

3032

@@ -34,29 +36,34 @@ static hstoreCheckValLen_t hstoreCheckValLen_p;
3436
void
3537
_PG_init(void)
3638
{
37-
/* These asserts verify that typedefs above match original declarations */
39+
/* Asserts verify that typedefs above match original declarations */
3840
AssertVariableIsOfType(&PLyObject_AsString, PLyObject_AsString_t);
39-
AssertVariableIsOfType(&hstoreUpgrade, hstoreUpgrade_t);
40-
AssertVariableIsOfType(&hstoreUniquePairs, hstoreUniquePairs_t);
41-
AssertVariableIsOfType(&hstorePairs, hstorePairs_t);
42-
AssertVariableIsOfType(&hstoreCheckKeyLen, hstoreCheckKeyLen_t);
43-
AssertVariableIsOfType(&hstoreCheckValLen, hstoreCheckValLen_t);
44-
4541
PLyObject_AsString_p = (PLyObject_AsString_t)
4642
load_external_function("$libdir/" PLPYTHON_LIBNAME, "PLyObject_AsString",
4743
true, NULL);
44+
#if PY_MAJOR_VERSION >= 3
45+
AssertVariableIsOfType(&PLyUnicode_FromStringAndSize, PLyUnicode_FromStringAndSize_t);
46+
PLyUnicode_FromStringAndSize_p = (PLyUnicode_FromStringAndSize_t)
47+
load_external_function("$libdir/" PLPYTHON_LIBNAME, "PLyUnicode_FromStringAndSize",
48+
true, NULL);
49+
#endif
50+
AssertVariableIsOfType(&hstoreUpgrade, hstoreUpgrade_t);
4851
hstoreUpgrade_p = (hstoreUpgrade_t)
4952
load_external_function("$libdir/hstore", "hstoreUpgrade",
5053
true, NULL);
54+
AssertVariableIsOfType(&hstoreUniquePairs, hstoreUniquePairs_t);
5155
hstoreUniquePairs_p = (hstoreUniquePairs_t)
5256
load_external_function("$libdir/hstore", "hstoreUniquePairs",
5357
true, NULL);
58+
AssertVariableIsOfType(&hstorePairs, hstorePairs_t);
5459
hstorePairs_p = (hstorePairs_t)
5560
load_external_function("$libdir/hstore", "hstorePairs",
5661
true, NULL);
62+
AssertVariableIsOfType(&hstoreCheckKeyLen, hstoreCheckKeyLen_t);
5763
hstoreCheckKeyLen_p = (hstoreCheckKeyLen_t)
5864
load_external_function("$libdir/hstore", "hstoreCheckKeyLen",
5965
true, NULL);
66+
AssertVariableIsOfType(&hstoreCheckValLen, hstoreCheckValLen_t);
6067
hstoreCheckValLen_p = (hstoreCheckValLen_t)
6168
load_external_function("$libdir/hstore", "hstoreCheckValLen",
6269
true, NULL);
@@ -65,6 +72,7 @@ _PG_init(void)
6572

6673
/* These defines must be after the module init function */
6774
#define PLyObject_AsString PLyObject_AsString_p
75+
#define PLyUnicode_FromStringAndSize PLyUnicode_FromStringAndSize_p
6876
#define hstoreUpgrade hstoreUpgrade_p
6977
#define hstoreUniquePairs hstoreUniquePairs_p
7078
#define hstorePairs hstorePairs_p

0 commit comments

Comments
 (0)