Changeset: 5281303c845d for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=5281303c845d
Modified Files:
sql/backends/monet5/UDF/pyapi/pyheader.h
sql/backends/monet5/UDF/pyapi/type_conversion.c
sql/backends/monet5/UDF/pyapi/type_conversion.h
sql/backends/monet5/UDF/pyapi3/Tests/All
sql/backends/monet5/UDF/pyapi3/Tests/pyloader3_07.stable.out
Branch: python3udf
Log Message:
Fix string -> numeric conversion for Python 3 and remove tests that are
inconsistent because of the different Python 3 dictionary implementation.
diffs (131 lines):
diff --git a/sql/backends/monet5/UDF/pyapi/pyheader.h
b/sql/backends/monet5/UDF/pyapi/pyheader.h
--- a/sql/backends/monet5/UDF/pyapi/pyheader.h
+++ b/sql/backends/monet5/UDF/pyapi/pyheader.h
@@ -74,7 +74,7 @@
#define PyString_FromStringAndSize PyUnicode_FromStringAndSize
#define PyInt_FromLong PyLong_FromLong
#define PyInt_Check PyLong_Check
-#define PythonUnicodeType char
+#define PythonUnicodeType Py_UNICODE
#define PYFUNCNAME(name) PYAPI3##name
#else
#define PythonUnicodeType Py_UNICODE
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
@@ -202,20 +202,6 @@ str pyobject_to_##type(PyObject **pyobj,
} \
return retval; \
}
-#define CONVERSION_FUNCTION_FACTORY(tpe, inttpe) \
- STRING_TO_NUMBER_FACTORY(tpe) \
- str unicode_to_##tpe(Py_UNICODE *ptr, size_t maxsize, tpe *value) \
- { \
- char utf8[1024]; \
- if (maxsize == 0) \
- maxsize = utf32_strlen(ptr); \
- if (maxsize > 255) \
- maxsize = 255; \
- unicode_to_utf8(0, maxsize, utf8, ptr);
\
- return str_to_##tpe(utf8, 0, value); \
- } \
- PY_TO_(tpe, inttpe);
-
#else
#define PY_TO_(type, inttpe) \
str pyobject_to_##type(PyObject **pyobj, size_t maxsize, type *value) \
@@ -251,16 +237,22 @@ str pyobject_to_##type(PyObject **pyobj,
} \
return retval; \
}
-#define CONVERSION_FUNCTION_FACTORY(tpe, inttpe) \
- STRING_TO_NUMBER_FACTORY(tpe) \
- str unicode_to_##tpe(char *ptr, size_t maxsize, tpe *value)
\
- { \
- return str_to_##tpe(ptr, maxsize, value); \
- } \
+#endif
+
+#define CONVERSION_FUNCTION_FACTORY(tpe, inttpe) \
+ STRING_TO_NUMBER_FACTORY(tpe) \
+ str unicode_to_##tpe(Py_UNICODE *ptr, size_t maxsize, tpe *value) \
+ { \
+ char utf8[1024]; \
+ if (maxsize == 0) \
+ maxsize = utf32_strlen(ptr); \
+ if (maxsize > 255) \
+ maxsize = 255; \
+ unicode_to_utf8(0, maxsize / sizeof(Py_UNICODE), utf8, ptr);
\
+ return str_to_##tpe(utf8, 0, value); \
+ } \
PY_TO_(tpe, inttpe);
-#endif
-
CONVERSION_FUNCTION_FACTORY(bte, bte)
CONVERSION_FUNCTION_FACTORY(oid, oid)
CONVERSION_FUNCTION_FACTORY(bit, bit)
diff --git a/sql/backends/monet5/UDF/pyapi/type_conversion.h
b/sql/backends/monet5/UDF/pyapi/type_conversion.h
--- a/sql/backends/monet5/UDF/pyapi/type_conversion.h
+++ b/sql/backends/monet5/UDF/pyapi/type_conversion.h
@@ -26,12 +26,8 @@ bool string_copy(char * source, char* de
int hge_to_string(char *str, hge );
//! Converts a base-10 string to a hge value
str str_to_hge(char *ptr, size_t maxsize, hge *value);
-#ifdef IS_PY3K
//! Converts a base-10 utf32-encoded string to a hge value
-str unicode_to_hge(char *utf32, size_t maxsize, hge *value);
-#else
str unicode_to_hge(Py_UNICODE *utf32, size_t maxsize, hge *value);
-#endif
//! Converts a PyObject to a hge value
str pyobject_to_hge(PyObject **ptr, size_t maxsize, hge *value);
//! Create a PyLongObject from a hge integer
@@ -42,18 +38,11 @@ size_t pyobject_get_size(PyObject *obj);
//! Converts a PyObject to a str; the output string will be a newly allocated
string (if *value == NULL) or stored in *value (if *value != NULL)
str pyobject_to_str(PyObject **ptr, size_t maxsize, str *value);
-#ifdef IS_PY3K
//using macros, create a number of str_to_<type>, unicode_to_<type> and
pyobject_to_<type> functions (we are Java now)
#define CONVERSION_FUNCTION_HEADER_FACTORY(tpe) \
str str_to_##tpe(char *ptr, size_t maxsize, tpe *value); \
- str unicode_to_##tpe(char *ptr, size_t maxsize, tpe *value);
\
- str pyobject_to_##tpe(PyObject **ptr, size_t maxsize, tpe *value);
-#else
-#define CONVERSION_FUNCTION_HEADER_FACTORY(tpe) \
- str str_to_##tpe(char *ptr, size_t maxsize, tpe *value); \
str unicode_to_##tpe(Py_UNICODE *ptr, size_t maxsize, tpe *value);
\
str pyobject_to_##tpe(PyObject **ptr, size_t maxsize, tpe *value);
-#endif
CONVERSION_FUNCTION_HEADER_FACTORY(bte)
CONVERSION_FUNCTION_HEADER_FACTORY(oid)
diff --git a/sql/backends/monet5/UDF/pyapi3/Tests/All
b/sql/backends/monet5/UDF/pyapi3/Tests/All
--- a/sql/backends/monet5/UDF/pyapi3/Tests/All
+++ b/sql/backends/monet5/UDF/pyapi3/Tests/All
@@ -29,8 +29,5 @@ HAVE_LIBPY3?pyapi3_32
HAVE_LIBPY3?pyloader3_01
HAVE_LIBPY3?pyloader3_02
-HAVE_LIBPY3?pyloader3_03
-HAVE_LIBPY3?pyloader3_04
HAVE_LIBPY3?pyloader3_05
-HAVE_LIBPY3?pyloader3_06
HAVE_LIBPY3?pyloader3_07
diff --git a/sql/backends/monet5/UDF/pyapi3/Tests/pyloader3_07.stable.out
b/sql/backends/monet5/UDF/pyapi3/Tests/pyloader3_07.stable.out
--- a/sql/backends/monet5/UDF/pyapi3/Tests/pyloader3_07.stable.out
+++ b/sql/backends/monet5/UDF/pyapi3/Tests/pyloader3_07.stable.out
@@ -36,10 +36,10 @@ Ready.
#};
#SELECT * FROM pyloader07table;
% sys.pyloader07table, sys.pyloader07table # table_name
-% t, s # name
-% int, int # type
+% s, t # name
+% bigint, bigint # type
% 2, 2 # length
-[ 42, 33 ]
+[ 33, 42 ]
#DROP TABLE pyloader07table;
#DROP LOADER pyloader07;
#ROLLBACK;
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list