[pypy-svn] r73314 - in pypy/branch/cpython-extension/pypy/module/cpyext: . include test
fijal at codespeak.net
fijal at codespeak.net
Sat Apr 3 01:23:54 CEST 2010
Author: fijal
Date: Sat Apr 3 01:23:52 2010
New Revision: 73314
Modified:
pypy/branch/cpython-extension/pypy/module/cpyext/include/stringobject.c
pypy/branch/cpython-extension/pypy/module/cpyext/include/stringobject.h
pypy/branch/cpython-extension/pypy/module/cpyext/stringobject.py
pypy/branch/cpython-extension/pypy/module/cpyext/test/test_cpyext.py
pypy/branch/cpython-extension/pypy/module/cpyext/test/test_stringobject.py
Log:
Write down a test for PyString_FromFormatV, fails for irrelevant reasons
(I think)
Modified: pypy/branch/cpython-extension/pypy/module/cpyext/include/stringobject.c
==============================================================================
--- pypy/branch/cpython-extension/pypy/module/cpyext/include/stringobject.c (original)
+++ pypy/branch/cpython-extension/pypy/module/cpyext/include/stringobject.c Sat Apr 3 01:23:52 2010
@@ -2,7 +2,7 @@
#include "Python.h"
PyObject *
-PyString_FromFormatV(const char *format, va_list vargs)
+PyString_FromFormatV(char *format, va_list vargs)
{
va_list count;
Py_ssize_t n = 0;
Modified: pypy/branch/cpython-extension/pypy/module/cpyext/include/stringobject.h
==============================================================================
--- pypy/branch/cpython-extension/pypy/module/cpyext/include/stringobject.h (original)
+++ pypy/branch/cpython-extension/pypy/module/cpyext/include/stringobject.h Sat Apr 3 01:23:52 2010
@@ -15,8 +15,7 @@
Py_ssize_t size;
} PyStringObject;
-PyObject *
-PyString_FromFormatV(const char *format, va_list vargs);
+PyObject *PyString_FromFormatV(char *format, va_list vargs);
#ifdef __cplusplus
}
Modified: pypy/branch/cpython-extension/pypy/module/cpyext/stringobject.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/module/cpyext/stringobject.py (original)
+++ pypy/branch/cpython-extension/pypy/module/cpyext/stringobject.py Sat Apr 3 01:23:52 2010
@@ -51,7 +51,7 @@
return space.int_w(space.len(w_obj))
@cpython_api([PyObjectP, Py_ssize_t], rffi.INT_real, error=-1)
-def _PyString_Resize(space, string, newsize):
+def _PyString_Resize(space, w_string, newsize):
"""A way to resize a string object even though it is "immutable". Only use this to
build up a brand new string object; don't use this if the string may already be
known in other parts of the code. It is an error to call this function if the
@@ -64,4 +64,5 @@
This function used an int type for newsize. This might
require changes in your code for properly supporting 64-bit systems."""
- raise NotImplementedError
+ import pdb
+ pdb.set_trace()
Modified: pypy/branch/cpython-extension/pypy/module/cpyext/test/test_cpyext.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/module/cpyext/test/test_cpyext.py (original)
+++ pypy/branch/cpython-extension/pypy/module/cpyext/test/test_cpyext.py Sat Apr 3 01:23:52 2010
@@ -87,7 +87,7 @@
self.space.sys.get('modules'),
self.space.wrap(name))
- def import_extension(self, modname, functions):
+ def import_extension(self, modname, functions, prologue=""):
methods_table = []
codes = []
@@ -103,7 +103,7 @@
""" % (cfuncname, code)
codes.append(func_code)
- body = "\n".join(codes) + """
+ body = prologue + "\n".join(codes) + """
static PyMethodDef methods[] = {
%s
{ NULL }
Modified: pypy/branch/cpython-extension/pypy/module/cpyext/test/test_stringobject.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/module/cpyext/test/test_stringobject.py (original)
+++ pypy/branch/cpython-extension/pypy/module/cpyext/test/test_stringobject.py Sat Apr 3 01:23:52 2010
@@ -96,15 +96,34 @@
s = module.getstring()
assert s == 'test'
+ def test_py_string_as_string(self):
+ module = self.import_extension('foo', [
+ ("string_as_string", "METH_VARARGS",
+ '''
+ return PyString_FromStringAndSize(PyString_AsString(
+ PyTuple_GetItem(args, 0)), 4);
+ '''
+ )])
+ assert module.string_as_string("huheduwe") == "huhe"
+
def test_format_v(self):
- skip("unsupported yet, think how to fak va_list")
module = self.import_extension('foo', [
("test_string_format_v", "METH_VARARGS",
'''
- return PyString_FromFormatV("bla %d ble %s",
+ return helper("bla %d ble %s\\n",
PyInt_AsLong(PyTuple_GetItem(args, 0)),
PyString_AsString(PyTuple_GetItem(args, 1)));
'''
)
- ])
- pass
+ ], prologue='''
+ PyObject* helper(char* fmt, ...)
+ {
+ va_list va;
+ va_start(va, fmt);
+ PyObject* res = PyString_FromFormatV(fmt, va);
+ va_end(va);
+ return res;
+ }
+ ''')
+ res = module.test_string_format_v(1, "xyz")
+ print res
More information about the Pypy-commit
mailing list