Commit dd0c2f1a authored by Boxiang Sun's avatar Boxiang Sun

Add PyMethod_SetSelf to let extensions can set the im_self field in PyMethodObject

parent baffffe3
..FF..................................E.F.F...
======================================================================
ERROR: test_w_unicode_attr_name (__main__.TestAcquire)
----------------------------------------------------------------------
Traceback (most recent call last):
File "./lib/python2.7/site-packages/Acquisition-2.13.9-py2.7-linux-x86_64.egg/Acquisition/tests.py", line 2533, in test_w_unicode_attr_name
found = self.acquire(self.a.b.c, u'aq_parent')
AttributeError: aq_parent
======================================================================
FAIL: test_Basic_gc (__main__)
Doctest: __main__.test_Basic_gc
----------------------------------------------------------------------
Traceback (most recent call last):
File "/srv/slapgrid/slappart13/pyston/build/Debug-gcc/lib/python2.7/doctest.py", line 2226, in runTest
raise self.failureException(self.format_failure(new.getvalue()))
AssertionError: Failed doctest test for __main__.test_Basic_gc
File "./lib/python2.7/site-packages/Acquisition-2.13.9-py2.7-linux-x86_64.egg/Acquisition/tests.py", line 1738, in test_Basic_gc
----------------------------------------------------------------------
File "./lib/python2.7/site-packages/Acquisition-2.13.9-py2.7-linux-x86_64.egg/Acquisition/tests.py", line 1746, in __main__.test_Basic_gc
Failed example:
for B in I, E:
class C1(B):
pass
class C2(Base):
def __del__(self):
print 'removed'
a=C1('a')
a.b = C1('a.b')
a.b.a = a
a.b.c = C2()
ignore = gc.collect()
del a
removed = gc.collect()
print removed > 0
Expected:
removed
True
removed
True
Got:
False
False
======================================================================
FAIL: test_Wrapper_gc (__main__)
Doctest: __main__.test_Wrapper_gc
----------------------------------------------------------------------
Traceback (most recent call last):
File "/srv/slapgrid/slappart13/pyston/build/Debug-gcc/lib/python2.7/doctest.py", line 2226, in runTest
raise self.failureException(self.format_failure(new.getvalue()))
AssertionError: Failed doctest test for __main__.test_Wrapper_gc
File "./lib/python2.7/site-packages/Acquisition-2.13.9-py2.7-linux-x86_64.egg/Acquisition/tests.py", line 1771, in test_Wrapper_gc
----------------------------------------------------------------------
File "./lib/python2.7/site-packages/Acquisition-2.13.9-py2.7-linux-x86_64.egg/Acquisition/tests.py", line 1778, in __main__.test_Wrapper_gc
Failed example:
for B in I, E:
class C:
def __del__(self):
print 'removed'
a=B('a')
a.b = B('b')
a.a_b = a.b # circ ref through wrapper
a.b.c = C()
ignored = gc.collect()
del a
removed = gc.collect()
removed > 0
Expected:
removed
True
removed
True
Got:
False
False
======================================================================
FAIL: test_explicit_aq_unicode_should_be_called (__main__.TestUnicode)
----------------------------------------------------------------------
Traceback (most recent call last):
File "./lib/python2.7/site-packages/Acquisition-2.13.9-py2.7-linux-x86_64.egg/Acquisition/tests.py", line 2553, in test_explicit_aq_unicode_should_be_called
self.assertEqual(str(wrapped), repr(wrapped))
AssertionError: '<__main__.A object at 0x7f50d5dd4d80>' != '<Acquisition.ExplicitAcquisitionWrapper object at 0x7f50d68c4ba0>'
======================================================================
FAIL: test_implicit_aq_unicode_should_be_called (__main__.TestUnicode)
----------------------------------------------------------------------
Traceback (most recent call last):
File "./lib/python2.7/site-packages/Acquisition-2.13.9-py2.7-linux-x86_64.egg/Acquisition/tests.py", line 2545, in test_implicit_aq_unicode_should_be_called
self.assertEqual(str(wrapped), repr(wrapped))
AssertionError: '<__main__.A object at 0x7f50d5dd4330>' != '<Acquisition.ImplicitAcquisitionWrapper object at 0x7f50d68c4d50>'
----------------------------------------------------------------------
Ran 46 tests in 0.670s
FAILED (failures=4, errors=1)
......@@ -75,6 +75,9 @@ PyAPI_FUNC(PyObject *) PyMethod_Function(PyObject *) PYSTON_NOEXCEPT;
PyAPI_FUNC(PyObject *) PyMethod_Self(PyObject *) PYSTON_NOEXCEPT;
PyAPI_FUNC(PyObject *) PyMethod_Class(PyObject *) PYSTON_NOEXCEPT;
// Pyston change: add help API to allow extensions to set the fields of PyMethodObject
PyAPI_FUNC(void) PyMethod_SetSelf(PyObject *, PyObject*) PYSTON_NOEXCEPT;
/* Look up attribute with name (a string) on instance object pinst, using
* only the instance and base class dicts. If a descriptor is found in
* a class dict, the descriptor is returned without calling it.
......
......@@ -1927,6 +1927,18 @@ extern "C" PyObject* PyMethod_Self(PyObject* im) noexcept {
return ((BoxedInstanceMethod*)im)->obj;
}
extern "C" void PyMethod_SetSelf(PyObject* im, PyObject* instance) noexcept {
if (!PyMethod_Check(im)) {
PyErr_BadInternalCall();
}
Box* self = ((BoxedInstanceMethod*)im)->obj;
Py_XDECREF(self);
Py_INCREF(instance);
((BoxedInstanceMethod*)im)->obj = instance;
Py_INCREF(im);
}
extern "C" PyObject* PyMethod_Class(PyObject* im) noexcept {
if (!PyMethod_Check(im)) {
PyErr_BadInternalCall();
......
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