[pypy-svn] r72971 - in pypy/branch/cpython-extension/pypy/module/cpyext: . include test test/zfec
fijal at codespeak.net
fijal at codespeak.net
Sat Mar 27 20:33:39 CET 2010
Author: fijal
Date: Sat Mar 27 20:33:37 2010
New Revision: 72971
Added:
pypy/branch/cpython-extension/pypy/module/cpyext/include/intobject.h
pypy/branch/cpython-extension/pypy/module/cpyext/intobject.py (contents, props changed)
pypy/branch/cpython-extension/pypy/module/cpyext/test/test_intobject.py (contents, props changed)
pypy/branch/cpython-extension/pypy/module/cpyext/test/zfec/
Modified:
pypy/branch/cpython-extension/pypy/module/cpyext/__init__.py
pypy/branch/cpython-extension/pypy/module/cpyext/include/Python.h
pypy/branch/cpython-extension/pypy/module/cpyext/stubs.py
Log:
(zooko, fijal) Added PyInt_Check
Modified: pypy/branch/cpython-extension/pypy/module/cpyext/__init__.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/module/cpyext/__init__.py (original)
+++ pypy/branch/cpython-extension/pypy/module/cpyext/__init__.py Sat Mar 27 20:33:37 2010
@@ -40,5 +40,6 @@
import pypy.module.cpyext.stringobject
import pypy.module.cpyext.tupleobject
import pypy.module.cpyext.dictobject
+import pypy.module.cpyext.intobject
# now that all rffi_platform.Struct types are registered, configure them
api.configure_types()
Modified: pypy/branch/cpython-extension/pypy/module/cpyext/include/Python.h
==============================================================================
--- pypy/branch/cpython-extension/pypy/module/cpyext/include/Python.h (original)
+++ pypy/branch/cpython-extension/pypy/module/cpyext/include/Python.h Sat Mar 27 20:33:37 2010
@@ -37,6 +37,7 @@
#include "descrobject.h"
#include "tupleobject.h"
#include "dictobject.h"
+#include "intobject.h"
#include <pypy_decl.h>
Added: pypy/branch/cpython-extension/pypy/module/cpyext/include/intobject.h
==============================================================================
--- (empty file)
+++ pypy/branch/cpython-extension/pypy/module/cpyext/include/intobject.h Sat Mar 27 20:33:37 2010
@@ -0,0 +1,13 @@
+
+/* Int object interface */
+
+#ifndef Py_INTOBJECT_H
+#define Py_INTOBJECT_H
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+#endif /* !Py_BOOLOBJECT_H */
Added: pypy/branch/cpython-extension/pypy/module/cpyext/intobject.py
==============================================================================
--- (empty file)
+++ pypy/branch/cpython-extension/pypy/module/cpyext/intobject.py Sat Mar 27 20:33:37 2010
@@ -0,0 +1,12 @@
+
+from pypy.rpython.lltypesystem import rffi, lltype
+from pypy.module.cpyext.api import cpython_api, PyObject, CANNOT_FAIL
+from pypy.module.cpyext.api import general_check
+
+ at cpython_api([PyObject], rffi.INT_real, error=CANNOT_FAIL)
+def PyInt_Check(space, w_obj):
+ """Return true if o is of type PyInt_Type or a subtype of
+ PyInt_Type.
+
+ Allowed subtypes to be accepted."""
+ return general_check(space, w_obj, space.w_int)
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 Sat Mar 27 20:33:37 2010
@@ -3291,14 +3291,6 @@
raise NotImplementedError
@cpython_api([PyObject], rffi.INT_real)
-def PyInt_Check(space, o):
- """Return true if o is of type PyInt_Type or a subtype of
- PyInt_Type.
-
- Allowed subtypes to be accepted."""
- raise NotImplementedError
-
- at cpython_api([PyObject], rffi.INT_real)
def PyInt_CheckExact(space, o):
"""Return true if o is of type PyInt_Type, but not a subtype of
PyInt_Type.
Added: pypy/branch/cpython-extension/pypy/module/cpyext/test/test_intobject.py
==============================================================================
--- (empty file)
+++ pypy/branch/cpython-extension/pypy/module/cpyext/test/test_intobject.py Sat Mar 27 20:33:37 2010
@@ -0,0 +1,17 @@
+
+from pypy.module.cpyext.test.test_cpyext import AppTestCpythonExtensionBase
+
+class AppTestIntObject(AppTestCpythonExtensionBase):
+ def test_intobject(self):
+ module = self.import_extension('foo', [
+ ("check_int", "METH_VARARGS",
+ """
+ PyObject* a = PyTuple_GetItem(args, 0);
+ if (PyInt_Check(a)) {
+ Py_RETURN_TRUE;
+ }
+ Py_RETURN_FALSE;
+ """)])
+ assert module.check_int(3)
+ assert module.check_int(True)
+ assert not module.check_int((1, 2, 3))
More information about the Pypy-commit
mailing list