diff options
author | Stefan Behnel <stefan_ml@behnel.de> | 2013-04-07 07:38:45 +0200 |
---|---|---|
committer | Stefan Behnel <stefan_ml@behnel.de> | 2013-04-07 07:38:45 +0200 |
commit | 940f939169cd3d7dcdd14ded4820a8a4e5ef7da5 (patch) | |
tree | 93f0cc27be0816c734efa74b6108d9af7e1ff754 | |
parent | b1f10fa2c1bbb0a076807a9f391204c6a997ba9a (diff) | |
download | cython-940f939169cd3d7dcdd14ded4820a8a4e5ef7da5.tar.gz |
test 'type_version_tag' directive and fix it in Py20.19b1
--HG--
rename : tests/compile/ext_attribute_cache.pyx => tests/run/ext_attribute_cache.pyx
-rw-r--r-- | Cython/Compiler/TypeSlots.py | 2 | ||||
-rw-r--r-- | tests/compile/ext_attribute_cache.pyx | 13 | ||||
-rw-r--r-- | tests/run/ext_attribute_cache.pyx | 52 |
3 files changed, 53 insertions, 14 deletions
diff --git a/Cython/Compiler/TypeSlots.py b/Cython/Compiler/TypeSlots.py index 3a3fc9c6a..b8d66229d 100644 --- a/Cython/Compiler/TypeSlots.py +++ b/Cython/Compiler/TypeSlots.py @@ -383,7 +383,7 @@ class TypeFlagsSlot(SlotDescriptor): value += "|Py_TPFLAGS_HAVE_VERSION_TAG" else: # it's enabled in 'Py_TPFLAGS_DEFAULT' in Py3 - value = "(%s^Py_TPFLAGS_HAVE_VERSION_TAG)" % value + value = "(%s&~Py_TPFLAGS_HAVE_VERSION_TAG)" % value value += "|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER" if not scope.parent_type.is_final_type: value += "|Py_TPFLAGS_BASETYPE" diff --git a/tests/compile/ext_attribute_cache.pyx b/tests/compile/ext_attribute_cache.pyx deleted file mode 100644 index bcc43f559..000000000 --- a/tests/compile/ext_attribute_cache.pyx +++ /dev/null @@ -1,13 +0,0 @@ -# mode: compile - -cimport cython - -cdef class AttrCache(object): - cdef public int x - cdef object y - -@cython.type_version_tag(False) -cdef class NoAttrCache(object): - cdef public int x - cdef object y - diff --git a/tests/run/ext_attribute_cache.pyx b/tests/run/ext_attribute_cache.pyx new file mode 100644 index 000000000..7901bfae9 --- /dev/null +++ b/tests/run/ext_attribute_cache.pyx @@ -0,0 +1,52 @@ +# mode: run +# tag: tpflags, type_version_tag + +cimport cython + + +cdef extern from *: + unsigned long PY_VERSION_HEX + unsigned long Py_TPFLAGS_HAVE_VERSION_TAG + ctypedef struct PyTypeObject: + unsigned long tp_flags + + +SHOULD_HAVE_FLAG = PY_VERSION_HEX >= 0x02060000 + + +def test_flag(t): + return ((<PyTypeObject*>t).tp_flags & Py_TPFLAGS_HAVE_VERSION_TAG) != 0 + + +cdef class ImplicitAttrCache(object): + """ + >>> flag = test_flag(ImplicitAttrCache) + >>> if SHOULD_HAVE_FLAG: print(flag) + ... else: print(True) + True + """ + cdef public int x + cdef object y + + +@cython.type_version_tag(True) +cdef class ExplicitAttrCache(object): + """ + >>> flag = test_flag(ImplicitAttrCache) + >>> if SHOULD_HAVE_FLAG: print(flag) + ... else: print(True) + True + """ + cdef public int x + cdef object y + + +@cython.type_version_tag(False) +cdef class NoAttrCache(object): + """ + >>> test_flag(NoAttrCache) + False + """ + cdef public int x + cdef object y + |