From d2092d57350e822b1fb00f1c059e67f27ee6dc58 Mon Sep 17 00:00:00 2001 From: Daniele Varrazzo Date: Sat, 14 Nov 2020 13:13:43 +0000 Subject: [PATCH] Better use of Python api for numeric load Float remains to be tweaked, as affected by https://github.com/cython/cython/issues/3909 --- psycopg3_c/psycopg3_c/types/numeric.pyx | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) 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) -- 2.47.3