@@ -11,20 +11,22 @@ extern void _PG_init(void);
11
11
12
12
/* Linkage to functions in plpython module */
13
13
typedef char * (* PLyObject_AsString_t ) (PyObject * plrv );
14
-
15
14
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
16
19
17
20
/* Linkage to functions in hstore module */
18
21
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
-
24
22
static hstoreUpgrade_t hstoreUpgrade_p ;
23
+ typedef int (* hstoreUniquePairs_t ) (Pairs * a , int32 l , int32 * buflen );
25
24
static hstoreUniquePairs_t hstoreUniquePairs_p ;
25
+ typedef HStore * (* hstorePairs_t ) (Pairs * pairs , int32 pcount , int32 buflen );
26
26
static hstorePairs_t hstorePairs_p ;
27
+ typedef size_t (* hstoreCheckKeyLen_t ) (size_t len );
27
28
static hstoreCheckKeyLen_t hstoreCheckKeyLen_p ;
29
+ typedef size_t (* hstoreCheckValLen_t ) (size_t len );
28
30
static hstoreCheckValLen_t hstoreCheckValLen_p ;
29
31
30
32
@@ -34,29 +36,34 @@ static hstoreCheckValLen_t hstoreCheckValLen_p;
34
36
void
35
37
_PG_init (void )
36
38
{
37
- /* These asserts verify that typedefs above match original declarations */
39
+ /* Asserts verify that typedefs above match original declarations */
38
40
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
-
45
41
PLyObject_AsString_p = (PLyObject_AsString_t )
46
42
load_external_function ("$libdir/" PLPYTHON_LIBNAME , "PLyObject_AsString" ,
47
43
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 );
48
51
hstoreUpgrade_p = (hstoreUpgrade_t )
49
52
load_external_function ("$libdir/hstore" , "hstoreUpgrade" ,
50
53
true, NULL );
54
+ AssertVariableIsOfType (& hstoreUniquePairs , hstoreUniquePairs_t );
51
55
hstoreUniquePairs_p = (hstoreUniquePairs_t )
52
56
load_external_function ("$libdir/hstore" , "hstoreUniquePairs" ,
53
57
true, NULL );
58
+ AssertVariableIsOfType (& hstorePairs , hstorePairs_t );
54
59
hstorePairs_p = (hstorePairs_t )
55
60
load_external_function ("$libdir/hstore" , "hstorePairs" ,
56
61
true, NULL );
62
+ AssertVariableIsOfType (& hstoreCheckKeyLen , hstoreCheckKeyLen_t );
57
63
hstoreCheckKeyLen_p = (hstoreCheckKeyLen_t )
58
64
load_external_function ("$libdir/hstore" , "hstoreCheckKeyLen" ,
59
65
true, NULL );
66
+ AssertVariableIsOfType (& hstoreCheckValLen , hstoreCheckValLen_t );
60
67
hstoreCheckValLen_p = (hstoreCheckValLen_t )
61
68
load_external_function ("$libdir/hstore" , "hstoreCheckValLen" ,
62
69
true, NULL );
@@ -65,6 +72,7 @@ _PG_init(void)
65
72
66
73
/* These defines must be after the module init function */
67
74
#define PLyObject_AsString PLyObject_AsString_p
75
+ #define PLyUnicode_FromStringAndSize PLyUnicode_FromStringAndSize_p
68
76
#define hstoreUpgrade hstoreUpgrade_p
69
77
#define hstoreUniquePairs hstoreUniquePairs_p
70
78
#define hstorePairs hstorePairs_p
0 commit comments