[pypy-svn] commit/pypy: 26 new changesets
Bitbucket
commits-noreply at bitbucket.org
Fri Dec 17 18:59:48 CET 2010
26 new changesets in pypy:
http://bitbucket.org/pypy/pypy/changeset/65c025e13881/
changeset: r40091:65c025e13881
user: amauryfa
date: 2010-11-05 18:38:17
summary: cpyext: Fix definition for old DL_EXPORT macros
+ unconditionally define HAVE_WCHAR_H
(transplanted from 77f53ce2fe976cd0b34b8d11b34179be10aedd6f)
affected #: 2 files (341 bytes)
--- a/pypy/module/cpyext/include/Python.h Fri Dec 17 15:09:04 2010 +0100
+++ b/pypy/module/cpyext/include/Python.h Fri Nov 05 17:38:17 2010 +0000
@@ -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
--- a/pypy/module/cpyext/include/pyconfig.h Fri Dec 17 15:09:04 2010 +0100
+++ b/pypy/module/cpyext/include/pyconfig.h Fri Nov 05 17:38:17 2010 +0000
@@ -15,6 +15,7 @@
#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
http://bitbucket.org/pypy/pypy/changeset/3fa8fe54dba0/
changeset: r40092:3fa8fe54dba0
user: amauryfa
date: 2010-11-05 19:36:22
summary: A useful symbol for _testcapi
(transplanted from f163b2bce34969485784190454e49db8bd75c9a7)
affected #: 1 file (40 bytes)
--- a/pypy/module/cpyext/api.py Fri Nov 05 17:38:17 2010 +0000
+++ b/pypy/module/cpyext/api.py Fri Nov 05 18:36:22 2010 +0000
@@ -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)
http://bitbucket.org/pypy/pypy/changeset/4edaa71f829b/
changeset: r40093:4edaa71f829b
user: amauryfa
date: 2010-11-06 23:37:15
summary: Reduce duplicated code
(transplanted from 5fed388540ecde4977b133a0f5e8e7f2513f776b)
affected #: 1 file (1.2 KB)
--- a/pypy/module/cpyext/structmember.py Fri Nov 05 18:36:22 2010 +0000
+++ b/pypy/module/cpyext/structmember.py Sat Nov 06 22:37:15 2010 +0000
@@ -9,35 +9,33 @@
from pypy.module.cpyext.stringobject import (PyString_FromString,
PyString_FromStringAndSize)
from pypy.module.cpyext.typeobjectdefs import PyMemberDef
+from pypy.rlib.unroll import unrolling_iterable
+
+integer_converters = unrolling_iterable([
+ (structmemberdefs.T_SHORT, rffi.SHORT, PyInt_AsLong),
+ (structmemberdefs.T_INT, rffi.INT, PyInt_AsLong),
+ (structmemberdefs.T_LONG, rffi.LONG, PyInt_AsLong),
+ (structmemberdefs.T_USHORT, rffi.USHORT, PyInt_AsUnsignedLong),
+ (structmemberdefs.T_UINT, rffi.UINT, PyInt_AsUnsignedLong),
+ (structmemberdefs.T_ULONG, rffi.ULONG, PyInt_AsUnsignedLong),
+ (structmemberdefs.T_BYTE, rffi.UCHAR, PyInt_AsLong),
+ ])
@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, lltype, _ = converter
+ if typ == member_type
+ result = rffi.cast(rffi.CArrayPtr(lltype), addr)
+ w_result = space.wrap(result[0])
+ return w_result
+
+ if member_type == structmemberdefs.T_STRING:
result = rffi.cast(rffi.CCHARPP, addr)
if result[0]:
w_result = PyString_FromString(space, result[0])
@@ -49,16 +47,19 @@
elif member_type == structmemberdefs.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 == structmemberdefs.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"))
@@ -86,35 +87,15 @@
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, lltype, getter = converter
+ if typ == member_type:
+ value = getter(space, w_value)
+ array = rffi.cast(rffi.CarrayPtr(lltype), addr)
+ array[0] = rffi.cast(lltype, value)
+ return 0
+
+ if member_type == structmemberdefs.T_CHAR:
str_value = space.str_w(w_value)
if len(str_value) != 1:
raise OperationError(space.w_TypeError,
http://bitbucket.org/pypy/pypy/changeset/e95793bc0e3d/
changeset: r40094:e95793bc0e3d
user: amauryfa
date: 2010-11-06 23:54:57
summary: Run tests, and fix mistakes
(transplanted from 544b2e8c3b4aacb33f9e1c7bf2fc42cb226f343e)
affected #: 1 file (374 bytes)
--- a/pypy/module/cpyext/structmember.py Sat Nov 06 22:37:15 2010 +0000
+++ b/pypy/module/cpyext/structmember.py Sat Nov 06 22:54:57 2010 +0000
@@ -1,7 +1,7 @@
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
@@ -12,13 +12,13 @@
from pypy.rlib.unroll import unrolling_iterable
integer_converters = unrolling_iterable([
- (structmemberdefs.T_SHORT, rffi.SHORT, PyInt_AsLong),
- (structmemberdefs.T_INT, rffi.INT, PyInt_AsLong),
- (structmemberdefs.T_LONG, rffi.LONG, PyInt_AsLong),
- (structmemberdefs.T_USHORT, rffi.USHORT, PyInt_AsUnsignedLong),
- (structmemberdefs.T_UINT, rffi.UINT, PyInt_AsUnsignedLong),
- (structmemberdefs.T_ULONG, rffi.ULONG, PyInt_AsUnsignedLong),
- (structmemberdefs.T_BYTE, rffi.UCHAR, PyInt_AsLong),
+ (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),
])
@@ -29,25 +29,25 @@
member_type = rffi.cast(lltype.Signed, w_member.c_type)
for converter in integer_converters:
- typ, lltype, _ = converter
- if typ == member_type
- result = rffi.cast(rffi.CArrayPtr(lltype), addr)
+ typ, lltyp, _ = converter
+ if typ == member_type:
+ result = rffi.cast(rffi.CArrayPtr(lltyp), addr)
w_result = space.wrap(result[0])
return w_result
- if member_type == structmemberdefs.T_STRING:
+ 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 == structmemberdefs.T_OBJECT:
+ elif member_type == T_OBJECT:
obj_ptr = rffi.cast(PyObjectP, addr)
if obj_ptr[0]:
w_result = from_ref(space, obj_ptr[0])
@@ -73,37 +73,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"))
for converter in integer_converters:
- typ, lltype, getter = converter
+ typ, lltyp, getter = converter
if typ == member_type:
value = getter(space, w_value)
- array = rffi.cast(rffi.CarrayPtr(lltype), addr)
- array[0] = rffi.cast(lltype, value)
+ array = rffi.cast(rffi.CArrayPtr(lltyp), addr)
+ array[0] = rffi.cast(lltyp, value)
return 0
- if member_type == structmemberdefs.T_CHAR:
+ 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])
http://bitbucket.org/pypy/pypy/changeset/bd9480b2d1ea/
changeset: r40095:bd9480b2d1ea
user: amauryfa
date: 2010-11-07 00:04:14
summary: More types in structmembers
(transplanted from f4f91d4af7c71d40ec5329ea3456ac0188c76022)
affected #: 3 files (618 bytes)
--- a/pypy/module/cpyext/include/structmember.h Sat Nov 06 22:54:57 2010 +0000
+++ b/pypy/module/cpyext/include/structmember.h Sat Nov 06 23:04:14 2010 +0000
@@ -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/structmember.py Sat Nov 06 22:54:57 2010 +0000
+++ b/pypy/module/cpyext/structmember.py Sat Nov 06 23:04:14 2010 +0000
@@ -6,8 +6,11 @@
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
@@ -19,6 +22,12 @@
(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),
])
--- a/pypy/module/cpyext/structmemberdefs.py Sat Nov 06 22:54:57 2010 +0000
+++ b/pypy/module/cpyext/structmemberdefs.py Sat Nov 06 23:04:14 2010 +0000
@@ -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
http://bitbucket.org/pypy/pypy/changeset/dd665acd02c1/
changeset: r40096:dd665acd02c1
user: amauryfa
date: 2010-11-07 00:32:54
summary: cpyext: implement PyLong_AsLongAndOverflow
(transplanted from 530b4cfd30162ce5e05acf9f06c328e0c42de38f)
affected #: 2 files (2.7 KB)
--- a/pypy/module/cpyext/longobject.py Sat Nov 06 23:04:14 2010 +0000
+++ b/pypy/module/cpyext/longobject.py Sat Nov 06 23:32:54 2010 +0000
@@ -62,6 +62,48 @@
raised."""
return rffi.cast(rffi.ULONGLONG, space.r_ulonglong_w(w_long))
+ 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] = 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] = 1
+ else:
+ overflow_ptr[0] = -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] = 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] = 1
+ else:
+ overflow_ptr[0] = -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/test/test_longobject.py Sat Nov 06 23:04:14 2010 +0000
+++ b/pypy/module/cpyext/test/test_longobject.py Sat Nov 06 23:32:54 2010 +0000
@@ -64,6 +64,30 @@
assert api.PyErr_Occurred()
api.PyErr_Clear()
+ def test_as_long_and_overflow(self, space, api):
+ overflow = lltype.malloc(rffi.INTP.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.INTP.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
http://bitbucket.org/pypy/pypy/changeset/4e43c9cb6fac/
changeset: r40097:4e43c9cb6fac
user: amauryfa
date: 2010-11-07 11:03:51
summary: Fix translation
(transplanted from 0a38eb5c960f62250d7684b1ed740b05b4400592)
affected #: 1 file (131 bytes)
--- a/pypy/module/cpyext/structmember.py Sat Nov 06 23:32:54 2010 +0000
+++ b/pypy/module/cpyext/structmember.py Sun Nov 07 10:03:51 2010 +0000
@@ -41,7 +41,10 @@
typ, lltyp, _ = converter
if typ == member_type:
result = rffi.cast(rffi.CArrayPtr(lltyp), addr)
- w_result = space.wrap(result[0])
+ 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:
http://bitbucket.org/pypy/pypy/changeset/00f508cb268c/
changeset: r40098:00f508cb268c
user: amauryfa
date: 2010-11-07 20:48:06
summary: Add constants: PY_LLONG_MAX &co
affected #: 2 files (793 bytes)
--- a/pypy/module/cpyext/include/pyconfig.h Sun Nov 07 10:03:51 2010 +0000
+++ b/pypy/module/cpyext/include/pyconfig.h Sun Nov 07 19:48:06 2010 +0000
@@ -10,7 +10,6 @@
#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
--- a/pypy/module/cpyext/include/pyport.h Sun Nov 07 10:03:51 2010 +0000
+++ b/pypy/module/cpyext/include/pyport.h Sun Nov 07 19:48:06 2010 +0000
@@ -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
http://bitbucket.org/pypy/pypy/changeset/75ef23f19202/
changeset: r40099:75ef23f19202
user: amauryfa
date: 2010-11-07 21:12:14
summary: Fix #include order: should fix definition of PY_LONG_LONG
affected #: 1 file (1 byte)
--- a/pypy/module/cpyext/include/Python.h Sun Nov 07 19:48:06 2010 +0000
+++ b/pypy/module/cpyext/include/Python.h Sun Nov 07 20:12:14 2010 +0000
@@ -80,6 +80,7 @@
#include <pypy_macros.h>
#include "patchlevel.h"
+#include "pyconfig.h"
#include "object.h"
#include "pyport.h"
@@ -92,8 +93,6 @@
#include <locale.h>
#include <ctype.h>
-#include "pyconfig.h"
-
#include "boolobject.h"
#include "floatobject.h"
#include "complexobject.h"
http://bitbucket.org/pypy/pypy/changeset/7fb4b3b3b895/
changeset: r40100:7fb4b3b3b895
user: amauryfa
date: 2010-11-07 21:36:55
summary: Implement PyInt_AsUnsignedLongMask
affected #: 4 files (1.6 KB)
--- a/pypy/module/cpyext/intobject.py Sun Nov 07 20:12:14 2010 +0000
+++ b/pypy/module/cpyext/intobject.py Sun Nov 07 20:36:55 2010 +0000
@@ -3,7 +3,7 @@
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.rlib.rarithmetic import r_uint
PyInt_Check, PyInt_CheckExact = build_type_checkers("Int")
@@ -35,6 +35,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."""
--- a/pypy/module/cpyext/longobject.py Sun Nov 07 20:12:14 2010 +0000
+++ b/pypy/module/cpyext/longobject.py Sun Nov 07 20:36:55 2010 +0000
@@ -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):
"""
--- a/pypy/module/cpyext/stubs.py Sun Nov 07 20:12:14 2010 +0000
+++ b/pypy/module/cpyext/stubs.py Sun Nov 07 20:36:55 2010 +0000
@@ -1813,14 +1813,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
-
@cpython_api([PyObject], rffi.LONGLONG, error=-1)
def PyInt_AsUnsignedLongLongMask(space, io):
"""Will first attempt to cast the object to a PyIntObject or
@@ -1953,13 +1945,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
-
@cpython_api([PyObject], rffi.ULONGLONG, error=-1)
def PyLong_AsUnsignedLongLongMask(space, io):
"""Return a C unsigned long long from a Python long integer, without
--- a/pypy/module/cpyext/test/test_intobject.py Sun Nov 07 20:12:14 2010 +0000
+++ b/pypy/module/cpyext/test/test_intobject.py Sun Nov 07 20:36:55 2010 +0000
@@ -28,6 +28,11 @@
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):
http://bitbucket.org/pypy/pypy/changeset/e8c3eb932d94/
changeset: r40101:e8c3eb932d94
user: amauryfa
date: 2010-11-07 21:53:42
summary: Add PyUnicode_FromString, PyUnicode_FromStringAndSize
affected #: 2 files (1.3 KB)
--- a/pypy/module/cpyext/unicodeobject.py Sun Nov 07 20:36:55 2010 +0000
+++ b/pypy/module/cpyext/unicodeobject.py Sun Nov 07 20:53:42 2010 +0000
@@ -287,6 +287,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
http://bitbucket.org/pypy/pypy/changeset/9c5019dd2ff9/
changeset: r40102:9c5019dd2ff9
user: amauryfa
date: 2010-11-07 22:37:11
summary: Add PyCodec_IncrementalEncoder, PyCodec_IncrementalDecoder
affected #: 3 files (1.6 KB)
--- a/pypy/module/cpyext/__init__.py Sun Nov 07 20:53:42 2010 +0000
+++ b/pypy/module/cpyext/__init__.py Sun Nov 07 21:37:11 2010 +0000
@@ -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()
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/pypy/module/cpyext/codecs.py Sun Nov 07 21:37:11 2010 +0000
@@ -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")
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/pypy/module/cpyext/test/test_codecs.py Sun Nov 07 21:37:11 2010 +0000
@@ -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)
+
http://bitbucket.org/pypy/pypy/changeset/b687972216f2/
changeset: r40103:b687972216f2
user: amauryfa
date: 2010-11-07 23:12:47
summary: PyUnicode_FromObject, PyUnicode_Compare
affected #: 3 files (1.5 KB)
--- a/pypy/module/cpyext/stubs.py Sun Nov 07 21:37:11 2010 +0000
+++ b/pypy/module/cpyext/stubs.py Sun Nov 07 22:12:47 2010 +0000
@@ -2686,12 +2686,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
@@ -3078,12 +3072,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:
--- a/pypy/module/cpyext/unicodeobject.py Sun Nov 07 21:37:11 2010 +0000
+++ b/pypy/module/cpyext/unicodeobject.py Sun Nov 07 22:12:47 2010 +0000
@@ -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
@@ -424,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))
+
http://bitbucket.org/pypy/pypy/changeset/8ad11bbf7b9b/
changeset: r40104:8ad11bbf7b9b
user: amauryfa
date: 2010-11-07 23:21:06
summary: Add PyExceptionClass_Check
affected #: 1 file (203 bytes)
--- a/pypy/module/cpyext/include/pyerrors.h Sun Nov 07 22:12:47 2010 +0000
+++ b/pypy/module/cpyext/include/pyerrors.h Sun Nov 07 22:21:06 2010 +0000
@@ -7,6 +7,10 @@
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_Format(PyObject *exception, const char *format, ...);
http://bitbucket.org/pypy/pypy/changeset/e57e3212e281/
changeset: r40105:e57e3212e281
user: amauryfa
date: 2010-11-07 23:26:38
summary: PyErr_NewExceptionWithDoc, copied from CPython.
affected #: 3 files (900 bytes)
--- a/pypy/module/cpyext/api.py Sun Nov 07 22:21:06 2010 +0000
+++ b/pypy/module/cpyext/api.py Sun Nov 07 22:26:38 2010 +0000
@@ -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',
--- a/pypy/module/cpyext/include/pyerrors.h Sun Nov 07 22:21:06 2010 +0000
+++ b/pypy/module/cpyext/include/pyerrors.h Sun Nov 07 22:26:38 2010 +0000
@@ -12,6 +12,7 @@
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/src/pyerrors.c Sun Nov 07 22:21:06 2010 +0000
+++ b/pypy/module/cpyext/src/pyerrors.c Sun Nov 07 22:26:38 2010 +0000
@@ -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;
+}
+
+
http://bitbucket.org/pypy/pypy/changeset/10d84112e09d/
changeset: r40106:10d84112e09d
user: amauryfa
date: 2010-11-07 23:42:54
summary: PyTraceBack_Print, don't know how to test it :-(
affected #: 1 file (420 bytes)
--- a/pypy/module/cpyext/pyerrors.py Sun Nov 07 22:26:38 2010 +0000
+++ b/pypy/module/cpyext/pyerrors.py Sun Nov 07 22:42:54 2010 +0000
@@ -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
http://bitbucket.org/pypy/pypy/changeset/592e37f9153e/
changeset: r40107:592e37f9153e
user: amauryfa
date: 2010-11-07 23:46:41
summary: Typo
affected #: 1 file (1 byte)
--- a/pypy/module/cpyext/pyerrors.py Sun Nov 07 22:42:54 2010 +0000
+++ b/pypy/module/cpyext/pyerrors.py Sun Nov 07 22:46:41 2010 +0000
@@ -276,7 +276,7 @@
"""Alias for PyErr_PrintEx(1)."""
PyErr_PrintEx(space, 1)
- at cpython_api([PyObject, PyObject], rffi.INT_real, error=-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'))
http://bitbucket.org/pypy/pypy/changeset/124206164e43/
changeset: r40108:124206164e43
user: amauryfa
date: 2010-11-08 00:12:46
summary: Add a dummy PyGC_Head structure
affected #: 1 file (121 bytes)
--- a/pypy/module/cpyext/include/object.h Sun Nov 07 22:46:41 2010 +0000
+++ b/pypy/module/cpyext/include/object.h Sun Nov 07 23:12:46 2010 +0000
@@ -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
http://bitbucket.org/pypy/pypy/changeset/db985d308b1e/
changeset: r40109:db985d308b1e
user: amauryfa
date: 2010-11-08 18:10:19
summary: Add PyLong_AsUnsignedLongLongMask, and remove most "#if 0" in getargs.c
affected #: 3 files (1.1 KB)
--- a/pypy/module/cpyext/longobject.py Sun Nov 07 23:12:46 2010 +0000
+++ b/pypy/module/cpyext/longobject.py Mon Nov 08 17:10:19 2010 +0000
@@ -70,6 +70,15 @@
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()
+
@cpython_api([PyObject, rffi.CArrayPtr(rffi.INT_real)], lltype.Signed,
error=-1)
def PyLong_AsLongAndOverflow(space, w_long, overflow_ptr):
--- a/pypy/module/cpyext/src/getargs.c Sun Nov 07 23:12:46 2010 +0000
+++ b/pypy/module/cpyext/src/getargs.c Mon Nov 08 17:10:19 2010 +0000
@@ -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/test/test_longobject.py Sun Nov 07 23:12:46 2010 +0000
+++ b/pypy/module/cpyext/test/test_longobject.py Mon Nov 08 17:10:19 2010 +0000
@@ -64,8 +64,11 @@
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.INTP.TO, 1, flavor='raw')
+ 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(
@@ -75,7 +78,7 @@
lltype.free(overflow, flavor='raw')
def test_as_longlong_and_overflow(self, space, api):
- overflow = lltype.malloc(rffi.INTP.TO, 1, flavor='raw')
+ 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(
http://bitbucket.org/pypy/pypy/changeset/dc3131665c21/
changeset: r40110:dc3131665c21
user: amauryfa
date: 2010-11-09 19:43:52
summary: This function is now implemented
affected #: 1 file (327 bytes)
--- a/pypy/module/cpyext/stubs.py Mon Nov 08 17:10:19 2010 +0000
+++ b/pypy/module/cpyext/stubs.py Tue Nov 09 18:43:52 2010 +0000
@@ -1813,14 +1813,6 @@
"""
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, ):
"""
http://bitbucket.org/pypy/pypy/changeset/682d3cc5d656/
changeset: r40111:682d3cc5d656
user: amauryfa
date: 2010-12-03 17:00:35
summary: Add PyDict_Contains
affected #: 3 files (824 bytes)
--- a/pypy/module/cpyext/dictobject.py Tue Nov 09 18:43:52 2010 +0000
+++ b/pypy/module/cpyext/dictobject.py Fri Dec 03 16:00:35 2010 +0000
@@ -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/stubs.py Tue Nov 09 18:43:52 2010 +0000
+++ b/pypy/module/cpyext/stubs.py Fri Dec 03 16:00:35 2010 +0000
@@ -627,14 +627,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
--- a/pypy/module/cpyext/test/test_dictobject.py Tue Nov 09 18:43:52 2010 +0000
+++ b/pypy/module/cpyext/test/test_dictobject.py Fri Dec 03 16:00:35 2010 +0000
@@ -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
http://bitbucket.org/pypy/pypy/changeset/e096a913c660/
changeset: r40112:e096a913c660
user: amauryfa
date: 2010-12-03 17:56:20
summary: Implement PyCFunction_GetFunction().
Works only with functions defined in extension modules, not with pypy built-in functions!
affected #: 7 files (865 bytes)
--- a/pypy/module/cpyext/api.py Fri Dec 03 16:00:35 2010 +0000
+++ b/pypy/module/cpyext/api.py Fri Dec 03 16:56:20 2010 +0000
@@ -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
--- a/pypy/module/cpyext/complexobject.py Fri Dec 03 16:00:35 2010 +0000
+++ b/pypy/module/cpyext/complexobject.py Fri Dec 03 16:56:20 2010 +0000
@@ -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/methodobject.py Fri Dec 03 16:00:35 2010 +0000
+++ b/pypy/module/cpyext/methodobject.py Fri Dec 03 16:56:20 2010 +0000
@@ -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 Fri Dec 03 16:00:35 2010 +0000
+++ b/pypy/module/cpyext/modsupport.py Fri Dec 03 16:56:20 2010 +0000
@@ -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/test/test_methodobject.py Fri Dec 03 16:00:35 2010 +0000
+++ b/pypy/module/cpyext/test/test_methodobject.py Fri Dec 03 16:56:20 2010 +0000
@@ -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 Fri Dec 03 16:00:35 2010 +0000
+++ b/pypy/module/cpyext/typeobject.py Fri Dec 03 16:56:20 2010 +0000
@@ -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 Fri Dec 03 16:00:35 2010 +0000
+++ b/pypy/module/cpyext/typeobjectdefs.py Fri Dec 03 16:56:20 2010 +0000
@@ -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}))
http://bitbucket.org/pypy/pypy/changeset/45539a11cfd3/
changeset: r40113:45539a11cfd3
user: amauryfa
date: 2010-12-03 17:58:57
summary: "error=nullptr" is now the default for pointer results
affected #: 3 files (128 bytes)
--- a/pypy/module/cpyext/cdatetime.py Fri Dec 03 16:56:20 2010 +0000
+++ b/pypy/module/cpyext/cdatetime.py Fri Dec 03 16:58:57 2010 +0000
@@ -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)
--- a/pypy/module/cpyext/object.py Fri Dec 03 16:56:20 2010 +0000
+++ b/pypy/module/cpyext/object.py Fri Dec 03 16:58:57 2010 +0000
@@ -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/unicodeobject.py Fri Dec 03 16:56:20 2010 +0000
+++ b/pypy/module/cpyext/unicodeobject.py Fri Dec 03 16:58:57 2010 +0000
@@ -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."""
http://bitbucket.org/pypy/pypy/changeset/cf6e85d4ad42/
changeset: r40114:cf6e85d4ad42
user: amauryfa
date: 2010-12-03 18:08:27
summary: Remove from stubs.py already implemented functions
affected #: 1 file (7.5 KB)
--- a/pypy/module/cpyext/stubs.py Fri Dec 03 16:58:57 2010 +0000
+++ b/pypy/module/cpyext/stubs.py Fri Dec 03 17:08:27 2010 +0000
@@ -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
@@ -708,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, ):
"""
@@ -740,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
@@ -1016,22 +950,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."""
@@ -1050,18 +968,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):
"""
@@ -1831,29 +1737,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
@@ -1893,30 +1776,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):
"""
@@ -1929,13 +1788,6 @@
"""
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
@@ -2367,20 +2219,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
@@ -2559,15 +2397,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
@@ -2577,17 +2406,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.
@@ -2608,12 +2426,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
http://bitbucket.org/pypy/pypy/changeset/af35f9d8f9b7/
changeset: r40115:af35f9d8f9b7
user: amauryfa
date: 2010-12-03 18:54:41
summary: PyFloat_FromString, PyInt_FromString
affected #: 5 files (4.0 KB)
--- a/pypy/module/cpyext/floatobject.py Fri Dec 03 17:08:27 2010 +0000
+++ b/pypy/module/cpyext/floatobject.py Fri Dec 03 17:54:41 2010 +0000
@@ -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/intobject.py Fri Dec 03 17:08:27 2010 +0000
+++ b/pypy/module/cpyext/intobject.py Fri Dec 03 17:54:41 2010 +0000
@@ -1,8 +1,9 @@
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")
@@ -72,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/stubs.py Fri Dec 03 17:08:27 2010 +0000
+++ b/pypy/module/cpyext/stubs.py Fri Dec 03 17:54:41 2010 +0000
@@ -805,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
@@ -1687,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
--- a/pypy/module/cpyext/test/test_floatobject.py Fri Dec 03 17:08:27 2010 +0000
+++ b/pypy/module/cpyext/test/test_floatobject.py Fri Dec 03 17:54:41 2010 +0000
@@ -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 Fri Dec 03 17:08:27 2010 +0000
+++ b/pypy/module/cpyext/test/test_intobject.py Fri Dec 03 17:54:41 2010 +0000
@@ -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):
@@ -38,3 +39,14 @@
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
http://bitbucket.org/pypy/pypy/changeset/9588e2ce73ae/
changeset: r40116:9588e2ce73ae
user: amauryfa
date: 2010-11-07 00:42:23
summary: These INT/Signed casts will drive me nuts.
affected #: 1 file (156 bytes)
--- a/pypy/module/cpyext/longobject.py Fri Dec 03 17:54:41 2010 +0000
+++ b/pypy/module/cpyext/longobject.py Sat Nov 06 23:42:23 2010 +0000
@@ -88,16 +88,16 @@
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] = 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] = 1
+ overflow_ptr[0] = rffi.cast(rffi.INT_real, 1)
else:
- overflow_ptr[0] = -1
+ overflow_ptr[0] = rffi.cast(rffi.INT_real, -1)
return -1
@cpython_api([PyObject, rffi.CArrayPtr(rffi.INT_real)], rffi.LONGLONG,
@@ -109,16 +109,16 @@
-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] = 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] = 1
+ overflow_ptr[0] = rffi.cast(rffi.INT_real, 1)
else:
- overflow_ptr[0] = -1
+ overflow_ptr[0] = rffi.cast(rffi.INT_real, -1)
return -1
@cpython_api([lltype.Float], PyObject)
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