@@ -11,20 +11,22 @@ extern void _PG_init(void);
1111
1212/* Linkage to functions in plpython module */
1313typedef char * (* PLyObject_AsString_t ) (PyObject * plrv );
14-
1514static 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 */
1821typedef 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-
2422static hstoreUpgrade_t hstoreUpgrade_p ;
23+ typedef int (* hstoreUniquePairs_t ) (Pairs * a ,int32 l ,int32 * buflen );
2524static hstoreUniquePairs_t hstoreUniquePairs_p ;
25+ typedef HStore * (* hstorePairs_t ) (Pairs * pairs ,int32 pcount ,int32 buflen );
2626static hstorePairs_t hstorePairs_p ;
27+ typedef size_t (* hstoreCheckKeyLen_t ) (size_t len );
2728static hstoreCheckKeyLen_t hstoreCheckKeyLen_p ;
29+ typedef size_t (* hstoreCheckValLen_t ) (size_t len );
2830static hstoreCheckValLen_t hstoreCheckValLen_p ;
2931
3032
@@ -34,29 +36,34 @@ static hstoreCheckValLen_t hstoreCheckValLen_p;
3436void
3537_PG_init (void )
3638{
37- /*These asserts verify that typedefs above match original declarations */
39+ /*Asserts verify that typedefs above match original declarations */
3840AssertVariableIsOfType (& 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-
4541PLyObject_AsString_p = (PLyObject_AsString_t )
4642load_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 );
4851hstoreUpgrade_p = (hstoreUpgrade_t )
4952load_external_function ("$libdir/hstore" ,"hstoreUpgrade" ,
5053 true,NULL );
54+ AssertVariableIsOfType (& hstoreUniquePairs ,hstoreUniquePairs_t );
5155hstoreUniquePairs_p = (hstoreUniquePairs_t )
5256load_external_function ("$libdir/hstore" ,"hstoreUniquePairs" ,
5357 true,NULL );
58+ AssertVariableIsOfType (& hstorePairs ,hstorePairs_t );
5459hstorePairs_p = (hstorePairs_t )
5560load_external_function ("$libdir/hstore" ,"hstorePairs" ,
5661 true,NULL );
62+ AssertVariableIsOfType (& hstoreCheckKeyLen ,hstoreCheckKeyLen_t );
5763hstoreCheckKeyLen_p = (hstoreCheckKeyLen_t )
5864load_external_function ("$libdir/hstore" ,"hstoreCheckKeyLen" ,
5965 true,NULL );
66+ AssertVariableIsOfType (& hstoreCheckValLen ,hstoreCheckValLen_t );
6067hstoreCheckValLen_p = (hstoreCheckValLen_t )
6168load_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