Changeset: c6652f31100a for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=c6652f31100a
Modified Files:
        sql/backends/monet5/UDF/pyapi/connection.c
        sql/backends/monet5/UDF/pyapi/emit.c
        sql/backends/monet5/UDF/pyapi/formatinput.c
        sql/backends/monet5/UDF/pyapi/pyloader.c
        sql/backends/monet5/UDF/pyapi/pytypes.c
        sql/backends/monet5/UDF/pyapi/type_conversion.c
        sql/backends/monet5/UDF/pyapi/unicode.c
Branch: Dec2016
Log Message:

Fixes for Python3 UDFs.


diffs (126 lines):

diff --git a/sql/backends/monet5/UDF/pyapi/connection.c 
b/sql/backends/monet5/UDF/pyapi/connection.c
--- a/sql/backends/monet5/UDF/pyapi/connection.c
+++ b/sql/backends/monet5/UDF/pyapi/connection.c
@@ -156,9 +156,21 @@ static PyMethodDef _connectionObject_met
 };
 
 PyTypeObject Py_ConnectionType = {
-    PyObject_HEAD_INIT(NULL)
-    0,
-    "monetdb._connection",
+    _PyObject_EXTRA_INIT
+// in python3 they use structs within structs to represent this information, 
and many compilers throw warnings if you don't use separate braces
+// to initialize these separate structs. However, in Python2, they use 
#defines to put this information in, so we have these nice #ifdefs
+#ifdef IS_PY3K
+    { { 
+#endif
+        1, NULL 
+#ifdef IS_PY3K
+    }
+#endif 
+    , 0
+#ifdef IS_PY3K
+    }
+#endif
+    , "monetdb._connection",
     sizeof(Py_ConnectionObject),
     0,
     0,                                          /* tp_dealloc */
@@ -243,7 +255,7 @@ PyObject *Py_Connection_Create(Client cn
 }
 
 static void _connection_import_array(void) {
-    import_array();
+    _import_array();
 }
 
 str _connection_init(void)
diff --git a/sql/backends/monet5/UDF/pyapi/emit.c 
b/sql/backends/monet5/UDF/pyapi/emit.c
--- a/sql/backends/monet5/UDF/pyapi/emit.c
+++ b/sql/backends/monet5/UDF/pyapi/emit.c
@@ -312,9 +312,21 @@ static PyMethodDef _emitObject_methods[]
 };
 
 PyTypeObject PyEmitType = {
-    PyObject_HEAD_INIT(NULL)
-    0,
-    "monetdb._emit",
+    _PyObject_EXTRA_INIT
+// in python3 they use structs within structs to represent this information, 
and many compilers throw warnings if you don't use separate braces
+// to initialize these separate structs. However, in Python2, they use 
#defines to put this information in, so we have these nice #ifdefs
+#ifdef IS_PY3K
+    { { 
+#endif
+        1, NULL 
+#ifdef IS_PY3K
+    }
+#endif 
+    , 0
+#ifdef IS_PY3K
+    }
+#endif
+    , "monetdb._emit",
     sizeof(PyEmitObject),
     0,
     0,                                          /* tp_dealloc */
diff --git a/sql/backends/monet5/UDF/pyapi/formatinput.c 
b/sql/backends/monet5/UDF/pyapi/formatinput.c
--- a/sql/backends/monet5/UDF/pyapi/formatinput.c
+++ b/sql/backends/monet5/UDF/pyapi/formatinput.c
@@ -373,5 +373,5 @@ finally:
 }
 
 void _formatinput_init(void) {
-    import_array();
+    _import_array();
 }
diff --git a/sql/backends/monet5/UDF/pyapi/pyloader.c 
b/sql/backends/monet5/UDF/pyapi/pyloader.c
--- a/sql/backends/monet5/UDF/pyapi/pyloader.c
+++ b/sql/backends/monet5/UDF/pyapi/pyloader.c
@@ -9,7 +9,7 @@
 #include "formatinput.h"
 
 static void _loader_import_array(void) {
-    import_array();
+    _import_array();
 }
 
 str _loader_init(void)
diff --git a/sql/backends/monet5/UDF/pyapi/pytypes.c 
b/sql/backends/monet5/UDF/pyapi/pytypes.c
--- a/sql/backends/monet5/UDF/pyapi/pytypes.c
+++ b/sql/backends/monet5/UDF/pyapi/pytypes.c
@@ -170,5 +170,5 @@ bool PyType_IsLazyArray(PyObject *object
 }
 
 void _pytypes_init(void) {
-    import_array();
+    _import_array();
 }
diff --git a/sql/backends/monet5/UDF/pyapi/type_conversion.c 
b/sql/backends/monet5/UDF/pyapi/type_conversion.c
--- a/sql/backends/monet5/UDF/pyapi/type_conversion.c
+++ b/sql/backends/monet5/UDF/pyapi/type_conversion.c
@@ -13,6 +13,8 @@
 
 #if PY_MAJOR_VERSION >= 3
 #define IS_PY3K
+#define PyInt_Check PyLong_Check
+#define PyString_CheckExact PyUnicode_CheckExact
 #endif
 
 bool string_copy(char * source, char* dest, size_t max_size, bool 
allow_unicode)
@@ -351,5 +353,5 @@ CONVERSION_FUNCTION_FACTORY(hge, hge)
 #endif
 
 void _typeconversion_init(void) {
-    import_array();
+    _import_array();
 }
diff --git a/sql/backends/monet5/UDF/pyapi/unicode.c 
b/sql/backends/monet5/UDF/pyapi/unicode.c
--- a/sql/backends/monet5/UDF/pyapi/unicode.c
+++ b/sql/backends/monet5/UDF/pyapi/unicode.c
@@ -207,5 +207,5 @@ bool utf8_to_utf32(size_t offset, size_t
 }
 
 void _unicode_init(void) {
-    import_array();
+    _import_array();
 }
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to