Changeset: 74c729009c37 for MonetDB URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=74c729009c37 Modified Files: sql/backends/monet5/UDF/pyapi3/connection3.c sql/backends/monet5/UDF/pyapi3/convert_loops.h sql/backends/monet5/UDF/pyapi3/formatinput3.c sql/backends/monet5/UDF/pyapi3/pyapi3.c sql/backends/monet5/UDF/pyapi3/pyheader.h sql/backends/monet5/UDF/pyapi3/pytypes3.c sql/backends/monet5/UDF/pyapi3/type_conversion.h sql/backends/monet5/UDF/pyapi3/type_conversion3.c sql/backends/monet5/sql.mal testing/malcheck.py Branch: mbedded Log Message:
merged with default diffs (truncated from 337 to 300 lines): diff --git a/sql/backends/monet5/UDF/pyapi3/connection3.c b/sql/backends/monet5/UDF/pyapi3/connection3.c --- a/sql/backends/monet5/UDF/pyapi3/connection3.c +++ b/sql/backends/monet5/UDF/pyapi3/connection3.c @@ -21,23 +21,8 @@ CREATE_SQL_FUNCTION_PTR(str, append_to_t static PyObject *_connection_execute(Py_ConnectionObject *self, PyObject *args) { char *query = NULL; -#ifndef IS_PY3K - if (PyUnicode_CheckExact(args)) { - PyObject* str = PyUnicode_AsUTF8String(args); - if (!str) { - PyErr_Format(PyExc_Exception, "Unicode failure."); - return NULL; - } - query = GDKstrdup(((PyStringObject *)str)->ob_sval); - Py_DECREF(str); - } else -#endif if (PyString_CheckExact(args)) { -#ifndef IS_PY3K - query = GDKstrdup(((PyStringObject *)args)->ob_sval); -#else query = GDKstrdup(PyUnicode_AsUTF8(args)); -#endif } else { PyErr_Format(PyExc_TypeError, "expected a query string, but got an object of type %s", diff --git a/sql/backends/monet5/UDF/pyapi3/convert_loops.h b/sql/backends/monet5/UDF/pyapi3/convert_loops.h --- a/sql/backends/monet5/UDF/pyapi3/convert_loops.h +++ b/sql/backends/monet5/UDF/pyapi3/convert_loops.h @@ -463,7 +463,7 @@ convert_and_append(BAT* b, const char* t goto wrapup; \ } \ } else { \ - if (!string_copy(&data[(index_offset * ret->count + iu) * \ + if (!pyapi3_string_copy(&data[(index_offset * ret->count + iu) * \ ret->memory_size], \ utf8_string, ret->memory_size, false)) { \ msg = createException(MAL, "pyapi3.eval", \ diff --git a/sql/backends/monet5/UDF/pyapi3/formatinput3.c b/sql/backends/monet5/UDF/pyapi3/formatinput3.c --- a/sql/backends/monet5/UDF/pyapi3/formatinput3.c +++ b/sql/backends/monet5/UDF/pyapi3/formatinput3.c @@ -107,14 +107,7 @@ char *FormatCode(char *code, char **args char base_start[] = "def pyfun("; char base_end[] = "):\n"; *msg = NULL; -#ifndef IS_PY3K - if (code[1] == '@') { - *code_object = PyCodeObject_ParseString(code, msg); - return NULL; - } -#else (void)code_object; -#endif indentation_levels = (size_t *)GDKzalloc(max_indentation * sizeof(size_t)); statements_per_level = diff --git a/sql/backends/monet5/UDF/pyapi3/pyapi3.c b/sql/backends/monet5/UDF/pyapi3/pyapi3.c --- a/sql/backends/monet5/UDF/pyapi3/pyapi3.c +++ b/sql/backends/monet5/UDF/pyapi3/pyapi3.c @@ -985,11 +985,7 @@ static str PyAPIeval(Client cntxt, MalBl colname->ob_type->tp_name); goto wrapup; } -#ifndef IS_PY3K - retnames[i] = ((PyStringObject *)colname)->ob_sval; -#else retnames[i] = (char *) PyUnicode_AsUTF8(colname); -#endif } } pResult = @@ -1328,12 +1324,8 @@ PYFUNCNAME(PyAPIprelude)(void *ret) { (void) ret; MT_lock_set(&pyapiLock); if (!pyapiInitialized) { -#ifdef IS_PY3K wchar_t* program = Py_DecodeLocale("mserver5", NULL); wchar_t* argv[] = { program }; -#else - char* argv[] = {"mserver5"}; -#endif str msg = MAL_SUCCEED; PyObject *tmp; Py_Initialize(); @@ -1374,13 +1366,7 @@ PYFUNCNAME(PyAPIprelude)(void *ret) { return msg; } pyapiInitialized = true; - fprintf(stdout, "# MonetDB/Python%d module loaded\n", -#ifdef IS_PY3K - 3 -#else - 2 -#endif - ); + fprintf(stdout, "# MonetDB/Python%d module loaded\n", 3); } MT_lock_unset(&pyapiLock); option_disable_fork = GDKgetenv_istrue(fork_disableflag) || GDKgetenv_isyes(fork_disableflag); diff --git a/sql/backends/monet5/UDF/pyapi3/pyheader.h b/sql/backends/monet5/UDF/pyapi3/pyheader.h --- a/sql/backends/monet5/UDF/pyapi3/pyheader.h +++ b/sql/backends/monet5/UDF/pyapi3/pyheader.h @@ -66,9 +66,6 @@ #define pyapi_export extern #endif -// Fixes for Python 2 <> Python 3 -#if PY_MAJOR_VERSION >= 3 -#define IS_PY3K #define PyString_FromString PyUnicode_FromString #define PyString_Check PyUnicode_Check #define PyString_CheckExact PyUnicode_CheckExact @@ -79,10 +76,6 @@ #define PyInt_Check PyLong_Check #define PythonUnicodeType Py_UNICODE #define PYFUNCNAME(name) PYAPI3##name -#else -#define PythonUnicodeType Py_UNICODE -#define PYFUNCNAME(name) PYAPI2##name -#endif #if defined(WIN32) // On Windows we need to dynamically load any SQL functions we use diff --git a/sql/backends/monet5/UDF/pyapi3/pytypes3.c b/sql/backends/monet5/UDF/pyapi3/pytypes3.c --- a/sql/backends/monet5/UDF/pyapi3/pytypes3.c +++ b/sql/backends/monet5/UDF/pyapi3/pytypes3.c @@ -275,10 +275,7 @@ bool PyType_IsPyScalar(PyObject *object) PyFloat_Check(object) || PyLong_Check(object) || PyString_Check(object) || PyBool_Check(object) || PyUnicode_Check(object) || PyByteArray_Check(object) -#ifdef IS_PY3K - || PyBytes_Check(object) -#endif - ); + || PyBytes_Check(object)); } void _pytypes_init(void) { _import_array(); } diff --git a/sql/backends/monet5/UDF/pyapi3/type_conversion.h b/sql/backends/monet5/UDF/pyapi3/type_conversion.h --- a/sql/backends/monet5/UDF/pyapi3/type_conversion.h +++ b/sql/backends/monet5/UDF/pyapi3/type_conversion.h @@ -24,7 +24,7 @@ //! Copies the string of size up to max_size from the source to the destination, //! returns FALSE if "source" is not a legal ASCII string (i.e. a character is //! >= 128) -bool string_copy(const char *source, char *dest, size_t max_size, bool allow_unicode); +bool pyapi3_string_copy(const char *source, char *dest, size_t max_size, bool allow_unicode); #ifdef HAVE_HGE //! Converts a hge to a string and writes it into the string "str" int hge_to_string(char *str, hge); diff --git a/sql/backends/monet5/UDF/pyapi3/type_conversion3.c b/sql/backends/monet5/UDF/pyapi3/type_conversion3.c --- a/sql/backends/monet5/UDF/pyapi3/type_conversion3.c +++ b/sql/backends/monet5/UDF/pyapi3/type_conversion3.c @@ -12,13 +12,10 @@ #include <longintrepr.h> -#if PY_MAJOR_VERSION >= 3 -#define IS_PY3K #define PyInt_Check PyLong_Check #define PyString_CheckExact PyUnicode_CheckExact -#endif -bool string_copy(const char *source, char *dest, size_t max_size, bool allow_unicode) +bool pyapi3_string_copy(const char *source, char *dest, size_t max_size, bool allow_unicode) { size_t i; for (i = 0; i < max_size; i++) { @@ -67,11 +64,7 @@ size_t pyobject_get_size(PyObject *obj) { size_t size = 256; - if ( -#ifndef IS_PY3K - PyString_CheckExact(obj) || -#endif - PyByteArray_CheckExact(obj)) { + if (PyByteArray_CheckExact(obj)) { size = Py_SIZE(obj); // Normal strings are 1 byte per character } else if (PyUnicode_CheckExact(obj)) { size = Py_SIZE(obj) * 4; // UTF32 is 4 bytes per character @@ -92,12 +85,6 @@ str pyobject_to_blob(PyObject **ptr, siz obj = *ptr; (void)maxsize; -#ifndef IS_PY3K - if (PyString_CheckExact(obj)) { - size = PyString_Size(obj); - bytes_data = ((PyStringObject *)obj)->ob_sval; - } else -#endif if (PyByteArray_CheckExact(obj)) { size = PyByteArray_Size(obj); bytes_data = ((PyByteArrayObject *)obj)->ob_bytes; @@ -145,45 +132,24 @@ str pyobject_to_str(PyObject **ptr, size len = maxsize; } -#ifndef IS_PY3K - if (PyString_CheckExact(obj)) { - char *str = ((PyStringObject *)obj)->ob_sval; - if (!string_copy(str, utf8_string, len-1, false)) { + if (PyByteArray_CheckExact(obj)) { + char *str = ((PyByteArrayObject *)obj)->ob_bytes; + if (!pyapi3_string_copy(str, utf8_string, len-1, false)) { msg = createException(MAL, "pyapi3.eval", - SQLSTATE(PY000) "Invalid string encoding used. Please return " - "a regular ASCII string, or a Numpy_Unicode " - "object.\n"); - goto wrapup; - } - } else -#endif - if (PyByteArray_CheckExact(obj)) { - char *str = ((PyByteArrayObject *)obj)->ob_bytes; - if (!string_copy(str, utf8_string, len-1, false)) { - msg = createException(MAL, "pyapi3.eval", - SQLSTATE(PY000) "Invalid string encoding used. Please return " - "a regular ASCII string, or a Numpy_Unicode " - "object.\n"); + SQLSTATE(PY000) "Invalid string encoding used. Please return " + "a regular ASCII string, or a Numpy_Unicode " + "object.\n"); goto wrapup; } } else if (PyUnicode_CheckExact(obj)) { -#ifndef IS_PY3K - Py_UNICODE *str = (Py_UNICODE *)((PyUnicodeObject *)obj)->str; -#if Py_UNICODE_SIZE >= 4 - utf32_to_utf8(0, ((PyUnicodeObject *)obj)->length, utf8_string, str); -#else - ucs2_to_utf8(0, ((PyUnicodeObject *)obj)->length, utf8_string, str); -#endif -#else const char *str = PyUnicode_AsUTF8(obj); - if (!string_copy(str, utf8_string, len-1, true)) { + if (!pyapi3_string_copy(str, utf8_string, len-1, true)) { msg = createException(MAL, "pyapi3.eval", - SQLSTATE(PY000) "Invalid string encoding used. Please return " - "a regular ASCII string, or a Numpy_Unicode " - "object.\n"); + SQLSTATE(PY000) "Invalid string encoding used. Please return " + "a regular ASCII string, or a Numpy_Unicode " + "object.\n"); goto wrapup; } -#endif } else if (PyBool_Check(obj) || PyLong_Check(obj) || PyInt_Check(obj) || PyFloat_Check(obj)) { #ifdef HAVE_HGE @@ -224,44 +190,6 @@ wrapup: return MAL_SUCCEED; \ } -#ifndef IS_PY3K -#define PY_TO_(type, inttpe) \ -str pyobject_to_##type(PyObject **pyobj, size_t maxsize, type *value) \ -{ \ - PyObject *ptr = *pyobj; \ - str retval = MAL_SUCCEED; \ - (void) maxsize; \ - if (PyLong_CheckExact(ptr)) { \ - PyLongObject *p = (PyLongObject*) ptr; \ - inttpe h = 0; \ - inttpe prev = 0; \ - ssize_t i = Py_SIZE(p); \ - int sign = i < 0 ? -1 : 1; \ - i *= sign; \ - while (--i >= 0) { \ - prev = h; (void)prev; \ - h = (h << PyLong_SHIFT) + p->ob_digit[i]; \ - if ((h >> PyLong_SHIFT) != prev) { \ - return GDKstrdup("Overflow when converting value."); \ - } \ - } \ - *value = (type)(h * sign); \ - } else if (PyInt_CheckExact(ptr) || PyBool_Check(ptr)) { \ - *value = (type)((PyIntObject*)ptr)->ob_ival; \ - } else if (PyFloat_CheckExact(ptr)) { \ - *value = isnan(((PyFloatObject*)ptr)->ob_fval) ? type##_nil : (type) ((PyFloatObject*)ptr)->ob_fval; \ - } else if (PyString_CheckExact(ptr)) { \ - return str_to_##type(((PyStringObject*)ptr)->ob_sval, 0, value); \ - } else if (PyByteArray_CheckExact(ptr)) { \ - return str_to_##type(((PyByteArrayObject*)ptr)->ob_bytes, 0, value); \ - } else if (PyUnicode_CheckExact(ptr)) { \ - return unicode_to_##type(((PyUnicodeObject*)ptr)->str, 0, value); \ - } else if (ptr == Py_None) { \ - *value = type##_nil; \ - } \ - return retval; \ -} -#else #define PY_TO_(type, inttpe) \ str pyobject_to_##type(PyObject **pyobj, size_t maxsize, type *value) \ { \ @@ -296,7 +224,6 @@ str pyobject_to_##type(PyObject **pyobj, } \ return retval; \ } _______________________________________________ checkin-list mailing list checkin-list@monetdb.org https://www.monetdb.org/mailman/listinfo/checkin-list