Author: Manuel Jacob
Branch: refactor-str-types
Changeset: r65795:d0e72051a49f
Date: 2013-07-29 16:53 +0200
http://bitbucket.org/pypy/pypy/changeset/d0e72051a49f/

Log:    Fix marshalling of string types.

diff --git a/pypy/objspace/std/marshal_impl.py 
b/pypy/objspace/std/marshal_impl.py
--- a/pypy/objspace/std/marshal_impl.py
+++ b/pypy/objspace/std/marshal_impl.py
@@ -251,11 +251,11 @@
 def PySTRING_CHECK_INTERNED(w_str):
     return False
 
-def marshal_w__Bytes(space, w_str, m):
-    # using the fastest possible access method here
-    # that does not touch the internal representation,
-    # which might change (array of bytes?)
-    s = w_str.unwrap(space)
+def marshal_bytes(space, w_str, m):
+    if not isinstance(w_str, W_BytesObject):
+        raise_exception(space, "unmarshallable object")
+
+    s = space.str_w(w_str)
     if m.version >= 1 and PySTRING_CHECK_INTERNED(w_str):
         # we use a native rtyper stringdict for speed
         idx = m.stringtable.get(s, -1)
@@ -267,10 +267,11 @@
             m.atom_str(TYPE_INTERNED, s)
     else:
         m.atom_str(TYPE_STRING, s)
+handled_by_any.append(('str', marshal_bytes))
 
-def unmarshal_String(space, u, tc):
+def unmarshal_bytes(space, u, tc):
     return space.wrap(u.get_str())
-register(TYPE_STRING, unmarshal_String)
+register(TYPE_STRING, unmarshal_bytes)
 
 def unmarshal_interned(space, u, tc):
     w_ret = space.wrap(u.get_str())
@@ -410,13 +411,16 @@
     return space.wrap(code)
 register(TYPE_CODE, unmarshal_pycode)
 
-def marshal_w__Unicode(space, w_unicode, m):
+def marshal_unicode(space, w_unicode, m):
+    if not isinstance(w_unicode, W_UnicodeObject):
+        raise_exception(space, "unmarshallable object")
     s = unicodehelper.encode_utf8(space, space.unicode_w(w_unicode))
     m.atom_str(TYPE_UNICODE, s)
+handled_by_any.append(('unicode', marshal_unicode))
 
-def unmarshal_Unicode(space, u, tc):
+def unmarshal_unicode(space, u, tc):
     return space.wrap(unicodehelper.decode_utf8(space, u.get_str()))
-register(TYPE_UNICODE, unmarshal_Unicode)
+register(TYPE_UNICODE, unmarshal_unicode)
 
 app = gateway.applevel(r'''
     def tuple_to_set(datalist, frozen=False):
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to