[pypy-svn] commit/pypy: hakanardo: hg merge default
Bitbucket
commits-noreply at bitbucket.org
Sun Dec 19 21:53:45 CET 2010
1 new changeset in pypy:
http://bitbucket.org/pypy/pypy/changeset/2661bf51a77c/
changeset: r40135:2661bf51a77c
branch: jit-unroll-loops
user: hakanardo
date: 2010-12-19 13:11:22
summary: hg merge default
affected #: 15 files (14.2 KB)
--- a/lib_pypy/_ctypes/dll.py Sun Dec 19 11:54:23 2010 +0100
+++ b/lib_pypy/_ctypes/dll.py Sun Dec 19 13:11:22 2010 +0100
@@ -3,5 +3,6 @@
def dlopen(name, mode):
# XXX mode is ignored
if name is None:
- return None # XXX this should return *all* loaded libs, dlopen(NULL)
+ # XXX this should return *all* loaded libs, dlopen(NULL).
+ raise NotImplementedError("dlopen(None)")
return _rawffi.CDLL(name)
--- a/py/_path/local.py Sun Dec 19 11:54:23 2010 +0100
+++ b/py/_path/local.py Sun Dec 19 13:11:22 2010 +0100
@@ -589,7 +589,7 @@
else:
paths = [re.sub('%SystemRoot%', systemroot, path)
for path in paths]
- tryadd = '', '.exe', '.com', '.bat' # XXX add more?
+ tryadd = '', '.exe', '.com', '.bat', '.cmd' # XXX add more?
else:
paths = py.std.os.environ['PATH'].split(':')
tryadd = ('',)
--- a/pypy/config/pypyoption.py Sun Dec 19 11:54:23 2010 +0100
+++ b/pypy/config/pypyoption.py Sun Dec 19 13:11:22 2010 +0100
@@ -301,7 +301,7 @@
default=False),
BoolOption("newshortcut",
"cache and shortcut calling __new__ from builtin types",
- default=False),
+ default=False),
BoolOption("logspaceoptypes",
"a instrumentation option: before exit, print the types seen by "
@@ -310,8 +310,9 @@
ChoiceOption("multimethods", "the multimethod implementation to use",
["doubledispatch", "mrd"],
default="mrd"),
- BoolOption("immutable_builtintypes",
- "Forbid the changing of builtin types", default=True),
+ BoolOption("mutable_builtintypes",
+ "Allow the changing of builtin types", default=False,
+ requires=[("objspace.std.builtinshortcut", True)]),
]),
])
--- a/pypy/doc/config/objspace.std.immutable_builtintypes.txt Sun Dec 19 11:54:23 2010 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-Disallow modification of builtin types. Enabled by default.
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/pypy/doc/config/objspace.std.mutable_builtintypes.txt Sun Dec 19 13:11:22 2010 +0100
@@ -0,0 +1,1 @@
+Allow modification of builtin types. Disabled by default.
--- a/pypy/doc/cpython_differences.txt Sun Dec 19 11:54:23 2010 +0100
+++ b/pypy/doc/cpython_differences.txt Sun Dec 19 13:11:22 2010 +0100
@@ -204,4 +204,16 @@
lets the exception propagate instead.
+Miscellaneous
+-------------
+
+* ``sys.setrecursionlimit()`` is ignored (and not needed) on
+ PyPy. On CPython it would set the maximum number of nested
+ calls that can occur before a RuntimeError is raised; on PyPy
+ overflowing the stack also causes RuntimeErrors, but the limit
+ is checked at a lower level. (The limit is currenty hard-coded
+ at 768 KB, corresponding to roughly 1480 Python calls on
+ Linux.)
+
+
.. include:: _ref.txt
--- a/pypy/jit/backend/x86/test/test_ztranslation.py Sun Dec 19 11:54:23 2010 +0100
+++ b/pypy/jit/backend/x86/test/test_ztranslation.py Sun Dec 19 13:11:22 2010 +0100
@@ -189,14 +189,14 @@
@dont_look_inside
def f(x, total):
- if x <= 3:
+ if x <= 30:
raise ImDone(total * 10)
- if x > 20:
+ if x > 200:
return 2
raise ValueError
@dont_look_inside
def g(x):
- if x > 15:
+ if x > 150:
raise ValueError
return 2
class Base:
@@ -207,7 +207,7 @@
return 1
@dont_look_inside
def h(x):
- if x < 2000:
+ if x < 20000:
return Sub()
else:
return Base()
@@ -238,8 +238,8 @@
logfile = udir.join('test_ztranslation.log')
os.environ['PYPYLOG'] = 'jit-log-opt:%s' % (logfile,)
try:
- res = self.meta_interp(main, [40])
- assert res == main(40)
+ res = self.meta_interp(main, [400])
+ assert res == main(400)
finally:
del os.environ['PYPYLOG']
@@ -248,5 +248,7 @@
if 'guard_class' in line:
guard_class += 1
# if we get many more guard_classes, it means that we generate
- # guards that always fail
- assert 0 < guard_class <= 4
+ # guards that always fail (the following assert's original purpose
+ # is to catch the following case: each GUARD_CLASS is misgenerated
+ # and always fails with "gcremovetypeptr")
+ assert 0 < guard_class < 10
--- a/pypy/jit/metainterp/compile.py Sun Dec 19 11:54:23 2010 +0100
+++ b/pypy/jit/metainterp/compile.py Sun Dec 19 13:11:22 2010 +0100
@@ -190,6 +190,9 @@
if not we_are_translated():
metainterp_sd.stats.compiled()
metainterp_sd.log("compiled new bridge")
+ if metainterp_sd.warmrunnerdesc is not None: # for tests
+ metainterp_sd.warmrunnerdesc.memory_manager.keep_loop_alive(
+ original_loop_token)
# ____________________________________________________________
--- a/pypy/module/cpyext/TODO Sun Dec 19 11:54:23 2010 +0100
+++ b/pypy/module/cpyext/TODO Sun Dec 19 13:11:22 2010 +0100
@@ -24,6 +24,3 @@
- sort out pypy's buffer protocol. PyPy's buffer right now don't support
raw memory (except array which supports it in a hackish way), which
should be fixed in order to make it nicely work with cpyext.
-
- - Fix Makefile generation on Windows when --shared is used (mandatory when
- cpyext is used with -Ojit)
--- a/pypy/module/cpyext/__init__.py Sun Dec 19 11:54:23 2010 +0100
+++ b/pypy/module/cpyext/__init__.py Sun Dec 19 13:11:22 2010 +0100
@@ -70,6 +70,7 @@
import pypy.module.cpyext.funcobject
import pypy.module.cpyext.classobject
import pypy.module.cpyext.pypyintf
+import pypy.module.cpyext.codecs
# now that all rffi_platform.Struct types are registered, configure them
api.configure_types()
--- a/pypy/module/cpyext/api.py Sun Dec 19 11:54:23 2010 +0100
+++ b/pypy/module/cpyext/api.py Sun Dec 19 13:11:22 2010 +0100
@@ -193,7 +193,7 @@
the API headers.
"""
if error is _NOT_SPECIFIED:
- if restype is PyObject:
+ if isinstance(restype, lltype.Ptr):
error = lltype.nullptr(restype.TO)
elif restype is lltype.Void:
error = CANNOT_FAIL
@@ -308,7 +308,7 @@
'PyModule_AddObject', 'PyModule_AddIntConstant', 'PyModule_AddStringConstant',
'Py_BuildValue', 'Py_VaBuildValue', 'PyTuple_Pack',
- 'PyErr_Format', 'PyErr_NewException',
+ 'PyErr_Format', 'PyErr_NewException', 'PyErr_NewExceptionWithDoc',
'PyEval_CallFunction', 'PyEval_CallMethod', 'PyObject_CallFunction',
'PyObject_CallMethod', 'PyObject_CallFunctionObjArgs', 'PyObject_CallMethodObjArgs',
@@ -746,6 +746,7 @@
("SIZEOF_LONG_LONG", rffi.LONGLONG),
("SIZEOF_VOID_P", rffi.VOIDP),
("SIZEOF_SIZE_T", rffi.SIZE_T),
+ ("SIZEOF_TIME_T", rffi.TIME_T),
("SIZEOF_LONG", rffi.LONG),
("SIZEOF_SHORT", rffi.SHORT),
("SIZEOF_INT", rffi.INT)
--- a/pypy/module/cpyext/cdatetime.py Sun Dec 19 11:54:23 2010 +0100
+++ b/pypy/module/cpyext/cdatetime.py Sun Dec 19 13:11:22 2010 +0100
@@ -18,8 +18,7 @@
('DeltaType', PyTypeObjectPtr),
))
- at cpython_api([], lltype.Ptr(PyDateTime_CAPI),
- error=lltype.nullptr(PyDateTime_CAPI))
+ at cpython_api([], lltype.Ptr(PyDateTime_CAPI))
def _PyDateTime_Import(space):
datetimeAPI = lltype.malloc(PyDateTime_CAPI, flavor='raw',
track_allocation=False)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/pypy/module/cpyext/codecs.py Sun Dec 19 13:11:22 2010 +0100
@@ -0,0 +1,22 @@
+from pypy.rpython.lltypesystem import rffi
+from pypy.module.cpyext.api import cpython_api, PyObject, CONST_STRING
+from pypy.module._codecs import interp_codecs
+
+ at cpython_api([CONST_STRING, CONST_STRING], PyObject)
+def PyCodec_IncrementalEncoder(space, encoding, errors):
+ w_codec = interp_codecs.lookup_codec(space, rffi.charp2str(encoding))
+ if errors:
+ w_errors = space.wrap(rffi.charp2str(errors))
+ return space.call_method(w_codec, "incrementalencoder", w_errors)
+ else:
+ return space.call_method(w_codec, "incrementalencoder")
+
+ at cpython_api([CONST_STRING, CONST_STRING], PyObject)
+def PyCodec_IncrementalDecoder(space, encoding, errors):
+ w_codec = interp_codecs.lookup_codec(space, rffi.charp2str(encoding))
+ if errors:
+ w_errors = space.wrap(rffi.charp2str(errors))
+ return space.call_method(w_codec, "incrementaldecoder", w_errors)
+ else:
+ return space.call_method(w_codec, "incrementaldecoder")
+
--- a/pypy/module/cpyext/complexobject.py Sun Dec 19 11:54:23 2010 +0100
+++ b/pypy/module/cpyext/complexobject.py Sun Dec 19 13:11:22 2010 +0100
@@ -36,7 +36,7 @@
# lltype does not handle functions returning a structure. This implements a
# helper function, which takes as argument a reference to the return value.
- at cpython_api([PyObject, Py_complex_ptr], lltype.Void, error=None)
+ at cpython_api([PyObject, Py_complex_ptr], lltype.Void)
def _PyComplex_AsCComplex(space, w_obj, result):
"""Return the Py_complex value of the complex number op.
--- a/pypy/module/cpyext/conftest.py Sun Dec 19 11:54:23 2010 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,16 +0,0 @@
-import py
-from pypy.conftest import option, gettestobjspace
-
-def pytest_ignore_collect(path, config):
- if config.option.runappdirect:
- return True # "cannot be run by py.test -A"
- # ensure additional functions are registered
- import pypy.module.cpyext.test.test_cpyext
- return False
-
-def pytest_funcarg__space(request):
- return gettestobjspace(usemodules=['cpyext', 'thread'])
-
-def pytest_funcarg__api(request):
- return request.cls.api
-
--- a/pypy/module/cpyext/dictobject.py Sun Dec 19 11:54:23 2010 +0100
+++ b/pypy/module/cpyext/dictobject.py Sun Dec 19 13:11:22 2010 +0100
@@ -67,6 +67,15 @@
len(p) on a dictionary."""
return space.int_w(space.len(w_obj))
+ at cpython_api([PyObject, PyObject], rffi.INT_real, error=-1)
+def PyDict_Contains(space, w_obj, w_value):
+ """Determine if dictionary p contains key. If an item in p is matches
+ key, return 1, otherwise return 0. On error, return -1.
+ This is equivalent to the Python expression key in p.
+ """
+ w_res = space.contains(w_obj, w_value)
+ return space.int_w(w_res)
+
@cpython_api([PyObject], lltype.Void)
def PyDict_Clear(space, w_obj):
"""Empty an existing dictionary of all key-value pairs."""
--- a/pypy/module/cpyext/floatobject.py Sun Dec 19 11:54:23 2010 +0100
+++ b/pypy/module/cpyext/floatobject.py Sun Dec 19 13:11:22 2010 +0100
@@ -1,6 +1,6 @@
from pypy.rpython.lltypesystem import rffi, lltype
-from pypy.module.cpyext.api import (CANNOT_FAIL, cpython_api, PyObject,
- build_type_checkers)
+from pypy.module.cpyext.api import (
+ CANNOT_FAIL, cpython_api, PyObject, build_type_checkers, CONST_STRING)
from pypy.interpreter.error import OperationError
PyFloat_Check, PyFloat_CheckExact = build_type_checkers("Float")
@@ -24,4 +24,12 @@
"""
Returns the o converted to a float object on success, or NULL on failure.
This is the equivalent of the Python expression float(o)."""
- return space.float(w_obj)
+ return space.call_function(space.w_float, w_obj)
+
+ at cpython_api([PyObject, rffi.CCHARPP], PyObject)
+def PyFloat_FromString(space, w_obj, _):
+ """Create a PyFloatObject object based on the string value in str, or
+ NULL on failure. The pend argument is ignored. It remains only for
+ backward compatibility."""
+ return space.call_function(space.w_float, w_obj)
+
--- a/pypy/module/cpyext/include/Python.h Sun Dec 19 11:54:23 2010 +0100
+++ b/pypy/module/cpyext/include/Python.h Sun Dec 19 13:11:22 2010 +0100
@@ -34,7 +34,23 @@
# endif
# define Py_LOCAL_INLINE(type) static __inline type __fastcall
#endif
-#define DL_IMPORT(RTYPE) PyAPI_FUNC(RTYPE)
+
+/* Deprecated DL_IMPORT and DL_EXPORT macros */
+#ifdef _WIN32
+# if defined(Py_BUILD_CORE)
+# define DL_IMPORT(RTYPE) __declspec(dllexport) RTYPE
+# define DL_EXPORT(RTYPE) __declspec(dllexport) RTYPE
+# else
+# define DL_IMPORT(RTYPE) __declspec(dllimport) RTYPE
+# define DL_EXPORT(RTYPE) __declspec(dllexport) RTYPE
+# endif
+#endif
+#ifndef DL_EXPORT
+# define DL_EXPORT(RTYPE) RTYPE
+#endif
+#ifndef DL_IMPORT
+# define DL_IMPORT(RTYPE) RTYPE
+#endif
#include <stdlib.h>
@@ -57,10 +73,6 @@
#define Py_CHARMASK(c) ((unsigned char)((c) & 0xff))
#endif
-#ifndef DL_EXPORT /* declarations for DLL import/export */
-#define DL_EXPORT(RTYPE) RTYPE
-#endif
-
#define statichere static
#define Py_MEMCPY memcpy
@@ -68,6 +80,7 @@
#include <pypy_macros.h>
#include "patchlevel.h"
+#include "pyconfig.h"
#include "object.h"
#include "pyport.h"
@@ -80,8 +93,6 @@
#include <locale.h>
#include <ctype.h>
-#include "pyconfig.h"
-
#include "boolobject.h"
#include "floatobject.h"
#include "complexobject.h"
--- a/pypy/module/cpyext/include/object.h Sun Dec 19 11:54:23 2010 +0100
+++ b/pypy/module/cpyext/include/object.h Sun Dec 19 13:11:22 2010 +0100
@@ -461,6 +461,11 @@
#define PyObject_GC_New(type, typeobj) \
( (type *) _PyObject_GC_New(typeobj) )
+/* A dummy PyGC_Head, just to please some tests. Don't use it! */
+typedef union _gc_head {
+ char dummy;
+} PyGC_Head;
+
/* Utility macro to help write tp_traverse functions.
* To use this macro, the tp_traverse function must name its arguments
* "visit" and "arg". This is intended to keep tp_traverse functions
--- a/pypy/module/cpyext/include/pyconfig.h Sun Dec 19 11:54:23 2010 +0100
+++ b/pypy/module/cpyext/include/pyconfig.h Sun Dec 19 13:11:22 2010 +0100
@@ -10,11 +10,11 @@
#define HAVE_LONG_LONG 1
#define HAVE_STDARG_PROTOTYPES 1
#define PY_FORMAT_LONG_LONG "ll"
-#define PY_LONG_LONG long long
#define PY_FORMAT_SIZE_T "z"
#define WITH_DOC_STRINGS
#define HAVE_UNICODE
#define WITHOUT_COMPLEX
+#define HAVE_WCHAR_H 1
/* PyPy supposes Py_UNICODE == wchar_t */
#define HAVE_USABLE_WCHAR_T 1
--- a/pypy/module/cpyext/include/pyerrors.h Sun Dec 19 11:54:23 2010 +0100
+++ b/pypy/module/cpyext/include/pyerrors.h Sun Dec 19 13:11:22 2010 +0100
@@ -7,7 +7,12 @@
extern "C" {
#endif
+#define PyExceptionClass_Check(x) \
+ (PyClass_Check((x)) || (PyType_Check((x)) && \
+ PyObject_IsSubclass((x), PyExc_BaseException)))
+
PyObject *PyErr_NewException(char *name, PyObject *base, PyObject *dict);
+PyObject *PyErr_NewExceptionWithDoc(char *name, char *doc, PyObject *base, PyObject *dict);
PyObject *PyErr_Format(PyObject *exception, const char *format, ...);
#ifdef __cplusplus
--- a/pypy/module/cpyext/include/pyport.h Sun Dec 19 11:54:23 2010 +0100
+++ b/pypy/module/cpyext/include/pyport.h Sun Dec 19 13:11:22 2010 +0100
@@ -5,6 +5,29 @@
#include <stdint.h>
#endif
+/* typedefs for some C9X-defined synonyms for integral types. */
+#ifdef HAVE_LONG_LONG
+#ifndef PY_LONG_LONG
+#define PY_LONG_LONG long long
+#if defined(LLONG_MAX)
+/* If LLONG_MAX is defined in limits.h, use that. */
+#define PY_LLONG_MIN LLONG_MIN
+#define PY_LLONG_MAX LLONG_MAX
+#define PY_ULLONG_MAX ULLONG_MAX
+#elif defined(__LONG_LONG_MAX__)
+/* Otherwise, if GCC has a builtin define, use that. */
+#define PY_LLONG_MAX __LONG_LONG_MAX__
+#define PY_LLONG_MIN (-PY_LLONG_MAX-1)
+#define PY_ULLONG_MAX (__LONG_LONG_MAX__*2ULL + 1ULL)
+#else
+/* Otherwise, rely on two's complement. */
+#define PY_ULLONG_MAX (~0ULL)
+#define PY_LLONG_MAX ((long long)(PY_ULLONG_MAX>>1))
+#define PY_LLONG_MIN (-PY_LLONG_MAX-1)
+#endif /* LLONG_MAX */
+#endif
+#endif /* HAVE_LONG_LONG */
+
/* Largest possible value of size_t.
SIZE_MAX is part of C99, so it might be defined on some
platforms. If it is not defined, (size_t)-1 is a portable
--- a/pypy/module/cpyext/include/structmember.h Sun Dec 19 11:54:23 2010 +0100
+++ b/pypy/module/cpyext/include/structmember.h Sun Dec 19 13:11:22 2010 +0100
@@ -24,17 +24,23 @@
#define T_SHORT 0
#define T_INT 1
#define T_LONG 2
+#define T_FLOAT 3
+#define T_DOUBLE 4
#define T_STRING 5
#define T_OBJECT 6
#define T_CHAR 7 /* 1-character string */
#define T_BYTE 8 /* 8-bit signed int */
+#define T_UBYTE 9
#define T_USHORT 10
#define T_UINT 11
#define T_ULONG 12
-#define T_STRING_INPLACE 13 /* Strings contained in the structure */
+#define T_STRING_INPLACE 13 /* Strings contained in the structure */
+#define T_BOOL 14
#define T_OBJECT_EX 16 /* Like T_OBJECT, but raises AttributeError
when the value is NULL, instead of
converting to None. */
+#define T_LONGLONG 17
+#define T_ULONGLONG 18
/* Flags */
#define READONLY 1
--- a/pypy/module/cpyext/intobject.py Sun Dec 19 11:54:23 2010 +0100
+++ b/pypy/module/cpyext/intobject.py Sun Dec 19 13:11:22 2010 +0100
@@ -1,9 +1,10 @@
from pypy.rpython.lltypesystem import rffi, lltype
from pypy.interpreter.error import OperationError
-from pypy.module.cpyext.api import (cpython_api, PyObject, CANNOT_FAIL,
- build_type_checkers, Py_ssize_t)
-
+from pypy.module.cpyext.api import (
+ cpython_api, build_type_checkers, PyObject,
+ CONST_STRING, CANNOT_FAIL, Py_ssize_t)
+from pypy.rlib.rarithmetic import r_uint
PyInt_Check, PyInt_CheckExact = build_type_checkers("Int")
@@ -35,6 +36,20 @@
space.wrap("an integer is required, got NULL"))
return space.uint_w(space.int(w_obj))
+ at cpython_api([PyObject], rffi.ULONG, error=-1)
+def PyInt_AsUnsignedLongMask(space, w_obj):
+ """Will first attempt to cast the object to a PyIntObject or
+ PyLongObject, if it is not already one, and then return its value as
+ unsigned long. This function does not check for overflow.
+ """
+ w_int = space.int(w_obj)
+ if space.is_true(space.isinstance(w_int, space.w_int)):
+ num = space.int_w(w_int)
+ return r_uint(num)
+ else:
+ num = space.bigint_w(w_int)
+ return num.uintmask()
+
@cpython_api([PyObject], lltype.Signed, error=CANNOT_FAIL)
def PyInt_AS_LONG(space, w_int):
"""Return the value of the object w_int. No error checking is performed."""
@@ -58,3 +73,26 @@
returned.
"""
return space.wrap(ival) # XXX this is wrong on win64
+
+ at cpython_api([CONST_STRING, rffi.CCHARPP, rffi.INT_real], PyObject)
+def PyInt_FromString(space, str, pend, base):
+ """Return a new PyIntObject or PyLongObject based on the string
+ value in str, which is interpreted according to the radix in base. If
+ pend is non-NULL, *pend will point to the first character in str which
+ follows the representation of the number. If base is 0, the radix will be
+ determined based on the leading characters of str: if str starts with
+ '0x' or '0X', radix 16 will be used; if str starts with '0', radix
+ 8 will be used; otherwise radix 10 will be used. If base is not 0, it
+ must be between 2 and 36, inclusive. Leading spaces are ignored. If
+ there are no digits, ValueError will be raised. If the string represents
+ a number too large to be contained within the machine's long int type
+ and overflow warnings are being suppressed, a PyLongObject will be
+ returned. If overflow warnings are not being suppressed, NULL will be
+ returned in this case."""
+ s = rffi.charp2str(str)
+ w_str = space.wrap(s)
+ w_base = space.wrap(rffi.cast(lltype.Signed, base))
+ if pend:
+ pend[0] = rffi.ptradd(str, len(s))
+ return space.call_function(space.w_int, w_str, w_base)
+
--- a/pypy/module/cpyext/longobject.py Sun Dec 19 11:54:23 2010 +0100
+++ b/pypy/module/cpyext/longobject.py Sun Dec 19 13:11:22 2010 +0100
@@ -3,6 +3,7 @@
CONST_STRING, ADDR)
from pypy.objspace.std.longobject import W_LongObject
from pypy.interpreter.error import OperationError
+from pypy.module.cpyext.intobject import PyInt_AsUnsignedLongMask
PyLong_Check, PyLong_CheckExact = build_type_checkers("Long")
@@ -38,6 +39,13 @@
raised."""
return rffi.cast(rffi.ULONG, space.uint_w(w_long))
+ at cpython_api([PyObject], rffi.ULONG, error=-1)
+def PyLong_AsUnsignedLongMask(space, w_long):
+ """Return a C unsigned long from a Python long integer, without checking
+ for overflow.
+ """
+ return PyInt_AsUnsignedLongMask(space, w_long)
+
@cpython_api([PyObject], lltype.Signed, error=-1)
def PyLong_AsLong(space, w_long):
"""
@@ -62,6 +70,57 @@
raised."""
return rffi.cast(rffi.ULONGLONG, space.r_ulonglong_w(w_long))
+ at cpython_api([PyObject], rffi.ULONGLONG, error=-1)
+def PyLong_AsUnsignedLongLongMask(space, w_long):
+ """Will first attempt to cast the object to a PyIntObject or
+ PyLongObject, if it is not already one, and then return its value as
+ unsigned long long, without checking for overflow.
+ """
+ num = space.bigint_w(w_long)
+ return num.ulonglongmask()
+
+ at cpython_api([PyObject, rffi.CArrayPtr(rffi.INT_real)], lltype.Signed,
+ error=-1)
+def PyLong_AsLongAndOverflow(space, w_long, overflow_ptr):
+ """
+ Return a C long representation of the contents of pylong. If pylong is
+ greater than LONG_MAX or less than LONG_MIN, set *overflow to 1 or -1,
+ respectively, and return -1; otherwise, set *overflow to 0. If any other
+ exception occurs (for example a TypeError or MemoryError), then -1 will be
+ returned and *overflow will be 0."""
+ overflow_ptr[0] = rffi.cast(rffi.INT_real, 0)
+ try:
+ return space.int_w(w_long)
+ except OperationError, e:
+ if not e.match(space, space.w_OverflowError):
+ raise
+ if space.is_true(space.gt(w_long, space.wrap(0))):
+ overflow_ptr[0] = rffi.cast(rffi.INT_real, 1)
+ else:
+ overflow_ptr[0] = rffi.cast(rffi.INT_real, -1)
+ return -1
+
+ at cpython_api([PyObject, rffi.CArrayPtr(rffi.INT_real)], rffi.LONGLONG,
+ error=-1)
+def PyLong_AsLongLongAndOverflow(space, w_long, overflow_ptr):
+ """
+ Return a C long long representation of the contents of pylong. If pylong is
+ greater than PY_LLONG_MAX or less than PY_LLONG_MIN, set *overflow to 1 or
+ -1, respectively, and return -1; otherwise, set *overflow to 0. If any
+ other exception occurs (for example a TypeError or MemoryError), then -1
+ will be returned and *overflow will be 0."""
+ overflow_ptr[0] = rffi.cast(rffi.INT_real, 0)
+ try:
+ return rffi.cast(rffi.LONGLONG, space.r_longlong_w(w_long))
+ except OperationError, e:
+ if not e.match(space, space.w_OverflowError):
+ raise
+ if space.is_true(space.gt(w_long, space.wrap(0))):
+ overflow_ptr[0] = rffi.cast(rffi.INT_real, 1)
+ else:
+ overflow_ptr[0] = rffi.cast(rffi.INT_real, -1)
+ return -1
+
@cpython_api([lltype.Float], PyObject)
def PyLong_FromDouble(space, val):
"""Return a new PyLongObject object from v, or NULL on failure."""
--- a/pypy/module/cpyext/methodobject.py Sun Dec 19 11:54:23 2010 +0100
+++ b/pypy/module/cpyext/methodobject.py Sun Dec 19 13:11:22 2010 +0100
@@ -16,13 +16,14 @@
from pypy.rlib.objectmodel import we_are_translated
from pypy.objspace.std.tupleobject import W_TupleObject
+PyCFunction_typedef = rffi.COpaquePtr('PyCFunction')
PyCFunction = lltype.Ptr(lltype.FuncType([PyObject, PyObject], PyObject))
PyCFunctionKwArgs = lltype.Ptr(lltype.FuncType([PyObject, PyObject, PyObject], PyObject))
PyMethodDef = cpython_struct(
'PyMethodDef',
[('ml_name', rffi.CCHARP),
- ('ml_meth', PyCFunction),
+ ('ml_meth', PyCFunction_typedef),
('ml_flags', rffi.INT_real),
('ml_doc', rffi.CCHARP),
])
@@ -70,12 +71,14 @@
if space.is_true(w_kw) and not flags & METH_KEYWORDS:
raise OperationError(space.w_TypeError, space.wrap(
rffi.charp2str(self.ml.c_ml_name) + "() takes no keyword arguments"))
+
+ func = rffi.cast(PyCFunction, self.ml.c_ml_meth)
if flags & METH_KEYWORDS:
func = rffi.cast(PyCFunctionKwArgs, self.ml.c_ml_meth)
return generic_cpy_call(space, func, w_self, w_args, w_kw)
elif flags & METH_NOARGS:
if len(w_args.wrappeditems) == 0:
- return generic_cpy_call(space, self.ml.c_ml_meth, w_self, None)
+ return generic_cpy_call(space, func, w_self, None)
raise OperationError(space.w_TypeError, space.wrap(
rffi.charp2str(self.ml.c_ml_name) + "() takes no arguments"))
elif flags & METH_O:
@@ -86,9 +89,9 @@
rffi.charp2str(self.ml.c_ml_name),
len(w_args.wrappeditems))))
w_arg = w_args.wrappeditems[0]
- return generic_cpy_call(space, self.ml.c_ml_meth, w_self, w_arg)
+ return generic_cpy_call(space, func, w_self, w_arg)
elif flags & METH_VARARGS:
- return generic_cpy_call(space, self.ml.c_ml_meth, w_self, w_args)
+ return generic_cpy_call(space, func, w_self, w_args)
else: # METH_OLDARGS, the really old style
size = len(w_args.wrappeditems)
if size == 1:
@@ -97,7 +100,7 @@
w_arg = None
else:
w_arg = w_args
- return generic_cpy_call(space, self.ml.c_ml_meth, w_self, w_arg)
+ return generic_cpy_call(space, func, w_self, w_arg)
def get_doc(space, self):
doc = self.ml.c_ml_doc
@@ -231,6 +234,11 @@
def PyCFunction_NewEx(space, ml, w_self, w_name):
return space.wrap(W_PyCFunctionObject(space, ml, w_self, w_name))
+ at cpython_api([PyObject], PyCFunction_typedef)
+def PyCFunction_GetFunction(space, w_obj):
+ cfunction = space.interp_w(W_PyCFunctionObject, w_obj)
+ return cfunction.ml.c_ml_meth
+
@cpython_api([PyObject], PyObject)
def PyStaticMethod_New(space, w_func):
return space.wrap(StaticMethod(w_func))
--- a/pypy/module/cpyext/modsupport.py Sun Dec 19 11:54:23 2010 +0100
+++ b/pypy/module/cpyext/modsupport.py Sun Dec 19 13:11:22 2010 +0100
@@ -5,7 +5,7 @@
from pypy.interpreter.module import Module
from pypy.module.cpyext.methodobject import (
W_PyCFunctionObject, PyCFunction_NewEx, PyDescr_NewMethod,
- PyMethodDef, PyCFunction, PyStaticMethod_New)
+ PyMethodDef, PyStaticMethod_New)
from pypy.module.cpyext.pyerrors import PyErr_BadInternalCall
from pypy.module.cpyext.state import State
from pypy.interpreter.error import OperationError
--- a/pypy/module/cpyext/object.py Sun Dec 19 11:54:23 2010 +0100
+++ b/pypy/module/cpyext/object.py Sun Dec 19 13:11:22 2010 +0100
@@ -15,7 +15,7 @@
import pypy.module.__builtin__.operation as operation
- at cpython_api([Py_ssize_t], rffi.VOIDP, error=lltype.nullptr(rffi.VOIDP.TO))
+ at cpython_api([Py_ssize_t], rffi.VOIDP)
def PyObject_MALLOC(space, size):
return lltype.malloc(rffi.VOIDP.TO, size,
flavor='raw', zero=True)
--- a/pypy/module/cpyext/pyerrors.py Sun Dec 19 11:54:23 2010 +0100
+++ b/pypy/module/cpyext/pyerrors.py Sun Dec 19 13:11:22 2010 +0100
@@ -275,3 +275,12 @@
def PyErr_Print(space):
"""Alias for PyErr_PrintEx(1)."""
PyErr_PrintEx(space, 1)
+
+ at cpython_api([PyObject, PyObject], rffi.INT_real, error=-1)
+def PyTraceBack_Print(space, w_tb, w_file):
+ space.call_method(w_file, "write", space.wrap(
+ 'Traceback (most recent call last):\n'))
+ w_traceback = space.call_method(space.builtin, '__import__',
+ space.wrap("traceback"))
+ space.call_method(w_traceback, "print_tb", w_tb, space.w_None, w_file)
+ return 0
--- a/pypy/module/cpyext/src/getargs.c Sun Dec 19 11:54:23 2010 +0100
+++ b/pypy/module/cpyext/src/getargs.c Sun Dec 19 13:11:22 2010 +0100
@@ -558,8 +558,6 @@
switch (c) {
case 'b': { /* unsigned byte -- very short int */
- Py_FatalError("'b' unimplemented for PyArg_*\n");
-#if 0
char *p = va_arg(*p_va, char *);
long ival;
if (float_argument_error(arg))
@@ -580,13 +578,10 @@
else
*p = (unsigned char) ival;
break;
-#endif
}
case 'B': {/* byte sized bitfield - both signed and unsigned
values allowed */
- Py_FatalError("'B' unimplemented for PyArg_*\n");
-#if 0
char *p = va_arg(*p_va, char *);
long ival;
if (float_argument_error(arg))
@@ -597,12 +592,9 @@
else
*p = (unsigned char) ival;
break;
-#endif
}
case 'h': {/* signed short int */
- Py_FatalError("'h' unimplemented for PyArg_*\n");
-#if 0
short *p = va_arg(*p_va, short *);
long ival;
if (float_argument_error(arg))
@@ -623,13 +615,10 @@
else
*p = (short) ival;
break;
-#endif
}
case 'H': { /* short int sized bitfield, both signed and
unsigned allowed */
- Py_FatalError("'H' unimplemented for PyArg_*\n");
-#if 0
unsigned short *p = va_arg(*p_va, unsigned short *);
long ival;
if (float_argument_error(arg))
@@ -640,7 +629,6 @@
else
*p = (unsigned short) ival;
break;
-#endif
}
case 'i': {/* signed int */
int *p = va_arg(*p_va, int *);
@@ -666,8 +654,6 @@
}
case 'I': { /* int sized bitfield, both signed and
unsigned allowed */
- Py_FatalError("'I' unimplemented for PyArg_*\n");
-#if 0
unsigned int *p = va_arg(*p_va, unsigned int *);
unsigned int ival;
if (float_argument_error(arg))
@@ -678,7 +664,6 @@
else
*p = ival;
break;
-#endif
}
case 'n': /* Py_ssize_t */
#if SIZEOF_SIZE_T != SIZEOF_LONG
@@ -709,8 +694,6 @@
}
case 'k': { /* long sized bitfield */
- Py_FatalError("'k' unimplemented for PyArg_*\n");
-#if 0
unsigned long *p = va_arg(*p_va, unsigned long *);
unsigned long ival;
if (PyInt_Check(arg))
@@ -721,13 +704,10 @@
return converterr("integer<k>", arg, msgbuf, bufsize);
*p = ival;
break;
-#endif
}
#ifdef HAVE_LONG_LONG
case 'L': {/* PY_LONG_LONG */
- Py_FatalError("'L' unimplemented for PyArg_*\n");
-#if 0
PY_LONG_LONG *p = va_arg( *p_va, PY_LONG_LONG * );
PY_LONG_LONG ival = PyLong_AsLongLong( arg );
if (ival == (PY_LONG_LONG)-1 && PyErr_Occurred() ) {
@@ -736,12 +716,9 @@
*p = ival;
}
break;
-#endif
}
case 'K': { /* long long sized bitfield */
- Py_FatalError("'K' unimplemented for PyArg_*\n");
-#if 0
unsigned PY_LONG_LONG *p = va_arg(*p_va, unsigned PY_LONG_LONG *);
unsigned PY_LONG_LONG ival;
if (PyInt_Check(arg))
@@ -752,7 +729,6 @@
return converterr("integer<K>", arg, msgbuf, bufsize);
*p = ival;
break;
-#endif
}
#endif // HAVE_LONG_LONG
@@ -778,8 +754,6 @@
#ifndef WITHOUT_COMPLEX
case 'D': {/* complex double */
- Py_FatalError("'D' unimplemented for PyArg_*\n");
-#if 0
Py_complex *p = va_arg(*p_va, Py_complex *);
Py_complex cval;
cval = PyComplex_AsCComplex(arg);
@@ -788,7 +762,6 @@
else
*p = cval;
break;
-#endif
}
#endif /* WITHOUT_COMPLEX */
@@ -986,8 +959,6 @@
break;
}
case 'e': {/* encoded string */
- Py_FatalError("'e' unimplemented for PyArg_*\n");
-#if 0
char **buffer;
const char *encoding;
PyObject *s;
@@ -1151,7 +1122,6 @@
}
Py_DECREF(s);
break;
-#endif
}
#ifdef Py_USING_UNICODE
--- a/pypy/module/cpyext/src/pyerrors.c Sun Dec 19 11:54:23 2010 +0100
+++ b/pypy/module/cpyext/src/pyerrors.c Sun Dec 19 13:11:22 2010 +0100
@@ -69,3 +69,37 @@
Py_XDECREF(modulename);
return result;
}
+
+/* Create an exception with docstring */
+PyObject *
+PyErr_NewExceptionWithDoc(char *name, char *doc, PyObject *base, PyObject *dict)
+{
+ int result;
+ PyObject *ret = NULL;
+ PyObject *mydict = NULL; /* points to the dict only if we create it */
+ PyObject *docobj;
+
+ if (dict == NULL) {
+ dict = mydict = PyDict_New();
+ if (dict == NULL) {
+ return NULL;
+ }
+ }
+
+ if (doc != NULL) {
+ docobj = PyString_FromString(doc);
+ if (docobj == NULL)
+ goto failure;
+ result = PyDict_SetItemString(dict, "__doc__", docobj);
+ Py_DECREF(docobj);
+ if (result < 0)
+ goto failure;
+ }
+
+ ret = PyErr_NewException(name, base, dict);
+ failure:
+ Py_XDECREF(mydict);
+ return ret;
+}
+
+
--- a/pypy/module/cpyext/structmember.py Sun Dec 19 11:54:23 2010 +0100
+++ b/pypy/module/cpyext/structmember.py Sun Dec 19 13:11:22 2010 +0100
@@ -1,64 +1,77 @@
from pypy.interpreter.error import OperationError
from pypy.interpreter.typedef import TypeDef, GetSetProperty
from pypy.rpython.lltypesystem import rffi, lltype
-from pypy.module.cpyext import structmemberdefs
+from pypy.module.cpyext.structmemberdefs import *
from pypy.module.cpyext.api import ADDR, PyObjectP, cpython_api
from pypy.module.cpyext.intobject import PyInt_AsLong, PyInt_AsUnsignedLong
from pypy.module.cpyext.pyerrors import PyErr_Occurred
from pypy.module.cpyext.pyobject import PyObject, Py_DecRef, from_ref, make_ref
-from pypy.module.cpyext.stringobject import (PyString_FromString,
- PyString_FromStringAndSize)
+from pypy.module.cpyext.stringobject import (
+ PyString_FromString, PyString_FromStringAndSize)
+from pypy.module.cpyext.floatobject import PyFloat_AsDouble
+from pypy.module.cpyext.longobject import (
+ PyLong_AsLongLong, PyLong_AsUnsignedLongLong)
from pypy.module.cpyext.typeobjectdefs import PyMemberDef
+from pypy.rlib.unroll import unrolling_iterable
+
+integer_converters = unrolling_iterable([
+ (T_SHORT, rffi.SHORT, PyInt_AsLong),
+ (T_INT, rffi.INT, PyInt_AsLong),
+ (T_LONG, rffi.LONG, PyInt_AsLong),
+ (T_USHORT, rffi.USHORT, PyInt_AsUnsignedLong),
+ (T_UINT, rffi.UINT, PyInt_AsUnsignedLong),
+ (T_ULONG, rffi.ULONG, PyInt_AsUnsignedLong),
+ (T_BYTE, rffi.UCHAR, PyInt_AsLong),
+ (T_UBYTE, rffi.UCHAR, PyInt_AsUnsignedLong),
+ (T_BOOL, rffi.UCHAR, PyInt_AsLong),
+ (T_FLOAT, rffi.FLOAT, PyFloat_AsDouble),
+ (T_DOUBLE, rffi.DOUBLE, PyFloat_AsDouble),
+ (T_LONGLONG, rffi.LONGLONG, PyLong_AsLongLong),
+ (T_ULONGLONG, rffi.ULONGLONG, PyLong_AsUnsignedLongLong),
+ ])
@cpython_api([PyObject, lltype.Ptr(PyMemberDef)], PyObject)
def PyMember_GetOne(space, obj, w_member):
addr = rffi.cast(ADDR, obj)
addr += w_member.c_offset
+
member_type = rffi.cast(lltype.Signed, w_member.c_type)
- if member_type == structmemberdefs.T_SHORT:
- result = rffi.cast(rffi.SHORTP, addr)
- w_result = space.wrap(result[0])
- elif member_type == structmemberdefs.T_INT:
- result = rffi.cast(rffi.INTP, addr)
- w_result = space.wrap(result[0])
- elif member_type == structmemberdefs.T_LONG:
- result = rffi.cast(rffi.LONGP, addr)
- w_result = space.wrap(result[0])
- elif member_type == structmemberdefs.T_USHORT:
- result = rffi.cast(rffi.USHORTP, addr)
- w_result = space.wrap(result[0])
- elif member_type == structmemberdefs.T_UINT:
- result = rffi.cast(rffi.UINTP, addr)
- w_result = space.wrap(result[0])
- elif member_type == structmemberdefs.T_ULONG:
- result = rffi.cast(rffi.ULONGP, addr)
- w_result = space.wrap(result[0])
- elif member_type == structmemberdefs.T_BYTE:
- result = rffi.cast(rffi.CCHARP, addr)
- w_result = space.wrap(result[0])
- elif member_type == structmemberdefs.T_STRING:
+ for converter in integer_converters:
+ typ, lltyp, _ = converter
+ if typ == member_type:
+ result = rffi.cast(rffi.CArrayPtr(lltyp), addr)
+ if lltyp is rffi.FLOAT:
+ w_result = space.wrap(rffi.cast(rffi.DOUBLE, result[0]))
+ else:
+ w_result = space.wrap(result[0])
+ return w_result
+
+ if member_type == T_STRING:
result = rffi.cast(rffi.CCHARPP, addr)
if result[0]:
w_result = PyString_FromString(space, result[0])
else:
w_result = space.w_None
- elif member_type == structmemberdefs.T_STRING_INPLACE:
+ elif member_type == T_STRING_INPLACE:
result = rffi.cast(rffi.CCHARP, addr)
w_result = PyString_FromString(space, result)
- elif member_type == structmemberdefs.T_CHAR:
+ elif member_type == T_CHAR:
result = rffi.cast(rffi.CCHARP, addr)
w_result = space.wrap(result[0])
- elif member_type in [structmemberdefs.T_OBJECT,
- structmemberdefs.T_OBJECT_EX]:
+ elif member_type == T_OBJECT:
obj_ptr = rffi.cast(PyObjectP, addr)
if obj_ptr[0]:
w_result = from_ref(space, obj_ptr[0])
else:
- if member_type == structmemberdefs.T_OBJECT_EX:
- w_name = space.wrap(rffi.charp2str(w_member.c_name))
- raise OperationError(space.w_AttributeError, w_name)
w_result = space.w_None
+ elif member_type == T_OBJECT_EX:
+ obj_ptr = rffi.cast(PyObjectP, addr)
+ if obj_ptr[0]:
+ w_result = from_ref(space, obj_ptr[0])
+ else:
+ w_name = space.wrap(rffi.charp2str(w_member.c_name))
+ raise OperationError(space.w_AttributeError, w_name)
else:
raise OperationError(space.w_SystemError,
space.wrap("bad memberdescr type"))
@@ -72,57 +85,35 @@
member_type = rffi.cast(lltype.Signed, w_member.c_type)
flags = rffi.cast(lltype.Signed, w_member.c_flags)
- if (flags & structmemberdefs.READONLY or
- member_type in [structmemberdefs.T_STRING,
- structmemberdefs.T_STRING_INPLACE]):
+ if (flags & READONLY or
+ member_type in [T_STRING, T_STRING_INPLACE]):
raise OperationError(space.w_TypeError,
space.wrap("readonly attribute"))
elif w_value is None:
- if member_type == structmemberdefs.T_OBJECT_EX:
+ if member_type == T_OBJECT_EX:
if not rffi.cast(PyObjectP, addr)[0]:
w_name = space.wrap(rffi.charp2str(w_member.c_name))
raise OperationError(space.w_AttributeError, w_name)
- elif member_type != structmemberdefs.T_OBJECT:
+ elif member_type != T_OBJECT:
raise OperationError(space.w_TypeError,
space.wrap("can't delete numeric/char attribute"))
- if member_type == structmemberdefs.T_SHORT:
- w_long_value = PyInt_AsLong(space, w_value)
- array = rffi.cast(rffi.SHORTP, addr)
- array[0] = rffi.cast(rffi.SHORT, w_long_value)
- elif member_type == structmemberdefs.T_INT:
- w_long_value = PyInt_AsLong(space, w_value)
- array = rffi.cast(rffi.INTP, addr)
- array[0] = rffi.cast(rffi.INT, w_long_value)
- elif member_type == structmemberdefs.T_LONG:
- w_long_value = PyInt_AsLong(space, w_value)
- array = rffi.cast(rffi.LONGP, addr)
- array[0] = rffi.cast(rffi.LONG, w_long_value)
- elif member_type == structmemberdefs.T_USHORT:
- w_long_value = PyInt_AsUnsignedLong(space, w_value)
- array = rffi.cast(rffi.USHORTP, addr)
- array[0] = rffi.cast(rffi.USHORT, w_long_value)
- elif member_type == structmemberdefs.T_UINT:
- w_long_value = PyInt_AsUnsignedLong(space, w_value)
- array = rffi.cast(rffi.UINTP, addr)
- array[0] = rffi.cast(rffi.UINT, w_long_value)
- elif member_type == structmemberdefs.T_ULONG:
- w_long_value = PyInt_AsUnsignedLong(space, w_value)
- array = rffi.cast(rffi.ULONGP, addr)
- array[0] = rffi.cast(rffi.ULONG, w_long_value)
- elif member_type == structmemberdefs.T_BYTE:
- w_long_value = PyInt_AsLong(space, w_value)
- array = rffi.cast(rffi.CCHARP, addr)
- array[0] = rffi.cast(rffi.CHAR, w_long_value)
- elif member_type == structmemberdefs.T_CHAR:
+ for converter in integer_converters:
+ typ, lltyp, getter = converter
+ if typ == member_type:
+ value = getter(space, w_value)
+ array = rffi.cast(rffi.CArrayPtr(lltyp), addr)
+ array[0] = rffi.cast(lltyp, value)
+ return 0
+
+ if member_type == T_CHAR:
str_value = space.str_w(w_value)
if len(str_value) != 1:
raise OperationError(space.w_TypeError,
space.wrap("string of length 1 expected"))
array = rffi.cast(rffi.CCHARP, addr)
array[0] = str_value[0]
- elif member_type in [structmemberdefs.T_OBJECT,
- structmemberdefs.T_OBJECT_EX]:
+ elif member_type in [T_OBJECT, T_OBJECT_EX]:
array = rffi.cast(PyObjectP, addr)
if array[0]:
Py_DecRef(space, array[0])
--- a/pypy/module/cpyext/structmemberdefs.py Sun Dec 19 11:54:23 2010 +0100
+++ b/pypy/module/cpyext/structmemberdefs.py Sun Dec 19 13:11:22 2010 +0100
@@ -1,14 +1,20 @@
T_SHORT = 0
T_INT = 1
T_LONG = 2
+T_FLOAT = 3
+T_DOUBLE = 4
T_STRING = 5
T_OBJECT = 6
T_CHAR = 7
T_BYTE = 8
+T_UBYTE = 9
T_USHORT = 10
T_UINT = 11
T_ULONG = 12
T_STRING_INPLACE = 13
+T_BOOL = 14
T_OBJECT_EX = 16
+T_LONGLONG = 17
+T_ULONGLONG = 18
READONLY = RO = 1
--- a/pypy/module/cpyext/stubs.py Sun Dec 19 11:54:23 2010 +0100
+++ b/pypy/module/cpyext/stubs.py Sun Dec 19 13:11:22 2010 +0100
@@ -4,73 +4,34 @@
from pypy.rpython.lltypesystem import rffi, lltype
# we don't really care
-PyTypeObjectPtr = lltype.Void
-Py_ssize_t = lltype.Void
-PyMethodDef = lltype.Void
-PyGetSetDef = lltype.Void
-PyMemberDef = lltype.Void
-Py_buffer = lltype.Void
-Py_complex = lltype.Void
-va_list = lltype.Void
-PyDateTime_Date = lltype.Void
-PyDateTime_DateTime = lltype.Void
-PyDateTime_Time = lltype.Void
-wrapperbase = lltype.Void
-FILE = lltype.Void
-PyFileObject = lltype.Void
-PyCodeObject = lltype.Void
-PyFrameObject = lltype.Void
-_inittab = lltype.Void
-PyThreadState = lltype.Void
-PyInterpreterState = lltype.Void
-#PyOS_sighandler_t = lltype.Void
-Py_UNICODE = lltype.Void
-PyCompilerFlags = lltype.Void
-_node = lltype.Void
+PyTypeObjectPtr = rffi.VOIDP
+Py_ssize_t = rffi.VOIDP
+PyMethodDef = rffi.VOIDP
+PyGetSetDef = rffi.VOIDP
+PyMemberDef = rffi.VOIDP
+Py_buffer = rffi.VOIDP
+Py_complex = rffi.VOIDP
+va_list = rffi.VOIDP
+PyDateTime_Date = rffi.VOIDP
+PyDateTime_DateTime = rffi.VOIDP
+PyDateTime_Time = rffi.VOIDP
+wrapperbase = rffi.VOIDP
+FILE = rffi.VOIDP
+PyFileObject = rffi.VOIDP
+PyCodeObject = rffi.VOIDP
+PyFrameObject = rffi.VOIDP
+_inittab = rffi.VOIDP
+PyThreadState = rffi.VOIDP
+PyInterpreterState = rffi.VOIDP
+PyOS_sighandler_t = rffi.VOIDP
+Py_UNICODE = rffi.VOIDP
+PyCompilerFlags = rffi.VOIDP
+_node = rffi.VOIDP
@cpython_api([PyObject], lltype.Void)
def _PyObject_Del(space, op):
raise NotImplementedError
- at cpython_api([rffi.CCHARP, PyMethodDef], PyObject)
-def Py_InitModule(space, name, methods):
- """Create a new module object based on a name and table of functions,
- returning the new module object.
-
- Older versions of Python did not support NULL as the value for the
- methods argument."""
- borrow_from()
- raise NotImplementedError
-
- at cpython_api([rffi.CCHARP, PyMethodDef, rffi.CCHARP], PyObject)
-def Py_InitModule3(space, name, methods, doc):
- """Create a new module object based on a name and table of functions,
- returning the new module object. If doc is non-NULL, it will be used
- to define the docstring for the module.
-
- Older versions of Python did not support NULL as the value for the
- methods argument."""
- borrow_from()
- raise NotImplementedError
-
- at cpython_api([PyObject, rffi.CCHARP, va_list], rffi.INT_real, error=0)
-def PyArg_VaParse(space, args, format, vargs):
- """Identical to PyArg_ParseTuple(), except that it accepts a va_list
- rather than a variable number of arguments."""
- raise NotImplementedError
-
- at cpython_api([PyObject, PyObject, rffi.CCHARP, rffi.CCHARP, va_list], rffi.INT_real, error=0)
-def PyArg_VaParseTupleAndKeywords(space, args, kw, format, keywords, vargs):
- """Identical to PyArg_ParseTupleAndKeywords(), except that it accepts a
- va_list rather than a variable number of arguments."""
- raise NotImplementedError
-
- at cpython_api([rffi.CCHARP, va_list], PyObject)
-def Py_VaBuildValue(space, format, vargs):
- """Identical to Py_BuildValue(), except that it accepts a va_list
- rather than a variable number of arguments."""
- raise NotImplementedError
-
@cpython_api([PyObject], rffi.INT_real, error=0)
def PyObject_CheckBuffer(space, obj):
"""Return 1 if obj supports the buffer interface otherwise 0."""
@@ -261,11 +222,6 @@
length. Return 0 on success and -1 (with raising an error) on error."""
raise NotImplementedError
- at cpython_api([PyObject], PyObject)
-def PyMemoryView_FromObject(space, obj):
- """Return a memoryview object from an object that defines the buffer interface."""
- raise NotImplementedError
-
@cpython_api([PyObject], rffi.INT_real, error=CANNOT_FAIL)
def PyByteArray_Check(space, o):
"""Return true if the object o is a bytearray object or an instance of a
@@ -402,13 +358,6 @@
version since the definition of the bytecode changes often."""
raise NotImplementedError
- at cpython_api([rffi.CCHARP, rffi.CCHARP, rffi.INT_real], PyObject)
-def PyCode_NewEmpty(space, filename, funcname, firstlineno):
- """Return a new empty code object with the specified filename,
- function name, and first line number. It is illegal to
- exec or eval() the resulting code object."""
- raise NotImplementedError
-
@cpython_api([Py_complex, Py_complex], Py_complex)
def _Py_c_sum(space, left, right):
"""Return the sum of two complex numbers, using the C Py_complex
@@ -627,14 +576,6 @@
"""
raise NotImplementedError
- at cpython_api([PyObject, PyObject], rffi.INT_real, error=-1)
-def PyDict_Contains(space, p, key):
- """Determine if dictionary p contains key. If an item in p is matches
- key, return 1, otherwise return 0. On error, return -1.
- This is equivalent to the Python expression key in p.
- """
- raise NotImplementedError
-
@cpython_api([PyObject, rffi.CCHARP], rffi.INT_real, error=-1)
def PyDict_DelItemString(space, p, key):
"""Remove the entry in dictionary p which has a key specified by the string
@@ -716,13 +657,6 @@
described there."""
raise NotImplementedError
- at cpython_api([rffi.CCHARP, rffi.INT_real], rffi.INT_real, error=-1)
-def PyErr_WarnPy3k(space, message, stacklevel):
- """Issue a DeprecationWarning with the given message and stacklevel
- if the Py_Py3kWarningFlag flag is enabled.
- """
- raise NotImplementedError
-
@cpython_api([], lltype.Void)
def PyErr_SetInterrupt(space, ):
"""
@@ -748,14 +682,6 @@
only be called from the main thread."""
raise NotImplementedError
- at cpython_api([rffi.CCHARP, rffi.CCHARP, PyObject, PyObject], PyObject)
-def PyErr_NewExceptionWithDoc(space, name, doc, base, dict):
- """Same as PyErr_NewException(), except that the new exception class can
- easily be given a docstring: If doc is non-NULL, it will be used as the
- docstring for the exception class.
- """
- raise NotImplementedError
-
@cpython_api([PyObject], lltype.Void)
def PyErr_WriteUnraisable(space, obj):
"""This utility function prints a warning message to sys.stderr when an
@@ -879,13 +805,6 @@
failure; the appropriate exception will be set."""
raise NotImplementedError
- at cpython_api([PyObject, rffi.CCHARPP], PyObject)
-def PyFloat_FromString(space, str, pend):
- """Create a PyFloatObject object based on the string value in str, or
- NULL on failure. The pend argument is ignored. It remains only for
- backward compatibility."""
- raise NotImplementedError
-
@cpython_api([rffi.VOIDP_real], PyObject)
def PyFloat_GetInfo(space, info):
"""Return a structseq instance which contains information about the
@@ -1024,22 +943,6 @@
extension modules."""
raise NotImplementedError
- at cpython_api([PyObject], lltype.Void)
-def Py_VISIT(space, o):
- """Call the visit callback, with arguments o and arg. If visit returns
- a non-zero value, then return it. Using this macro, tp_traverse
- handlers look like:
-
- static int
- my_traverse(Noddy *self, visitproc visit, void *arg)
- {
- Py_VISIT(self->foo);
- Py_VISIT(self->bar);
- return 0;
- }
- """
- raise NotImplementedError
-
@cpython_api([PyObject], rffi.INT_real, error=CANNOT_FAIL)
def PyGen_Check(space, gen):
"""Return true if ob is a generator object; ob must not be NULL."""
@@ -1058,18 +961,6 @@
NULL."""
raise NotImplementedError
- at cpython_api([rffi.CCHARP], PyObject)
-def PyImport_ImportModuleNoBlock(space, name):
- """This version of PyImport_ImportModule() does not block. It's intended
- to be used in C functions that import other modules to execute a function.
- The import may block if another thread holds the import lock. The function
- PyImport_ImportModuleNoBlock() never blocks. It first tries to fetch
- the module from sys.modules and falls back to PyImport_ImportModule()
- unless the lock is held, in which case the function will raise an
- ImportError.
- """
- raise NotImplementedError
-
@cpython_api([rffi.CCHARP, PyObject, PyObject, PyObject], PyObject)
def PyImport_ImportModuleEx(space, name, globals, locals, fromlist):
"""
@@ -1789,23 +1680,6 @@
"""
raise NotImplementedError
- at cpython_api([rffi.CCHARP, rffi.CCHARPP, rffi.INT_real], PyObject)
-def PyInt_FromString(space, str, pend, base):
- """Return a new PyIntObject or PyLongObject based on the string
- value in str, which is interpreted according to the radix in base. If
- pend is non-NULL, *pend will point to the first character in str which
- follows the representation of the number. If base is 0, the radix will be
- determined based on the leading characters of str: if str starts with
- '0x' or '0X', radix 16 will be used; if str starts with '0', radix
- 8 will be used; otherwise radix 10 will be used. If base is not 0, it
- must be between 2 and 36, inclusive. Leading spaces are ignored. If
- there are no digits, ValueError will be raised. If the string represents
- a number too large to be contained within the machine's long int type
- and overflow warnings are being suppressed, a PyLongObject will be
- returned. If overflow warnings are not being suppressed, NULL will be
- returned in this case."""
- raise NotImplementedError
-
@cpython_api([rffi.SIZE_T], PyObject)
def PyInt_FromSize_t(space, ival):
"""Create a new integer object with a value of ival. If the value exceeds
@@ -1813,22 +1687,6 @@
"""
raise NotImplementedError
- at cpython_api([PyObject], rffi.ULONG, error=-1)
-def PyInt_AsUnsignedLongMask(space, io):
- """Will first attempt to cast the object to a PyIntObject or
- PyLongObject, if it is not already one, and then return its value as
- unsigned long. This function does not check for overflow.
- """
- raise NotImplementedError
-
- at cpython_api([PyObject], rffi.LONGLONG, error=-1)
-def PyInt_AsUnsignedLongLongMask(space, io):
- """Will first attempt to cast the object to a PyIntObject or
- PyLongObject, if it is not already one, and then return its value as
- unsigned long long, without checking for overflow.
- """
- raise NotImplementedError
-
@cpython_api([], lltype.Signed, error=CANNOT_FAIL)
def PyInt_GetMax(space, ):
"""
@@ -1855,29 +1713,6 @@
"""
raise NotImplementedError
- at cpython_api([PyObject, Py_ssize_t], PyObject)
-def PyList_GET_ITEM(space, list, i):
- """Macro form of PyList_GetItem() without error checking.
-
- This macro used an int for i. This might require changes in
- your code for properly supporting 64-bit systems."""
- borrow_from()
- raise NotImplementedError
-
- at cpython_api([PyObject, Py_ssize_t, PyObject], lltype.Void)
-def PyList_SET_ITEM(space, list, i, o):
- """Macro form of PyList_SetItem() without error checking. This is
- normally only used to fill in new lists where there is no previous content.
-
- This macro "steals" a reference to item, and, unlike
- PyList_SetItem(), does not discard a reference to any item that
- it being replaced; any reference in list at position i will be
- leaked.
-
- This macro used an int for i. This might require
- changes in your code for properly supporting 64-bit systems."""
- raise NotImplementedError
-
@cpython_api([PyObject, Py_ssize_t, Py_ssize_t], PyObject)
def PyList_GetSlice(space, list, low, high):
"""Return a list of the objects in list containing the objects between low
@@ -1917,30 +1752,6 @@
changes in your code for properly supporting 64-bit systems."""
raise NotImplementedError
- at cpython_api([PyObject, rffi.INTP], lltype.Signed, error=-1)
-def PyLong_AsLongAndOverflow(space, pylong, overflow):
- """Return a C long representation of the contents of
- pylong. If pylong is greater than LONG_MAX or less
- than LONG_MIN, set *overflow to 1 or -1,
- respectively, and return -1; otherwise, set *overflow to
- 0. If any other exception occurs (for example a TypeError or
- MemoryError), then -1 will be returned and *overflow will
- be 0.
- """
- raise NotImplementedError
-
- at cpython_api([PyObject, rffi.INTP], rffi.LONGLONG, error=-1)
-def PyLong_AsLongLongAndOverflow(space, pylong, overflow):
- """Return a C long long representation of the contents of
- pylong. If pylong is greater than PY_LLONG_MAX or less
- than PY_LLONG_MIN, set *overflow to 1 or -1,
- respectively, and return -1; otherwise, set *overflow to
- 0. If any other exception occurs (for example a TypeError or
- MemoryError), then -1 will be returned and *overflow will
- be 0.
- """
- raise NotImplementedError
-
@cpython_api([PyObject], Py_ssize_t)
def PyLong_AsSsize_t(space, pylong):
"""
@@ -1953,20 +1764,6 @@
"""
raise NotImplementedError
- at cpython_api([PyObject], rffi.ULONG, error=-1)
-def PyLong_AsUnsignedLongMask(space, io):
- """Return a C unsigned long from a Python long integer, without checking
- for overflow.
- """
- raise NotImplementedError
-
- at cpython_api([PyObject], rffi.ULONGLONG, error=-1)
-def PyLong_AsUnsignedLongLongMask(space, io):
- """Return a C unsigned long long from a Python long integer, without
- checking for overflow.
- """
- raise NotImplementedError
-
@cpython_api([PyObject, rffi.CCHARP], rffi.INT_real, error=-1)
def PyMapping_DelItemString(space, o, key):
"""Remove the mapping for object key from the object o. Return -1 on
@@ -2398,20 +2195,6 @@
changes in your code for properly supporting 64-bit systems."""
raise NotImplementedError
- at cpython_api([PyObject], Py_ssize_t)
-def PyString_GET_SIZE(space, string):
- """Macro form of PyString_Size() but without error checking.
-
- This macro returned an int type. This might require changes in
- your code for properly supporting 64-bit systems."""
- raise NotImplementedError
-
- at cpython_api([PyObject], rffi.CCHARP, error=CANNOT_FAIL)
-def PyString_AS_STRING(space, string):
- """Macro form of PyString_AsString() but without error checking. Only
- string objects are supported; no Unicode objects should be passed."""
- raise NotImplementedError
-
@cpython_api([PyObjectP], lltype.Void)
def PyString_InternInPlace(space, string):
"""Intern the argument *string in place. The argument must be the address of a
@@ -2590,15 +2373,6 @@
the cleanup function, no Python APIs should be called by func."""
raise NotImplementedError
- at cpython_api([PyObject, Py_ssize_t], PyObject)
-def PyTuple_GET_ITEM(space, p, pos):
- """Like PyTuple_GetItem(), but does no checking of its arguments.
-
- This function used an int type for pos. This might require
- changes in your code for properly supporting 64-bit systems."""
- borrow_from()
- raise NotImplementedError
-
@cpython_api([PyObject, Py_ssize_t, Py_ssize_t], PyObject)
def PyTuple_GetSlice(space, p, low, high):
"""Take a slice of the tuple pointed to by p from low to high and return it
@@ -2608,17 +2382,6 @@
require changes in your code for properly supporting 64-bit systems."""
raise NotImplementedError
- at cpython_api([PyObject, Py_ssize_t, PyObject], lltype.Void)
-def PyTuple_SET_ITEM(space, p, pos, o):
- """Like PyTuple_SetItem(), but does no error checking, and should only be
- used to fill in brand new tuples.
-
- This function "steals" a reference to o.
-
- This function used an int type for pos. This might require
- changes in your code for properly supporting 64-bit systems."""
- raise NotImplementedError
-
@cpython_api([], rffi.INT_real, error=CANNOT_FAIL)
def PyTuple_ClearFreeList(space, ):
"""Clear the free list. Return the total number of freed items.
@@ -2639,12 +2402,6 @@
"""
raise NotImplementedError
- at cpython_api([PyObject, rffi.INT_real], rffi.INT_real, error=CANNOT_FAIL)
-def PyType_HasFeature(space, o, feature):
- """Return true if the type object o sets the feature feature. Type features
- are denoted by single bit flags."""
- raise NotImplementedError
-
@cpython_api([PyObject], rffi.INT_real, error=CANNOT_FAIL)
def PyType_IS_GC(space, o):
"""Return true if the type object includes support for the cycle detector; this
@@ -2701,12 +2458,6 @@
possible. This macro does not raise exceptions."""
raise NotImplementedError
- at cpython_api([PyObject], PyObject)
-def PyUnicode_FromObject(space, obj):
- """Shortcut for PyUnicode_FromEncodedObject(obj, NULL, "strict") which is used
- throughout the interpreter whenever coercion to Unicode is needed."""
- raise NotImplementedError
-
@cpython_api([rffi.CWCHARP, Py_ssize_t, rffi.CCHARP, rffi.CCHARP], PyObject)
def PyUnicode_Encode(space, s, size, encoding, errors):
"""Encode the Py_UNICODE buffer of the given size and return a Python
@@ -3093,12 +2844,6 @@
require changes in your code for properly supporting 64-bit systems."""
raise NotImplementedError
- at cpython_api([PyObject, PyObject], rffi.INT_real, error=-2)
-def PyUnicode_Compare(space, left, right):
- """Compare two strings and return -1, 0, 1 for less than, equal, and greater than,
- respectively."""
- raise NotImplementedError
-
@cpython_api([PyObject, PyObject, rffi.INT_real], PyObject)
def PyUnicode_RichCompare(space, left, right, op):
"""Rich compare two unicode strings and return one of the following:
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/pypy/module/cpyext/test/conftest.py Sun Dec 19 13:11:22 2010 +0100
@@ -0,0 +1,16 @@
+import py
+from pypy.conftest import option, gettestobjspace
+
+def pytest_ignore_collect(path, config):
+ if config.option.runappdirect:
+ return True # "cannot be run by py.test -A"
+ # ensure additional functions are registered
+ import pypy.module.cpyext.test.test_cpyext
+ return False
+
+def pytest_funcarg__space(request):
+ return gettestobjspace(usemodules=['cpyext', 'thread'])
+
+def pytest_funcarg__api(request):
+ return request.cls.api
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/pypy/module/cpyext/test/test_codecs.py Sun Dec 19 13:11:22 2010 +0100
@@ -0,0 +1,14 @@
+# encoding: iso-8859-15
+from pypy.module.cpyext.test.test_api import BaseApiTest
+from pypy.rpython.lltypesystem import rffi, lltype
+
+class TestCodecs(BaseApiTest):
+ def test_incremental(self, space, api):
+ utf8 = rffi.str2charp('utf-8')
+ w_encoder = api.PyCodec_IncrementalEncoder(utf8, None)
+ w_encoded = space.call_method(w_encoder, 'encode', space.wrap(u'späm'))
+ w_decoder = api.PyCodec_IncrementalDecoder(utf8, None)
+ w_decoded = space.call_method(w_decoder, 'decode', w_encoded)
+ assert space.unwrap(w_decoded) == u'späm'
+ rffi.free_charp(utf8)
+
--- a/pypy/module/cpyext/test/test_dictobject.py Sun Dec 19 11:54:23 2010 +0100
+++ b/pypy/module/cpyext/test/test_dictobject.py Sun Dec 19 13:11:22 2010 +0100
@@ -29,6 +29,9 @@
rffi.free_charp(buf)
assert not api.PyErr_Occurred()
+ assert api.PyDict_Contains(d, space.wrap("c"))
+ assert not api.PyDict_Contains(d, space.wrap("z"))
+
assert api.PyDict_DelItem(d, space.wrap("c")) == 0
assert api.PyDict_DelItem(d, space.wrap("name")) < 0
assert api.PyErr_Occurred() is space.w_KeyError
--- a/pypy/module/cpyext/test/test_floatobject.py Sun Dec 19 11:54:23 2010 +0100
+++ b/pypy/module/cpyext/test/test_floatobject.py Sun Dec 19 13:11:22 2010 +0100
@@ -1,4 +1,5 @@
from pypy.module.cpyext.test.test_api import BaseApiTest
+from pypy.module.cpyext.test.test_cpyext import AppTestCpythonExtensionBase
class TestFloatObject(BaseApiTest):
def test_floatobject(self, space, api):
@@ -11,9 +12,24 @@
def test_coerce(self, space, api):
assert space.type(api.PyNumber_Float(space.wrap(3))) is space.w_float
+ assert space.type(api.PyNumber_Float(space.wrap("3"))) is space.w_float
class Coerce(object):
def __float__(self):
return 42.5
assert space.eq_w(api.PyNumber_Float(space.wrap(Coerce())),
space.wrap(42.5))
+
+class AppTestFloatObject(AppTestCpythonExtensionBase):
+ def test_fromstring(self):
+ module = self.import_extension('foo', [
+ ("from_string", "METH_NOARGS",
+ """
+ PyObject* str = PyString_FromString("1234.56");
+ PyObject* res = PyFloat_FromString(str, NULL);
+ Py_DECREF(str);
+ return res;
+ """),
+ ])
+ assert module.from_string() == 1234.56
+ assert type(module.from_string()) is float
--- a/pypy/module/cpyext/test/test_intobject.py Sun Dec 19 11:54:23 2010 +0100
+++ b/pypy/module/cpyext/test/test_intobject.py Sun Dec 19 13:11:22 2010 +0100
@@ -1,4 +1,5 @@
from pypy.module.cpyext.test.test_api import BaseApiTest
+from pypy.module.cpyext.test.test_cpyext import AppTestCpythonExtensionBase
import sys
class TestIntObject(BaseApiTest):
@@ -28,8 +29,24 @@
assert api.PyErr_Occurred() is space.w_ValueError
api.PyErr_Clear()
+ assert (api.PyInt_AsUnsignedLongMask(space.wrap(sys.maxint))
+ == sys.maxint)
+ assert (api.PyInt_AsUnsignedLongMask(space.wrap(10**30))
+ == 10**30 % ((sys.maxint + 1) * 2))
+
def test_coerce(self, space, api):
class Coerce(object):
def __int__(self):
return 42
assert api.PyInt_AsLong(space.wrap(Coerce())) == 42
+
+class AppTestIntObject(AppTestCpythonExtensionBase):
+ def test_fromstring(self):
+ module = self.import_extension('foo', [
+ ("from_string", "METH_NOARGS",
+ """
+ return PyInt_FromString("1234", NULL, 16);
+ """),
+ ])
+ assert module.from_string() == 0x1234
+ assert type(module.from_string()) is int
--- a/pypy/module/cpyext/test/test_longobject.py Sun Dec 19 11:54:23 2010 +0100
+++ b/pypy/module/cpyext/test/test_longobject.py Sun Dec 19 13:11:22 2010 +0100
@@ -64,6 +64,33 @@
assert api.PyErr_Occurred()
api.PyErr_Clear()
+ assert api.PyLong_AsUnsignedLongLongMask(
+ space.wrap(1<<64)) == 0
+
+ def test_as_long_and_overflow(self, space, api):
+ overflow = lltype.malloc(rffi.CArrayPtr(rffi.INT_real).TO, 1, flavor='raw')
+ assert api.PyLong_AsLongAndOverflow(
+ space.wrap(sys.maxint), overflow) == sys.maxint
+ assert api.PyLong_AsLongAndOverflow(
+ space.wrap(-sys.maxint - 2), overflow) == -1
+ assert not api.PyErr_Occurred()
+ assert overflow[0] == -1
+ lltype.free(overflow, flavor='raw')
+
+ def test_as_longlong_and_overflow(self, space, api):
+ overflow = lltype.malloc(rffi.CArrayPtr(rffi.INT_real).TO, 1, flavor='raw')
+ assert api.PyLong_AsLongLongAndOverflow(
+ space.wrap(1<<62), overflow) == 1<<62
+ assert api.PyLong_AsLongLongAndOverflow(
+ space.wrap(1<<63), overflow) == -1
+ assert not api.PyErr_Occurred()
+ assert overflow[0] == 1
+ assert api.PyLong_AsLongLongAndOverflow(
+ space.wrap(-1<<64), overflow) == -1
+ assert not api.PyErr_Occurred()
+ assert overflow[0] == -1
+ lltype.free(overflow, flavor='raw')
+
def test_as_voidptr(self, space, api):
w_l = api.PyLong_FromVoidPtr(lltype.nullptr(rffi.VOIDP.TO))
assert space.unwrap(w_l) == 0L
--- a/pypy/module/cpyext/test/test_methodobject.py Sun Dec 19 11:54:23 2010 +0100
+++ b/pypy/module/cpyext/test/test_methodobject.py Sun Dec 19 13:11:22 2010 +0100
@@ -3,7 +3,8 @@
from pypy.module.cpyext.methodobject import PyMethodDef
from pypy.module.cpyext.api import ApiFunction
from pypy.module.cpyext.pyobject import PyObject, make_ref, Py_DecRef
-from pypy.module.cpyext.methodobject import PyDescr_NewMethod
+from pypy.module.cpyext.methodobject import (
+ PyDescr_NewMethod, PyCFunction_typedef)
from pypy.rpython.lltypesystem import rffi, lltype
class AppTestMethodObject(AppTestCpythonExtensionBase):
@@ -50,6 +51,16 @@
}
'''
),
+ ('isSameFunction', 'METH_O',
+ '''
+ PyCFunction ptr = PyCFunction_GetFunction(args);
+ if (!ptr) return NULL;
+ if (ptr == foo_getarg_O)
+ Py_RETURN_TRUE;
+ else
+ Py_RETURN_FALSE;
+ '''
+ ),
])
assert mod.getarg_O(1) == 1
raises(TypeError, mod.getarg_O)
@@ -64,6 +75,8 @@
assert mod.getarg_OLD(1, 2) == (1, 2)
assert mod.isCFunction(mod.getarg_O) == "getarg_O"
+ assert mod.isSameFunction(mod.getarg_O)
+ raises(TypeError, mod.isSameFunction, 1)
class TestPyCMethodObject(BaseApiTest):
def test_repr(self, space):
@@ -78,7 +91,8 @@
ml = lltype.malloc(PyMethodDef, flavor='raw', zero=True)
namebuf = rffi.str2charp('func')
ml.c_ml_name = namebuf
- ml.c_ml_meth = c_func.get_llhelper(space)
+ ml.c_ml_meth = rffi.cast(PyCFunction_typedef,
+ c_func.get_llhelper(space))
method = PyDescr_NewMethod(space, space.w_str, ml)
assert repr(method).startswith(
--- a/pypy/module/cpyext/typeobject.py Sun Dec 19 11:54:23 2010 +0100
+++ b/pypy/module/cpyext/typeobject.py Sun Dec 19 13:11:22 2010 +0100
@@ -16,10 +16,10 @@
track_reference, RefcountState, borrow_from)
from pypy.interpreter.module import Module
from pypy.module.cpyext import structmemberdefs
-from pypy.module.cpyext.modsupport import convert_method_defs, PyCFunction
+from pypy.module.cpyext.modsupport import convert_method_defs
from pypy.module.cpyext.state import State
from pypy.module.cpyext.methodobject import (
- PyDescr_NewWrapper, PyCFunction_NewEx)
+ PyDescr_NewWrapper, PyCFunction_NewEx, PyCFunction_typedef)
from pypy.module.cpyext.pyobject import Py_IncRef, Py_DecRef, _Py_Dealloc
from pypy.module.cpyext.structmember import PyMember_GetOne, PyMember_SetOne
from pypy.module.cpyext.typeobjectdefs import (
@@ -208,7 +208,7 @@
def setup_new_method_def(space):
ptr = get_new_method_def(space)
- ptr.c_ml_meth = rffi.cast(PyCFunction,
+ ptr.c_ml_meth = rffi.cast(PyCFunction_typedef,
llhelper(tp_new_wrapper.api_func.functype,
tp_new_wrapper.api_func.get_wrapper(space)))
--- a/pypy/module/cpyext/typeobjectdefs.py Sun Dec 19 11:54:23 2010 +0100
+++ b/pypy/module/cpyext/typeobjectdefs.py Sun Dec 19 13:11:22 2010 +0100
@@ -8,7 +8,6 @@
from pypy.module.cpyext.modsupport import PyMethodDef
-PyCFunction = Ptr(FuncType([PyObject, PyObject], PyObject))
P, FT, PyO = Ptr, FuncType, PyObject
PyOPtr = Ptr(lltype.Array(PyO, hints={'nolength': True}))
--- a/pypy/module/cpyext/unicodeobject.py Sun Dec 19 11:54:23 2010 +0100
+++ b/pypy/module/cpyext/unicodeobject.py Sun Dec 19 13:11:22 2010 +0100
@@ -122,7 +122,7 @@
ref_unicode.c_buffer = rffi.unicode2wcharp(u)
return ref_unicode.c_buffer
- at cpython_api([PyObject], rffi.CWCHARP, error=lltype.nullptr(rffi.CWCHARP.TO))
+ at cpython_api([PyObject], rffi.CWCHARP)
def PyUnicode_AsUnicode(space, ref):
"""Return a read-only pointer to the Unicode object's internal Py_UNICODE
buffer, NULL if unicode is not a Unicode object."""
@@ -253,6 +253,15 @@
w_errors = space.w_None
return space.call_method(w_str, 'decode', w_encoding, w_errors)
+ at cpython_api([PyObject], PyObject)
+def PyUnicode_FromObject(space, w_obj):
+ """Shortcut for PyUnicode_FromEncodedObject(obj, NULL, "strict") which is used
+ throughout the interpreter whenever coercion to Unicode is needed."""
+ if space.is_w(space.type(w_obj), space.w_unicode):
+ return w_obj
+ else:
+ return space.call_function(space.w_unicode, w_obj)
+
@cpython_api([PyObject, CONST_STRING, CONST_STRING], PyObject)
def PyUnicode_FromEncodedObject(space, w_obj, encoding, errors):
"""Coerce an encoded object obj to an Unicode object and return a reference with
@@ -287,6 +296,25 @@
space.wrap("decoding Unicode is not supported"))
return space.call_function(w_meth, w_encoding, w_errors)
+ at cpython_api([CONST_STRING], PyObject)
+def PyUnicode_FromString(space, s):
+ """Create a Unicode object from an UTF-8 encoded null-terminated char buffer"""
+ w_str = space.wrap(rffi.charp2str(s))
+ return space.call_method(w_str, 'decode', space.wrap("utf-8"))
+
+ at cpython_api([CONST_STRING, Py_ssize_t], PyObject)
+def PyUnicode_FromStringAndSize(space, s, size):
+ """Create a Unicode Object from the char buffer u. The bytes will be
+ interpreted as being UTF-8 encoded. u may also be NULL which causes the
+ contents to be undefined. It is the user's responsibility to fill in the
+ needed data. The buffer is copied into the new object. If the buffer is not
+ NULL, the return value might be a shared object. Therefore, modification of
+ the resulting Unicode object is only allowed when u is NULL."""
+ if not s:
+ raise NotImplementedError
+ w_str = space.wrap(rffi.charpsize2str(s, size))
+ return space.call_method(w_str, 'decode', space.wrap("utf-8"))
+
@cpython_api([PyObject], PyObject)
def PyUnicode_AsUTF8String(space, w_unicode):
"""Encode a Unicode object using UTF-8 and return the result as Python string
@@ -405,3 +433,10 @@
else:
w_errors = space.w_None
return space.call_method(w_str, 'decode', w_encoding, w_errors)
+
+ at cpython_api([PyObject, PyObject], rffi.INT_real, error=-2)
+def PyUnicode_Compare(space, w_left, w_right):
+ """Compare two strings and return -1, 0, 1 for less than, equal, and greater
+ than, respectively."""
+ return space.int_w(space.cmp(w_left, w_right))
+
--- a/pypy/module/posix/app_posix.py Sun Dec 19 11:54:23 2010 +0100
+++ b/pypy/module/posix/app_posix.py Sun Dec 19 13:11:22 2010 +0100
@@ -95,7 +95,7 @@
def close(self):
import os
- file.close(self)
+ super(popenfile, self).close()
pid = self._childpid
if pid is not None:
self._childpid = None
--- a/pypy/module/posix/test/test_posix_libfile.py Sun Dec 19 11:54:23 2010 +0100
+++ b/pypy/module/posix/test/test_posix_libfile.py Sun Dec 19 13:11:22 2010 +0100
@@ -50,3 +50,18 @@
f.close() # should wait here
end_time = time.time()
assert end_time - start_time >= 1.9
+
+ def test_popen_and_rebind_file_in___builtin__(self):
+ import sys
+ if sys.platform.startswith('win'):
+ skip("unix specific")
+ #
+ import __builtin__
+ posix = self.posix
+ orig_file = file
+ try:
+ f = posix.popen('true')
+ __builtin__.file = lambda x : explode
+ f.close()
+ finally:
+ __builtin__.file = orig_file
--- a/pypy/module/sys/version.py Sun Dec 19 11:54:23 2010 +0100
+++ b/pypy/module/sys/version.py Sun Dec 19 13:11:22 2010 +0100
@@ -6,7 +6,7 @@
#XXX # the release serial 42 is not in range(16)
CPYTHON_VERSION = (2, 5, 2, "beta", 42) #XXX # sync patchlevel.h
-CPYTHON_API_VERSION = 1012 #XXX # sync with include/modsupport.h
+CPYTHON_API_VERSION = 1013 #XXX # sync with include/modsupport.h
PYPY_VERSION = (1, 4, 0, "beta", 0) #XXX # sync patchlevel.h
--- a/pypy/module/sys/vm.py Sun Dec 19 11:54:23 2010 +0100
+++ b/pypy/module/sys/vm.py Sun Dec 19 13:11:22 2010 +0100
@@ -42,19 +42,24 @@
return space.wrap(f)
def setrecursionlimit(space, w_new_limit):
- """DEPRECATED on PyPy. Will issue warning and not work
- """
+ """setrecursionlimit() is ignored (and not needed) on PyPy.
+
+On CPython it would set the maximum number of nested calls that can
+occur before a RuntimeError is raised. On PyPy overflowing the stack
+also causes RuntimeErrors, but the limit is checked at a lower level.
+(The limit is currenty hard-coded at 768 KB, corresponding to roughly
+1480 Python calls on Linux.)"""
new_limit = space.int_w(w_new_limit)
if new_limit <= 0:
raise OperationError(space.w_ValueError,
space.wrap("recursion limit must be positive"))
- # global recursion_limit
- # we need to do it without writing globals.
- space.warn('setrecursionlimit() is ignored (and not needed) on PyPy', space.w_DeprecationWarning)
+ # for now, don't rewrite a warning but silently ignore the
+ # recursion limit.
+ #space.warn('setrecursionlimit() is ignored (and not needed) on PyPy', space.w_RuntimeWarning)
space.sys.recursionlimit = new_limit
def getrecursionlimit(space):
- """DEPRECATED on PyPy. Will issue warning and not work
+ """Return the last value set by setrecursionlimit().
"""
return space.wrap(space.sys.recursionlimit)
--- a/pypy/objspace/std/dictmultiobject.py Sun Dec 19 11:54:23 2010 +0100
+++ b/pypy/objspace/std/dictmultiobject.py Sun Dec 19 13:11:22 2010 +0100
@@ -809,42 +809,6 @@
space.wrap("popitem(): dictionary is empty"))
return space.newtuple([w_key, w_value])
-app = gateway.applevel('''
- def dictrepr(currently_in_repr, d):
- # Now we only handle one implementation of dicts, this one.
- # The fix is to move this to dicttype.py, and do a
- # multimethod lookup mapping str to StdObjSpace.str
- # This cannot happen until multimethods are fixed. See dicttype.py
- dict_id = id(d)
- if dict_id in currently_in_repr:
- return '{...}'
- currently_in_repr[dict_id] = 1
- try:
- items = []
- # XXX for now, we cannot use iteritems() at app-level because
- # we want a reasonable result instead of a RuntimeError
- # even if the dict is mutated by the repr() in the loop.
- for k, v in dict.items(d):
- items.append(repr(k) + ": " + repr(v))
- return "{" + ', '.join(items) + "}"
- finally:
- try:
- del currently_in_repr[dict_id]
- except:
- pass
-''', filename=__file__)
-
-dictrepr = app.interphook("dictrepr")
-
-def repr__DictMulti(space, w_dict):
- if w_dict.length() == 0:
- return space.wrap('{}')
- ec = space.getexecutioncontext()
- w_currently_in_repr = ec._py_repr
- if w_currently_in_repr is None:
- w_currently_in_repr = ec._py_repr = space.newdict()
- return dictrepr(space, w_currently_in_repr, w_dict)
-
# ____________________________________________________________
# Iteration
--- a/pypy/objspace/std/dicttype.py Sun Dec 19 11:54:23 2010 +0100
+++ b/pypy/objspace/std/dicttype.py Sun Dec 19 13:11:22 2010 +0100
@@ -49,10 +49,6 @@
def dict_reversed__ANY(space, w_dict):
raise OperationError(space.w_TypeError, space.wrap('argument to reversed() must be a sequence'))
-#dict_fromkeys = MultiMethod('fromkeys', 2, varargs=True)
-# This can return when multimethods have been fixed
-#dict_str = StdObjSpace.str
-
register_all(vars(), globals())
@gateway.unwrap_spec(ObjSpace, W_Root, W_Root, W_Root)
@@ -60,7 +56,7 @@
from pypy.objspace.std.dictmultiobject import W_DictMultiObject
if w_fill is None:
w_fill = space.w_None
- if w_type is space.w_dict:
+ if space.is_w(w_type, space.w_dict):
w_dict = W_DictMultiObject.allocate_and_init_instance(space, w_type)
for w_key in space.listview(w_keys):
w_dict.setitem(w_key, w_fill)
@@ -71,6 +67,40 @@
return w_dict
+app = gateway.applevel('''
+ def dictrepr(currently_in_repr, d):
+ if len(d) == 0:
+ return "{}"
+ dict_id = id(d)
+ if dict_id in currently_in_repr:
+ return '{...}'
+ currently_in_repr[dict_id] = 1
+ try:
+ items = []
+ # XXX for now, we cannot use iteritems() at app-level because
+ # we want a reasonable result instead of a RuntimeError
+ # even if the dict is mutated by the repr() in the loop.
+ for k, v in dict.items(d):
+ items.append(repr(k) + ": " + repr(v))
+ return "{" + ', '.join(items) + "}"
+ finally:
+ try:
+ del currently_in_repr[dict_id]
+ except:
+ pass
+''', filename=__file__)
+
+dictrepr = app.interphook("dictrepr")
+
+
+def descr_repr(space, w_dict):
+ ec = space.getexecutioncontext()
+ w_currently_in_repr = ec._py_repr
+ if w_currently_in_repr is None:
+ w_currently_in_repr = ec._py_repr = space.newdict()
+ return dictrepr(space, w_currently_in_repr, w_dict)
+
+
# ____________________________________________________________
def descr__new__(space, w_dicttype, __args__):
@@ -95,6 +125,7 @@
[gateway.ObjSpace,
gateway.W_Root,gateway.Arguments]),
__hash__ = no_hash_descr,
+ __repr__ = gateway.interp2app(descr_repr),
fromkeys = gateway.interp2app(descr_fromkeys, as_classmethod=True),
)
dict_typedef.registermethods(globals())
--- a/pypy/objspace/std/test/test_typeobject.py Sun Dec 19 11:54:23 2010 +0100
+++ b/pypy/objspace/std/test/test_typeobject.py Sun Dec 19 13:11:22 2010 +0100
@@ -943,7 +943,7 @@
class AppTestMutableBuiltintypes:
def setup_class(cls):
- cls.space = gettestobjspace(**{"objspace.std.immutable_builtintypes": False})
+ cls.space = gettestobjspace(**{"objspace.std.mutable_builtintypes": True})
def test_del_type_mro(self):
del type.mro
--- a/pypy/objspace/std/typeobject.py Sun Dec 19 11:54:23 2010 +0100
+++ b/pypy/objspace/std/typeobject.py Sun Dec 19 13:11:22 2010 +0100
@@ -134,7 +134,7 @@
def mutated(w_self):
space = w_self.space
- assert w_self.is_heaptype() or not space.config.objspace.std.immutable_builtintypes
+ assert w_self.is_heaptype() or space.config.objspace.std.mutable_builtintypes
if (not space.config.objspace.std.withtypeversion and
not space.config.objspace.std.getattributeshortcut and
not space.config.objspace.std.newshortcut):
@@ -157,8 +157,8 @@
w_subclass.mutated()
def version_tag(w_self):
- if (not we_are_jitted() or w_self.is_heaptype() or not
- w_self.space.config.objspace.std.immutable_builtintypes):
+ if (not we_are_jitted() or w_self.is_heaptype() or
+ w_self.space.config.objspace.std.mutable_builtintypes):
return w_self._version_tag
# heap objects cannot get their version_tag changed
return w_self._pure_version_tag()
@@ -784,7 +784,7 @@
space.set(w_descr, w_type, w_value)
return
- if (space.config.objspace.std.immutable_builtintypes
+ if (not space.config.objspace.std.mutable_builtintypes
and not w_type.is_heaptype()):
msg = "can't set attributes on type object '%s'"
raise operationerrfmt(space.w_TypeError, msg, w_type.name)
@@ -803,7 +803,7 @@
if space.is_data_descr(w_descr):
space.delete(w_descr, w_type)
return
- if (space.config.objspace.std.immutable_builtintypes
+ if (not space.config.objspace.std.mutable_builtintypes
and not w_type.is_heaptype()):
msg = "can't delete attributes on type object '%s'"
raise operationerrfmt(space.w_TypeError, msg, w_type.name)
--- a/pypy/tool/logparser.py Sun Dec 19 11:54:23 2010 +0100
+++ b/pypy/tool/logparser.py Sun Dec 19 13:11:22 2010 +0100
@@ -1,7 +1,7 @@
#! /usr/bin/env python
"""
Syntax:
- python logparser.py <action><logfilename><options...>
+ python logparser.py <action><logfilename><output><options...>
Actions:
draw-time draw a timeline image of the log (format PNG by default)
Repository URL: https://bitbucket.org/pypy/pypy/
--
This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.
More information about the Pypy-commit
mailing list