Features added
--------------
+* The extension type flag ``Py_TPFLAGS_HAVE_VERSION_TAG`` is enabled by default
+ on extension types and can be disabled using the ``type_version_tag`` compiler
+ directive.
+
* EXPERIMENTAL support for simple Cython code level line tracing. Enabled by
the "linetrace" compiler directive.
'py2_import': False, # For backward compatibility of Cython's source code in Py3 source mode
'c_string_type': 'bytes',
'c_string_encoding': '',
+ 'type_version_tag': True, # enables Py_TPFLAGS_HAVE_VERSION_TAG on extension types
# set __file__ and/or __path__ to known source/target path at import time (instead of not having them available)
'set_initial_path' : None, # SOURCEFILE or "/full/path/to/module"
# Avoid scope-specific to/from_py_functions for c_string.
'c_string_type': ('module',),
'c_string_encoding': ('module',),
+ 'type_version_tag': ('module', 'cclass'),
}
def parse_directive_value(name, value, relaxed_bool=False):
# Descriptor for the type flags slot.
def slot_code(self, scope):
- value = "Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER"
+ value = "Py_TPFLAGS_DEFAULT"
+ if scope.directives['type_version_tag']:
+ # it's not in 'Py_TPFLAGS_DEFAULT' in Py2
+ 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 += "|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER"
if not scope.parent_type.is_final_type:
value += "|Py_TPFLAGS_BASETYPE"
if scope.needs_gc():
returns = lambda type_arg: _EmptyDecoratorAndManager()
-final = internal = _empty_decorator
+final = internal = type_version_tag = _empty_decorator
def inline(f, *args, **kwds):
if isinstance(f, basestring):
#define Py_TPFLAGS_HAVE_NEWBUFFER 0
#endif
+#if PY_VERSION_HEX < 0x02060000
+ #define Py_TPFLAGS_HAVE_VERSION_TAG 0
+#endif
+
/* new Py3.3 unicode type (PEP 393) */
#if PY_VERSION_HEX > 0x03030000 && defined(PyUnicode_KIND)
#define CYTHON_PEP393_ENABLED 1
when set to ``ascii`` or ``default``, the latter being utf-8 in Python 3 and
nearly-always ascii in Python 2.
+``type_version_tag`` (True / False)
+ Enables the attribute cache for extension types in CPython by setting the
+ type flag ``Py_TPFLAGS_HAVE_VERSION_TAG``. Default is True, meaning that
+ the cache is enabled for Cython implemented types. To disable it
+ explicitly in the rare cases where a type needs to juggle with its ``tp_dict``
+ internally without paying attention to cache consistency, this option can
+ be set to False.
+
+
How to set directives
---------------------
--- /dev/null
+# 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
+