]> git.ipfire.org Git - thirdparty/psycopg.git/commitdiff
Better use of Python api for numeric load
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>
Sat, 14 Nov 2020 13:13:43 +0000 (13:13 +0000)
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>
Sat, 14 Nov 2020 14:19:54 +0000 (14:19 +0000)
Float remains to be tweaked, as affected by
https://github.com/cython/cython/issues/3909

psycopg3_c/psycopg3_c/types/numeric.pyx

index 67399dd0cb952bdfc4a0d04ade1a03527b44fd91..c0f6fcc24222e3d3597a5737d3bf49f2f483c4ba 100644 (file)
@@ -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)