Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
nexedi
cython
Commits
d10c07a6
Commit
d10c07a6
authored
Feb 09, 2019
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch '0.29.x'
parents
d98e7a96
31ee9cab
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
67 additions
and
9 deletions
+67
-9
Cython/Compiler/Nodes.py
Cython/Compiler/Nodes.py
+3
-3
Cython/Utility/ObjectHandling.c
Cython/Utility/ObjectHandling.c
+9
-5
tests/run/cpdef_method_override.pyx
tests/run/cpdef_method_override.pyx
+55
-1
No files found.
Cython/Compiler/Nodes.py
View file @
d10c07a6
...
@@ -4377,7 +4377,7 @@ class OverrideCheckNode(StatNode):
...
@@ -4377,7 +4377,7 @@ class OverrideCheckNode(StatNode):
" || (Py_TYPE(%s)->tp_flags & (Py_TPFLAGS_IS_ABSTRACT | Py_TPFLAGS_HEAPTYPE)))) {"
%
(
" || (Py_TYPE(%s)->tp_flags & (Py_TPFLAGS_IS_ABSTRACT | Py_TPFLAGS_HEAPTYPE)))) {"
%
(
self_arg
,
self_arg
))
self_arg
,
self_arg
))
code
.
putln
(
"#if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_PYTYPE_LOOKUP"
)
code
.
putln
(
"#if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_PYTYPE_LOOKUP
&& CYTHON_USE_TYPE_SLOTS
"
)
code
.
globalstate
.
use_utility_code
(
code
.
globalstate
.
use_utility_code
(
UtilityCode
.
load_cached
(
"PyDictVersioning"
,
"ObjectHandling.c"
))
UtilityCode
.
load_cached
(
"PyDictVersioning"
,
"ObjectHandling.c"
))
# TODO: remove the object dict version check by 'inlining' the getattr implementation for methods.
# TODO: remove the object dict version check by 'inlining' the getattr implementation for methods.
...
@@ -4412,7 +4412,7 @@ class OverrideCheckNode(StatNode):
...
@@ -4412,7 +4412,7 @@ class OverrideCheckNode(StatNode):
# NOTE: it's not 100% sure that we catch the exact versions here that were used for the lookup,
# NOTE: it's not 100% sure that we catch the exact versions here that were used for the lookup,
# but it is very unlikely that the versions change during lookup, and the type dict safe guard
# but it is very unlikely that the versions change during lookup, and the type dict safe guard
# should increase the chance of detecting such a case.
# should increase the chance of detecting such a case.
code
.
putln
(
"#if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_PYTYPE_LOOKUP"
)
code
.
putln
(
"#if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_PYTYPE_LOOKUP
&& CYTHON_USE_TYPE_SLOTS
"
)
code
.
putln
(
"%s = __Pyx_get_tp_dict_version(%s);"
%
(
code
.
putln
(
"%s = __Pyx_get_tp_dict_version(%s);"
%
(
Naming
.
tp_dict_version_temp
,
self_arg
))
Naming
.
tp_dict_version_temp
,
self_arg
))
code
.
putln
(
"%s = __Pyx_get_object_dict_version(%s);"
%
(
code
.
putln
(
"%s = __Pyx_get_object_dict_version(%s);"
%
(
...
@@ -4432,7 +4432,7 @@ class OverrideCheckNode(StatNode):
...
@@ -4432,7 +4432,7 @@ class OverrideCheckNode(StatNode):
code
.
put_decref_clear
(
func_node_temp
,
PyrexTypes
.
py_object_type
)
code
.
put_decref_clear
(
func_node_temp
,
PyrexTypes
.
py_object_type
)
code
.
funcstate
.
release_temp
(
func_node_temp
)
code
.
funcstate
.
release_temp
(
func_node_temp
)
code
.
putln
(
"#if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_PYTYPE_LOOKUP"
)
code
.
putln
(
"#if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_PYTYPE_LOOKUP
&& CYTHON_USE_TYPE_SLOTS
"
)
code
.
putln
(
"}"
)
code
.
putln
(
"}"
)
code
.
putln
(
"#endif"
)
code
.
putln
(
"#endif"
)
...
...
Cython/Utility/ObjectHandling.c
View file @
d10c07a6
...
@@ -2444,7 +2444,7 @@ static PyObject* __Pyx_PyNumber_InPlaceMatrixMultiply(PyObject* x, PyObject* y)
...
@@ -2444,7 +2444,7 @@ static PyObject* __Pyx_PyNumber_InPlaceMatrixMultiply(PyObject* x, PyObject* y)
/////////////// PyDictVersioning.proto ///////////////
/////////////// PyDictVersioning.proto ///////////////
#if CYTHON_USE_DICT_VERSIONS
#if CYTHON_USE_DICT_VERSIONS
&& CYTHON_USE_TYPE_SLOTS
#define __PYX_DICT_VERSION_INIT ((PY_UINT64_T) -1)
#define __PYX_DICT_VERSION_INIT ((PY_UINT64_T) -1)
#define __PYX_GET_DICT_VERSION(dict) (((PyDictObject*)(dict))->ma_version_tag)
#define __PYX_GET_DICT_VERSION(dict) (((PyDictObject*)(dict))->ma_version_tag)
#define __PYX_UPDATE_DICT_CACHE(dict, value, cache_var, version_var) \
#define __PYX_UPDATE_DICT_CACHE(dict, value, cache_var, version_var) \
...
@@ -2474,24 +2474,28 @@ static CYTHON_INLINE int __Pyx_object_dict_version_matches(PyObject* obj, PY_UIN
...
@@ -2474,24 +2474,28 @@ static CYTHON_INLINE int __Pyx_object_dict_version_matches(PyObject* obj, PY_UIN
/////////////// PyDictVersioning ///////////////
/////////////// PyDictVersioning ///////////////
#if CYTHON_USE_DICT_VERSIONS
#if CYTHON_USE_DICT_VERSIONS
&& CYTHON_USE_TYPE_SLOTS
static
CYTHON_INLINE
PY_UINT64_T
__Pyx_get_tp_dict_version
(
PyObject
*
obj
)
{
static
CYTHON_INLINE
PY_UINT64_T
__Pyx_get_tp_dict_version
(
PyObject
*
obj
)
{
PyObject
*
dict
=
Py_TYPE
(
obj
)
->
tp_dict
;
PyObject
*
dict
=
Py_TYPE
(
obj
)
->
tp_dict
;
return
dict
?
__PYX_GET_DICT_VERSION
(
dict
)
:
0
;
return
likely
(
dict
)
?
__PYX_GET_DICT_VERSION
(
dict
)
:
0
;
}
}
static
CYTHON_INLINE
PY_UINT64_T
__Pyx_get_object_dict_version
(
PyObject
*
obj
)
{
static
CYTHON_INLINE
PY_UINT64_T
__Pyx_get_object_dict_version
(
PyObject
*
obj
)
{
PyObject
**
dictptr
=
NULL
;
PyObject
**
dictptr
=
NULL
;
Py_ssize_t
offset
=
Py_TYPE
(
obj
)
->
tp_dictoffset
;
Py_ssize_t
offset
=
Py_TYPE
(
obj
)
->
tp_dictoffset
;
if
(
offset
)
{
if
(
offset
)
{
dictptr
=
(
offset
>
0
)
?
(
PyObject
**
)
((
char
*
)
obj
+
offset
)
:
_PyObject_GetDictPtr
(
obj
);
#if CYTHON_COMPILING_IN_CPYTHON
dictptr
=
(
likely
(
offset
>
0
))
?
(
PyObject
**
)
((
char
*
)
obj
+
offset
)
:
_PyObject_GetDictPtr
(
obj
);
#else
dictptr
=
_PyObject_GetDictPtr
(
obj
);
#endif
}
}
return
(
dictptr
&&
*
dictptr
)
?
__PYX_GET_DICT_VERSION
(
*
dictptr
)
:
0
;
return
(
dictptr
&&
*
dictptr
)
?
__PYX_GET_DICT_VERSION
(
*
dictptr
)
:
0
;
}
}
static
CYTHON_INLINE
int
__Pyx_object_dict_version_matches
(
PyObject
*
obj
,
PY_UINT64_T
tp_dict_version
,
PY_UINT64_T
obj_dict_version
)
{
static
CYTHON_INLINE
int
__Pyx_object_dict_version_matches
(
PyObject
*
obj
,
PY_UINT64_T
tp_dict_version
,
PY_UINT64_T
obj_dict_version
)
{
PyObject
*
dict
=
Py_TYPE
(
obj
)
->
tp_dict
;
PyObject
*
dict
=
Py_TYPE
(
obj
)
->
tp_dict
;
if
(
!
dict
||
tp_dict_version
!=
__PYX_GET_DICT_VERSION
(
dict
))
if
(
unlikely
(
!
dict
)
||
unlikely
(
tp_dict_version
!=
__PYX_GET_DICT_VERSION
(
dict
)
))
return
0
;
return
0
;
return
obj_dict_version
==
__Pyx_get_object_dict_version
(
obj
);
return
obj_dict_version
==
__Pyx_get_object_dict_version
(
obj
);
}
}
...
...
tests/run/cpdef_method_override.pyx
View file @
d10c07a6
...
@@ -31,12 +31,35 @@ cdef class BaseType:
...
@@ -31,12 +31,35 @@ cdef class BaseType:
BaseType.meth
BaseType.meth
BaseType.meth
BaseType.meth
"""
"""
def
callmeth
(
self
):
cpdef
callmeth
(
self
):
return
self
.
callmeth2
()
cpdef
callmeth2
(
self
):
# not overridden by subclasses
return
self
.
meth
()
return
self
.
meth
()
cpdef
meth
(
self
):
cpdef
meth
(
self
):
# overridden by subclasses
print
(
"BaseType.meth"
)
print
(
"BaseType.meth"
)
class
NonOverride
(
BaseType
):
"""
>>> NonOverride().callmeth()
BaseType.meth
>>> obj = NonOverride()
>>> obj.callmeth()
BaseType.meth
>>> obj.callmeth()
BaseType.meth
>>> _call_method(NonOverride)
BaseType.meth
BaseType.meth
BaseType.meth
BaseType.meth
BaseType.meth
BaseType.meth
"""
class
PyClass
(
BaseType
):
class
PyClass
(
BaseType
):
"""
"""
>>> PyClass().callmeth()
>>> PyClass().callmeth()
...
@@ -83,3 +106,34 @@ class PySlotsClass(BaseType):
...
@@ -83,3 +106,34 @@ class PySlotsClass(BaseType):
def
meth
(
self
):
def
meth
(
self
):
print
(
"PySlotsClass.meth"
)
print
(
"PySlotsClass.meth"
)
class
DynamicOverride
(
BaseType
):
"""
>>> DynamicOverride().callmeth()
meth1
>>> obj = DynamicOverride()
>>> obj.callmeth()
meth1
>>> obj.callmeth()
meth2
>>> obj.callmeth()
BaseType.meth
>>> obj.callmeth()
BaseType.meth
>>> _call_method(DynamicOverride)
meth1
meth1
meth2
meth1
meth2
BaseType.meth
"""
def
__init__
(
self
):
self
.
meth
=
self
.
meth1
def
meth1
(
self
):
self
.
meth
=
self
.
meth2
print
(
"meth1"
)
def
meth2
(
self
):
del
self
.
meth
print
(
"meth2"
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment