[pypy-svn] r74450 - pypy/trunk/pypy/module/cpyext
afa at codespeak.net
afa at codespeak.net
Sun May 9 09:43:12 CEST 2010
Author: afa
Date: Sun May 9 09:43:10 2010
New Revision: 74450
Modified:
pypy/trunk/pypy/module/cpyext/typeobject.py
Log:
No need to check for the result of generic_cpy_call():
it conveniently raises exceptions.
More code simplification, and probably a fix in DecRef when tp_new returns an
object of a different type.
Modified: pypy/trunk/pypy/module/cpyext/typeobject.py
==============================================================================
--- pypy/trunk/pypy/module/cpyext/typeobject.py (original)
+++ pypy/trunk/pypy/module/cpyext/typeobject.py Sun May 9 09:43:10 2010
@@ -278,24 +278,27 @@
for key, w_obj in kw_w.items():
space.setitem(w_kw, space.wrap(key), w_obj)
w_obj = generic_cpy_call(space, tp_new, pto, w_args, w_kw)
- if w_obj:
- w_obj_type = space.type(w_obj)
- if not int(space.is_w(w_obj_type, w_type) or
- space.is_true(space.issubtype(w_obj_type, w_type))):
- return w_obj
- pyo = make_ref(space, w_type)
- pto = rffi.cast(PyTypeObjectPtr, pyo)
- try:
- if pto.c_tp_init:
- generic_cpy_call(space, pto.c_tp_init, w_obj, w_args, w_kw)
- else:
- w_descr = space.lookup(w_obj, '__init__')
- w_result = space.get_and_call_args(w_descr, w_obj, __args__)
- return w_obj
- finally:
- Py_DecRef(space, pyo)
finally:
Py_DecRef(space, pyo)
+
+ # call tp_init on the result
+ w_obj_type = space.type(w_obj)
+ if not int(space.is_w(w_obj_type, w_type) or
+ space.is_true(space.issubtype(w_obj_type, w_type))):
+ return w_obj
+
+ pyo = make_ref(space, w_type)
+ pto = rffi.cast(PyTypeObjectPtr, pyo)
+ try:
+ if pto.c_tp_init:
+ generic_cpy_call(space, pto.c_tp_init, w_obj, w_args, w_kw)
+ else:
+ w_descr = space.lookup(w_obj, '__init__')
+ space.get_and_call_args(w_descr, w_obj, __args__)
+ finally:
+ Py_DecRef(space, pyo)
+
+ return w_obj
else:
w_type = _precheck_for_new(space, w_type)
return call__Type(space, w_type, __args__)
More information about the Pypy-commit
mailing list