Commits

Armin Rigo committed 0d95b46

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

Comments (0)

Files changed (5)

rpython/rtyper/llinterp.py

         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. """
         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?")

rpython/rtyper/lltypesystem/rclass.py

 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:
 #          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();
 #      }
 #
                             ('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}))
         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):
                 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)
         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:
         #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)

rpython/rtyper/test/tool.py

         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

rpython/translator/c/src/debug_traceback.c

 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();
 }

rpython/translator/c/src/exception.c

                                  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
 }