[pypy-svn] r13213 - in pypy: branch/translator-without-old-genc/c dist/pypy/rpython
arigo at codespeak.net
arigo at codespeak.net
Thu Jun 9 08:51:11 CEST 2005
Author: arigo
Date: Thu Jun 9 08:51:08 2005
New Revision: 13213
Modified:
pypy/branch/translator-without-old-genc/c/g_support.h
pypy/dist/pypy/rpython/rstr.py
Log:
Conversions rstring -> PyStringObject.
Starts to become hackish. Didn't figure out how to write the reverse
conversion. Needs some redesign...
Modified: pypy/branch/translator-without-old-genc/c/g_support.h
==============================================================================
--- pypy/branch/translator-without-old-genc/c/g_support.h (original)
+++ pypy/branch/translator-without-old-genc/c/g_support.h Thu Jun 9 08:51:08 2005
@@ -367,3 +367,6 @@
Py_INCREF(o);
return PyTuple_SetItem(tuple, index, o);
}
+
+#define PyString_FromStringAndSize_Hack(s, size) \
+ PyString_FromStringAndSize((char*)(s), size)
Modified: pypy/dist/pypy/rpython/rstr.py
==============================================================================
--- pypy/dist/pypy/rpython/rstr.py (original)
+++ pypy/dist/pypy/rpython/rstr.py Thu Jun 9 08:51:08 2005
@@ -5,6 +5,7 @@
from pypy.rpython.rmodel import Repr, TyperError, IntegerRepr
from pypy.rpython.rmodel import StringRepr, CharRepr, inputconst
from pypy.rpython.rarithmetic import intmask
+from pypy.rpython.robject import PyObjRepr, pyobj_repr
# ____________________________________________________________
#
@@ -124,6 +125,28 @@
string_repr = StringRepr()
char_repr = CharRepr()
+#
+# _________________________ Conversions _________________________
+
+##class __extend__(pairtype(PyObjRepr, StringRepr)):
+## def convert_from_to((r_from, r_to), v, llops):
+## XXX
+
+class __extend__(pairtype(StringRepr, PyObjRepr)):
+ def convert_from_to((r_from, r_to), v, llops):
+ v = llops.convertvar(v, r_from, string_repr)
+ cchars = inputconst(Void, "chars")
+ v_chars = llops.genop('getsubstruct', [v, cchars],
+ resulttype=Ptr(STR.chars))
+ v_size = llops.genop('getarraysize', [v_chars],
+ resulttype=Signed)
+ czero = inputconst(Signed, 0)
+ v_char0ptr = llops.genop('getarrayitem', [v_chars, czero],
+ resulttype=Ptr(STR.chars.OF))
+ return llops.gencapicall('PyString_FromStringAndSize_Hack',
+ [v_char0ptr, v_size],
+ resulttype=pyobj_repr)
+
# ____________________________________________________________
#
# Low-level methods. These can be run for testing, but are meant to
More information about the Pypy-commit
mailing list