From: Daniele Varrazzo Date: Sat, 14 Nov 2020 13:13:43 +0000 (+0000) Subject: Better use of Python api for numeric load X-Git-Tag: 3.0.dev0~361 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d2092d57350e822b1fb00f1c059e67f27ee6dc58;p=thirdparty%2Fpsycopg.git Better use of Python api for numeric load Float remains to be tweaked, as affected by https://github.com/cython/cython/issues/3909 --- diff --git a/psycopg3_c/psycopg3_c/types/numeric.pyx b/psycopg3_c/psycopg3_c/types/numeric.pyx index 67399dd0c..c0f6fcc24 100644 --- a/psycopg3_c/psycopg3_c/types/numeric.pyx +++ b/psycopg3_c/psycopg3_c/types/numeric.pyx @@ -7,14 +7,14 @@ Cython adapters for numeric types. from libc.stdint cimport * from psycopg3_c.endian cimport be16toh, be32toh, be64toh -from cpython.long cimport ( - PyLong_FromLong, PyLong_FromLongLong, PyLong_FromUnsignedLong) -from cpython.float cimport PyFloat_FromDouble +from cpython.long cimport PyLong_FromString, PyLong_FromLong +from cpython.long cimport PyLong_FromLongLong, PyLong_FromUnsignedLong +from cpython.float cimport PyFloat_FromString, PyFloat_FromDouble cdef class IntLoader(CLoader): cdef object cload(self, const char *data, size_t length): - return int(data) + return PyLong_FromString(data, NULL, 10) cdef class Int2BinaryLoader(CLoader): @@ -39,6 +39,9 @@ cdef class OidBinaryLoader(CLoader): cdef class FloatLoader(CLoader): cdef object cload(self, const char *data, size_t length): + # TODO: change after https://github.com/cython/cython/issues/3909 fixed + # cdef bytes b = data + # return PyFloat_FromString(b) return float(data)