From 852884e086706625a69247f2ddafd1a1465b138c Mon Sep 17 00:00:00 2001 From: Glyph Date: Tue, 12 Dec 2017 03:06:18 -0800 Subject: [PATCH 1/4] use accessor macros for pypy3 compatibility --- psycopg/adapter_datetime.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/psycopg/adapter_datetime.c b/psycopg/adapter_datetime.c index 9d04df40..a78311ee 100644 --- a/psycopg/adapter_datetime.c +++ b/psycopg/adapter_datetime.c @@ -100,7 +100,7 @@ _pydatetime_string_delta(pydatetimeObject *self) char buffer[8]; int i; - int a = obj->microseconds; + int a = PyDateTime_DELTA_GET_MICROSECONDS(obj); for (i=0; i < 6 ; i++) { buffer[5-i] = '0' + (a % 10); @@ -109,7 +109,9 @@ _pydatetime_string_delta(pydatetimeObject *self) buffer[6] = '\0'; return Bytes_FromFormat("'%d days %d.%s seconds'::interval", - obj->days, obj->seconds, buffer); + PyDateTime_DELTA_GET_DAYS(obj), + PyDateTime_DELTA_GET_SECONDS(obj), + buffer); } static PyObject * From 3fcb0351265e3077ee4088ba6e90016e5735a2a1 Mon Sep 17 00:00:00 2001 From: Glyph Date: Tue, 12 Dec 2017 03:12:54 -0800 Subject: [PATCH 2/4] define a "polyfill" inline for python 2 compatibility --- psycopg/adapter_datetime.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/psycopg/adapter_datetime.c b/psycopg/adapter_datetime.c index a78311ee..b5135efb 100644 --- a/psycopg/adapter_datetime.c +++ b/psycopg/adapter_datetime.c @@ -93,6 +93,12 @@ error: return rv; } +#ifndef PyDateTime_DELTA_GET_DAYS +#define PyDateTime_DELTA_GET_DAYS(o) (o->days) +#define PyDateTime_DELTA_GET_SECONDS(o) (o->seconds) +#define PyDateTime_DELTA_GET_MICROSECONDS(o) (o->microseconds) +#endif + static PyObject * _pydatetime_string_delta(pydatetimeObject *self) { From 77c703395befce2cc87a18a5ec706f5500f04f04 Mon Sep 17 00:00:00 2001 From: Daniele Varrazzo Date: Wed, 10 Jan 2018 22:24:05 +0000 Subject: [PATCH 3/4] Moved datatime compatibility macros with others --- psycopg/adapter_datetime.c | 6 ------ psycopg/python.h | 5 +++++ 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/psycopg/adapter_datetime.c b/psycopg/adapter_datetime.c index b5135efb..a78311ee 100644 --- a/psycopg/adapter_datetime.c +++ b/psycopg/adapter_datetime.c @@ -93,12 +93,6 @@ error: return rv; } -#ifndef PyDateTime_DELTA_GET_DAYS -#define PyDateTime_DELTA_GET_DAYS(o) (o->days) -#define PyDateTime_DELTA_GET_SECONDS(o) (o->seconds) -#define PyDateTime_DELTA_GET_MICROSECONDS(o) (o->microseconds) -#endif - static PyObject * _pydatetime_string_delta(pydatetimeObject *self) { diff --git a/psycopg/python.h b/psycopg/python.h index fc8c2fed..fa894bf3 100644 --- a/psycopg/python.h +++ b/psycopg/python.h @@ -87,6 +87,7 @@ typedef unsigned long Py_uhash_t; #ifndef PyNumber_Int #define PyNumber_Int PyNumber_Long #endif + #endif /* PY_MAJOR_VERSION > 2 */ #if PY_MAJOR_VERSION < 3 @@ -104,6 +105,10 @@ typedef unsigned long Py_uhash_t; #define Bytes_ConcatAndDel PyString_ConcatAndDel #define _Bytes_Resize _PyString_Resize +#define PyDateTime_DELTA_GET_DAYS(o) (((PyDateTime_Delta*)o)->days) +#define PyDateTime_DELTA_GET_SECONDS(o) (((PyDateTime_Delta*)o)->seconds) +#define PyDateTime_DELTA_GET_MICROSECONDS(o) (((PyDateTime_Delta*)o)->microseconds) + #else #define Bytes_Type PyBytes_Type From b3a70e09e960fd8d66e0f6a43962f7bf5cab2ba0 Mon Sep 17 00:00:00 2001 From: Daniele Varrazzo Date: Wed, 10 Jan 2018 22:44:37 +0000 Subject: [PATCH 4/4] pypi3 fix noted in the news file --- NEWS | 1 + 1 file changed, 1 insertion(+) diff --git a/NEWS b/NEWS index a1085252..1f1d7c85 100644 --- a/NEWS +++ b/NEWS @@ -24,6 +24,7 @@ What's new in psycopg 2.7.4 (:ticket:`632`). - Fixed `~cursor.rowcount` after `~cursor.executemany()` with :sql:`RETURNING` statements (:ticket:`633`). +- Fixed compatibility problem with pypy3 (:ticket:`#649`). - Wheel packages compiled against PostgreSQL 10.1 libpq and OpenSSL 1.0.2m.