[pypy-commit] pypy default: Retype the field "name" on the base object RPython class to be a regular

arigo noreply at buildbot.pypy.org
Wed Jul 9 17:48:05 CEST 2014


Author: Armin Rigo <arigo at tunes.org>
Branch: 
Changeset: r72400:0d95b46fffc3
Date: 2014-07-09 17:46 +0200
http://bitbucket.org/pypy/pypy/changeset/0d95b46fffc3/

Log:	Retype the field "name" on the base object RPython class to be a
	regular rstr.STR instead of some null-terminated Array(Char).

diff --git a/rpython/rtyper/llinterp.py b/rpython/rtyper/llinterp.py
--- a/rpython/rtyper/llinterp.py
+++ b/rpython/rtyper/llinterp.py
@@ -42,7 +42,7 @@
         return ': '.join([str(x) for x in self.args])
 
 def type_name(etype):
-    return ''.join(etype.name).rstrip('\x00')
+    return ''.join(etype.name.chars)
 
 class LLInterpreter(object):
     """ low level interpreter working with concrete values. """
@@ -145,7 +145,7 @@
         assert isinstance(exc, LLException)
         klass, inst = exc.args[0], exc.args[1]
         for cls in enumerate_exceptions_top_down():
-            if "".join(klass.name).rstrip("\0") == cls.__name__:
+            if "".join(klass.name.chars) == cls.__name__:
                 return cls
         raise ValueError("couldn't match exception, maybe it"
                       " has RPython attributes like OSError?")
diff --git a/rpython/rtyper/lltypesystem/rclass.py b/rpython/rtyper/lltypesystem/rclass.py
--- a/rpython/rtyper/lltypesystem/rclass.py
+++ b/rpython/rtyper/lltypesystem/rclass.py
@@ -22,6 +22,7 @@
 from rpython.rlib import objectmodel
 from rpython.tool.identity_dict import identity_dict
 from rpython.rtyper.lltypesystem.lloperation import llop
+from rpython.rtyper.lltypesystem import rstr
 
 #
 #  There is one "vtable" per user class, with the following structure:
@@ -32,7 +33,7 @@
 #          RuntimeTypeInfo * rtti;
 #          Signed subclassrange_min;  //this is also the id of the class itself
 #          Signed subclassrange_max;
-#          array { char } * name;
+#          RPyString * name;
 #          struct object * instantiate();
 #      }
 #
@@ -68,7 +69,7 @@
                             ('subclassrange_min', Signed),
                             ('subclassrange_max', Signed),
                             ('rtti', Ptr(RuntimeTypeInfo)),
-                            ('name', Ptr(Array(Char))),
+                            ('name', Ptr(rstr.STR)),
                             ('hash', Signed),
                             ('instantiate', Ptr(FuncType([], OBJECTPTR))),
                             hints = {'immutable': True}))
@@ -89,13 +90,6 @@
         vtable = vtable.super
     return vtable
 
-def alloc_array_name(name):
-    p = malloc(Array(Char), len(name)+1, immortal=True)
-    for i in range(len(name)):
-        p[i] = name[i]
-    p[len(name)] = '\x00'
-    return p
-
 
 class ClassRepr(AbstractClassRepr):
     def __init__(self, rtyper, classdef):
@@ -203,7 +197,7 @@
                 name = 'object'
             else:
                 name = rsubcls.classdef.shortname
-            vtable.name = alloc_array_name(name)
+            vtable.name = rstr.string_repr.convert_const(name)
             if hasattr(rsubcls.classdef, 'my_instantiate_graph'):
                 graph = rsubcls.classdef.my_instantiate_graph
                 vtable.instantiate = self.rtyper.getcallable(graph)
@@ -579,7 +573,6 @@
         return hop.genop('ptr_nonzero', [vinst], resulttype=Bool)
 
     def ll_str(self, i): # doesn't work for non-gc classes!
-        from rpython.rtyper.lltypesystem import rstr
         from rpython.rtyper.lltypesystem.ll_str import ll_int2hex
         from rpython.rlib.rarithmetic import r_uint
         if not i:
@@ -590,14 +583,8 @@
         #uid = r_uint(cast_ptr_to_int(i))
         uid = r_uint(llop.gc_id(lltype.Signed, i))
         #
-        nameLen = len(instance.typeptr.name)
-        nameString = rstr.mallocstr(nameLen-1)
-        i = 0
-        while i < nameLen - 1:
-            nameString.chars[i] = instance.typeptr.name[i]
-            i += 1
         res =                        rstr.instance_str_prefix
-        res = rstr.ll_strconcat(res, nameString)
+        res = rstr.ll_strconcat(res, instance.typeptr.name)
         res = rstr.ll_strconcat(res, rstr.instance_str_infix)
         res = rstr.ll_strconcat(res, ll_int2hex(uid, False))
         res = rstr.ll_strconcat(res, rstr.instance_str_suffix)
diff --git a/rpython/rtyper/test/tool.py b/rpython/rtyper/test/tool.py
--- a/rpython/rtyper/test/tool.py
+++ b/rpython/rtyper/test/tool.py
@@ -68,7 +68,7 @@
         return fnptr._obj._callable
 
     def class_name(self, value):
-        return "".join(value.super.typeptr.name)[:-1]
+        return ''.join(value.super.typeptr.name.chars)
 
     def read_attr(self, value, attr_name):
         value = value._obj
diff --git a/rpython/translator/c/src/debug_traceback.c b/rpython/translator/c/src/debug_traceback.c
--- a/rpython/translator/c/src/debug_traceback.c
+++ b/rpython/translator/c/src/debug_traceback.c
@@ -66,7 +66,8 @@
 void pypy_debug_catch_fatal_exception(void)
 {
   pypy_debug_traceback_print();
-  fprintf(stderr, "Fatal RPython error: %s\n",
-          RPyFetchExceptionType()->ov_name->items);
+  fprintf(stderr, "Fatal RPython error: %.*s\n",
+          (int)(RPyFetchExceptionType()->ov_name->rs_chars.length),
+          RPyFetchExceptionType()->ov_name->rs_chars.items);
   abort();
 }
diff --git a/rpython/translator/c/src/exception.c b/rpython/translator/c/src/exception.c
--- a/rpython/translator/c/src/exception.c
+++ b/rpython/translator/c/src/exception.c
@@ -16,8 +16,9 @@
                                  long lineno, const char *functionname)
 {
 #ifdef DO_LOG_EXC
-  fprintf(stderr, "%s %s: %s:%ld %s\n", msg,
-          RPyFetchExceptionType()->ov_name->items,
+  fprintf(stderr, "%s %.*s: %s:%ld %s\n", msg,
+          (int)(RPyFetchExceptionType()->ov_name->rs_chars.length),
+          RPyFetchExceptionType()->ov_name->rs_chars.items,
           filename, lineno, functionname);
 #endif
 }


More information about the pypy-commit mailing list