[pypy-dev] PyPy's PyDateTime_Delta definition

Skip Montanaro skip at pobox.com
Sat Sep 7 13:38:43 CEST 2013


Not a big deal.  I did it this way:

// PyPy introduced the PyDateTime_DELTA_* API as functions even though
// they aren't available in CPython until v3.x.  To make matters
// slightly worse, in CPython 3.x they are defined as macros.
#if !defined(PYPY_VERSION) && PY_MAJOR_VERSION < 3
#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)
#endif

(Apologies for the bad line wrappage. I am beginning to rue the day I
moved to Gmail for all my mail...)

Skip


On Sat, Sep 7, 2013 at 5:19 AM, Amaury Forgeot d'Arc <amauryfa at gmail.com> wrote:
>
> 2013/9/7 Skip Montanaro <skip at pobox.com>
>>
>> On Fri, Sep 6, 2013 at 6:13 PM, Skip Montanaro <skip at pobox.com> wrote:
>> >> Not sure I understand. Or did you mean "why are those declarations not
>> >> in
>> >> datetime.h"?
>> >
>> > Yes, sorry about the typo.
>>
>> Alas, I am still confused. The PyDateTime_DELTA_GET_* macros aren't
>> defined for CPython until the 3.x series. (There are macros in 2.7,
>> but they are defined in datetimemodule.c, not in a public header file.
>> PyPy declares them as functions.
>>
>> Is there some predefined "This is PyPy" macro I can check?
>
>
> Now I feel embarrassed.
> I was the one who added these macros to CPython 3.3, exactly for this
> reason.
> see the patch we propose for cx_Oracle:
> https://bitbucket.org/pypy/pypy/src/tip/pypy/module/cpyext/patches/cx_Oracle.patch
> "#ifdef PyDateTime_DELTA_GET_DAYS" should do the trick for any version.
>
>
> --
> Amaury Forgeot d'Arc


More information about the pypy-dev mailing list