[pypy-svn] r73943 - in pypy/branch/cpython-extension/pypy/module/cpyext: . test
afa at codespeak.net
afa at codespeak.net
Wed Apr 21 16:51:05 CEST 2010
Author: afa
Date: Wed Apr 21 16:51:03 2010
New Revision: 73943
Modified:
pypy/branch/cpython-extension/pypy/module/cpyext/object.py
pypy/branch/cpython-extension/pypy/module/cpyext/stubs.py
pypy/branch/cpython-extension/pypy/module/cpyext/test/test_object.py
Log:
PyObject_HasAttrString
Modified: pypy/branch/cpython-extension/pypy/module/cpyext/object.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/module/cpyext/object.py (original)
+++ pypy/branch/cpython-extension/pypy/module/cpyext/object.py Wed Apr 21 16:51:03 2010
@@ -81,8 +81,20 @@
@cpython_api([PyObject, PyObject], rffi.INT_real, error=CANNOT_FAIL)
def PyObject_HasAttr(space, w_obj, w_name):
- w_res = operation.hasattr(space, w_obj, w_name)
- return space.is_true(w_res)
+ try:
+ w_res = operation.hasattr(space, w_obj, w_name)
+ return space.is_true(w_res)
+ except OperationError:
+ return 0
+
+ at cpython_api([PyObject, CONST_STRING], rffi.INT_real, error=CANNOT_FAIL)
+def PyObject_HasAttrString(space, w_obj, name_ptr):
+ try:
+ name = rffi.charp2str(name_ptr)
+ w_res = operation.hasattr(space, w_obj, space.wrap(name))
+ return space.is_true(w_res)
+ except OperationError:
+ return 0
@cpython_api([PyObject, PyObject, PyObject], rffi.INT_real, error=-1)
def PyObject_SetAttr(space, w_obj, w_name, w_value):
Modified: pypy/branch/cpython-extension/pypy/module/cpyext/stubs.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/module/cpyext/stubs.py (original)
+++ pypy/branch/cpython-extension/pypy/module/cpyext/stubs.py Wed Apr 21 16:51:03 2010
@@ -4257,13 +4257,6 @@
instead of the repr()."""
raise NotImplementedError
- at cpython_api([PyObject, rffi.CCHARP], rffi.INT_real)
-def PyObject_HasAttrString(space, o, attr_name):
- """Returns 1 if o has the attribute attr_name, and 0 otherwise. This
- is equivalent to the Python expression hasattr(o, attr_name). This function
- always succeeds."""
- raise NotImplementedError
-
@cpython_api([PyObject, PyObject], PyObject)
def PyObject_GetAttr(space, o, attr_name):
"""Retrieve an attribute named attr_name from object o. Returns the attribute
Modified: pypy/branch/cpython-extension/pypy/module/cpyext/test/test_object.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/module/cpyext/test/test_object.py (original)
+++ pypy/branch/cpython-extension/pypy/module/cpyext/test/test_object.py Wed Apr 21 16:51:03 2010
@@ -33,6 +33,11 @@
assert hasattr_(space.w_int, '__eq__')
assert not hasattr_(space.w_int, 'nonexistingattr')
+ buf = rffi.str2charp('__len__')
+ assert api.PyObject_HasAttrString(space.w_str, buf)
+ assert not api.PyObject_HasAttrString(space.w_int, buf)
+ rffi.free_charp(buf)
+
def test_SetAttr(self, space, api):
class X:
pass
More information about the Pypy-commit
mailing list