提交 fbccc528 authored 作者: notoraptor's avatar notoraptor

Move compatibility code for PyInt_* functions

into a class attribute.
上级 62150d7c
...@@ -922,22 +922,20 @@ class EnumType(Type, dict): ...@@ -922,22 +922,20 @@ class EnumType(Type, dict):
def values_eq_approx(self, a, b): def values_eq_approx(self, a, b):
return float(a) == float(b) return float(a) == float(b)
@staticmethod pyint_compat_code = """
def c_support_macro_code(): #if PY_MAJOR_VERSION >= 3
return """ #ifndef PyInt_Check
#if PY_MAJOR_VERSION >= 3 #define PyInt_Check PyLong_Check
#ifndef PyInt_Check
#define PyInt_Check PyLong_Check
#endif
#ifndef PyInt_AsLong
#define PyInt_AsLong PyLong_AsLong
#endif
#endif #endif
""" #ifndef PyInt_AsLong
#define PyInt_AsLong PyLong_AsLong
#endif
#endif
"""
def c_support_code(self): def c_support_code(self):
return ( return (
self.c_support_macro_code() + self.pyint_compat_code +
''.join(""" ''.join("""
#define %s %s #define %s %s
""" % (k, str(self[k])) for k in sorted(self.keys())) """ % (k, str(self[k])) for k in sorted(self.keys()))
...@@ -1030,7 +1028,7 @@ class CEnumType(EnumList): ...@@ -1030,7 +1028,7 @@ class CEnumType(EnumList):
""" """
def c_support_code(self): def c_support_code(self):
return self.c_support_macro_code() return self.pyint_compat_code
def c_extract(self, name, sub, check_input=True): def c_extract(self, name, sub, check_input=True):
swapped_dict = dict((v, k) for (k, v) in self.items()) swapped_dict = dict((v, k) for (k, v) in self.items())
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论