From ee65439e9a85884a5ff801dbd54559cbb550d99a Mon Sep 17 00:00:00 2001 From: Robert Bradshaw Date: Wed, 19 Sep 2007 15:35:13 -0700 Subject: [PATCH] Use PY_VERSION_HEX rather than sys.version_info for typeslot versioning. so the generated c files don't depend on the version of python used to run Cython --- Cython/Compiler/Naming.py | 4 ++++ Cython/Compiler/TypeSlots.py | 14 ++++++++------ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/Cython/Compiler/Naming.py b/Cython/Compiler/Naming.py index e110d633..6ea000f2 100644 --- a/Cython/Compiler/Naming.py +++ b/Cython/Compiler/Naming.py @@ -56,3 +56,7 @@ c_api_tab_cname = pyrex_prefix + "c_api_tab" gilstate_cname = pyrex_prefix + "state" extern_c_macro = pyrex_prefix.upper() + "EXTERN_C" + + +def py_version_hex(major, minor=0, micro=0, release_level=0, release_serial=0): + return (major << 24) | (minor << 16) | (micro << 8) | (release_level << 4) | (release_serial) diff --git a/Cython/Compiler/TypeSlots.py b/Cython/Compiler/TypeSlots.py index 31c1e34d..d0ac3ec1 100644 --- a/Cython/Compiler/TypeSlots.py +++ b/Cython/Compiler/TypeSlots.py @@ -105,20 +105,22 @@ class SlotDescriptor: # slot_name string Member name of the slot in the type object # is_initialised_dynamically Is initialised by code in the module init function - def __init__(self, slot_name, min_version=(2,2), dynamic = 0): + def __init__(self, slot_name, min_version=None, dynamic = 0): self.slot_name = slot_name self.is_initialised_dynamically = dynamic self.min_version = min_version def generate(self, scope, code): - if sys.version_info[0:2] < self.min_version: - return # not supported yet if self.is_initialised_dynamically: value = 0 else: value = self.slot_code(scope) + if self.min_version: + code.putln("#if PY_VERSION_HEX >= 0x%X" % Naming.py_version_hex(*self.min_version)) code.putln("%s, /*%s*/" % (value, self.slot_name)) - + if self.min_version: + code.putln("#endif") + # Some C implementations have trouble statically # initialising a global with a pointer to an extern # function, so we initialise some of the type slots @@ -161,7 +163,7 @@ class GCDependentSlot(SlotDescriptor): # the type participates in GC. def __init__(self, slot_name, no_gc_value, gc_value, dynamic = 0): - SlotDescriptor.__init__(self, slot_name, dynamic) + SlotDescriptor.__init__(self, slot_name, dynamic = dynamic) self.no_gc_value = no_gc_value self.gc_value = gc_value @@ -179,7 +181,7 @@ class MethodSlot(SlotDescriptor): # method_name string The __xxx__ name of the method # default string or None Default value of the slot - def __init__(self, signature, slot_name, method_name, min_version=(2,2), default = None): + def __init__(self, signature, slot_name, method_name, min_version=None, default = None): SlotDescriptor.__init__(self, slot_name, min_version) self.signature = signature self.slot_name = slot_name -- 2.26.2