Commit 54bad41c authored by Stefan Behnel's avatar Stefan Behnel

Merge branch '0.29.x'

parents d720eb47 4ac64ddf
......@@ -454,6 +454,10 @@ Other changes
Bugs fixed
----------
* Now uses ``Py_SET_SIZE()`` and ``Py_SET_REFCNT()`` in Py3.9+ to avoid low-level
write access to these object fields.
Patch by Victor Stinner. (Github issue #3639)
* The built-in ``abs()`` function could lead to undefined behaviour when used on
the negative-most value of a signed C integer type.
Patch by Serge Guelton. (Github issue #1911)
......
......@@ -2040,6 +2040,10 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
if scope.directives['c_api_binop_methods']:
code.putln('#define %s %s' % (func_name, slot.left_slot.slot_code(scope)))
return
else:
error(self.pos,
"The 'c_api_binop_methods' directive is only supported for forward compatibility"
" and must be True.")
code.putln()
preprocessor_guard = slot.preprocessor_guard_code()
......
......@@ -830,6 +830,15 @@ static CYTHON_INLINE PyObject * __Pyx_PyDict_GetItemStrWithError(PyObject *dict,
#endif
#if PY_VERSION_HEX >= 0x030900A4
#define __Pyx_SET_REFCNT(obj, refcnt) Py_SET_REFCNT(obj, refcnt)
#define __Pyx_SET_SIZE(obj, size) Py_SET_SIZE(obj, size)
#else
#define __Pyx_SET_REFCNT(obj, refcnt) Py_REFCNT(obj) = (refcnt)
#define __Pyx_SET_SIZE(obj, size) Py_SIZE(obj) = (size)
#endif
#if PY_VERSION_HEX >= 0x030900A4
#define __Pyx_SET_REFCNT(obj, refcnt) Py_SET_REFCNT(obj, refcnt)
#define __Pyx_SET_SIZE(obj, size) Py_SET_SIZE(obj, size)
......
cimport cython
@cython.c_api_binop_methods(False)
@cython.cclass
class Base(object):
"""
>>> Base() + 2
'Base.__add__(Base(), 2)'
>>> 2 + Base()
'Base.__radd__(Base(), 2)'
>>> Base() ** 2
'Base.__pow__(Base(), 2, None)'
>>> 2 ** Base()
'Base.__rpow__(Base(), 2, None)'
>>> pow(Base(), 2, 100)
'Base.__pow__(Base(), 2, 100)'
"""
def __add__(self, other):
return "Base.__add__(%s, %s)" % (self, other)
def __radd__(self, other):
return "Base.__radd__(%s, %s)" % (self, other)
def __pow__(self, other, mod):
return "Base.__pow__(%s, %s, %s)" % (self, other, mod)
def __rpow__(self, other, mod):
return "Base.__rpow__(%s, %s, %s)" % (self, other, mod)
def __repr__(self):
return "%s()" % (self.__class__.__name__)
@cython.c_api_binop_methods(False)
@cython.cclass
class OverloadLeft(Base):
"""
>>> OverloadLeft() + 2
'OverloadLeft.__add__(OverloadLeft(), 2)'
>>> 2 + OverloadLeft()
'Base.__radd__(OverloadLeft(), 2)'
>>> OverloadLeft() + Base()
'OverloadLeft.__add__(OverloadLeft(), Base())'
>>> Base() + OverloadLeft()
'Base.__add__(Base(), OverloadLeft())'
"""
def __add__(self, other):
return "OverloadLeft.__add__(%s, %s)" % (self, other)
@cython.c_api_binop_methods(False)
@cython.cclass
class OverloadRight(Base):
"""
>>> OverloadRight() + 2
'Base.__add__(OverloadRight(), 2)'
>>> 2 + OverloadRight()
'OverloadRight.__radd__(OverloadRight(), 2)'
>>> OverloadRight() + Base()
'Base.__add__(OverloadRight(), Base())'
>>> Base() + OverloadRight()
'OverloadRight.__radd__(OverloadRight(), Base())'
"""
def __radd__(self, other):
return "OverloadRight.__radd__(%s, %s)" % (self, other)
@cython.c_api_binop_methods(True)
@cython.cclass
class OverloadCApi(Base):
"""
>>> OverloadCApi() + 2
'OverloadCApi.__add__(OverloadCApi(), 2)'
>>> 2 + OverloadCApi()
'OverloadCApi.__add__(2, OverloadCApi())'
>>> OverloadCApi() + Base()
'OverloadCApi.__add__(OverloadCApi(), Base())'
>>> Base() + OverloadCApi()
'OverloadCApi.__add__(Base(), OverloadCApi())'
"""
def __add__(self, other):
return "OverloadCApi.__add__(%s, %s)" % (self, other)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment