Partial revert of 1001, use builtin unicode type.
authorRobert Bradshaw <robertwb@math.washington.edu>
Thu, 14 Aug 2008 09:21:30 +0000 (02:21 -0700)
committerRobert Bradshaw <robertwb@math.washington.edu>
Thu, 14 Aug 2008 09:21:30 +0000 (02:21 -0700)
Cython/Compiler/Builtin.py
Cython/Compiler/ExprNodes.py
Cython/Compiler/PyrexTypes.py
Cython/Compiler/Symtab.py

index 94106760107c2197615a6b11fc56b9c8f8a83572..3c468fe005401c52b44e670c8486e632aae7da4c 100644 (file)
@@ -180,9 +180,10 @@ def init_builtins():
     init_builtin_funcs()
     init_builtin_types()
     init_builtin_structs()
-    global list_type, tuple_type, dict_type
+    global list_type, tuple_type, dict_type, unicode_type
     list_type  = builtin_scope.lookup('list').type
     tuple_type = builtin_scope.lookup('tuple').type
     dict_type  = builtin_scope.lookup('dict').type
+    unicode_type = builtin_scope.lookup('unicode').type
 
 init_builtins()
index 1557084fdf11880e593cd6ef5182239ebfafc609..9ab4d66478aa23ccbafd93a99578ed3ba700e7ad 100644 (file)
@@ -10,7 +10,7 @@ import Naming
 from Nodes import Node
 import PyrexTypes
 from PyrexTypes import py_object_type, c_long_type, typecast, error_type
-from Builtin import list_type, tuple_type, dict_type
+from Builtin import list_type, tuple_type, dict_type, unicode_type
 import Symtab
 import Options
 from Annotate import AnnotationItem
@@ -740,7 +740,7 @@ class StringNode(ConstNode):
 class UnicodeNode(PyConstNode):
     #  entry   Symtab.Entry
 
-    type = PyrexTypes.c_unicode_type
+    type = unicode_type
 
     def analyse_types(self, env):
         self.entry = env.add_string_const(self.value)
index 3c645331c13deed5ea7724e5a912fea8d887ca0d..46df500f737761a488d7ce7dd4a196121b2cad1e 100644 (file)
@@ -1003,6 +1003,19 @@ class CStringType:
         return '"%s"' % Utils.escape_byte_string(value)
 
 
+class CUTF8CharArrayType(CStringType, CArrayType):
+    #  C 'char []' type.
+    
+    parsetuple_format = "s"
+    pymemberdef_typecode = "T_STRING_INPLACE"
+    is_unicode = 1
+    
+    to_py_function = "PyUnicode_DecodeUTF8"
+    exception_value = "NULL"
+    
+    def __init__(self, size):
+        CArrayType.__init__(self, c_char_type, size)
+
 class CCharArrayType(CStringType, CArrayType):
     #  C 'char []' type.
     
@@ -1023,29 +1036,6 @@ class CCharPtrType(CStringType, CPtrType):
         CPtrType.__init__(self, c_char_type)
 
 
-class UnicodeType(BuiltinObjectType):
-    #  The Python unicode type.
-
-    is_string = 1
-    is_unicode = 1
-    
-    parsetuple_format = "U"
-
-    def __init__(self):
-        BuiltinObjectType.__init__(self, "unicode", "PyUnicodeObject")
-
-    def literal_code(self, value):
-        assert isinstance(value, str)
-        return '"%s"' % Utils.escape_byte_string(value)
-
-    def declaration_code(self, entity_code, 
-            for_display = 0, dll_linkage = None, pyrex = 0):
-        if pyrex or for_display:
-            return self.base_declaration_code(self.name, entity_code)
-        else:
-            return "%s %s[]" % (public_decl("char", dll_linkage), entity_code)
-
-
 class ErrorType(PyrexType):
     # Used to prevent propagation of error messages.
     
@@ -1111,8 +1101,8 @@ c_longdouble_type =  CFloatType(8, typestring="g")
 
 c_null_ptr_type =     CNullPtrType(c_void_type)
 c_char_array_type =   CCharArrayType(None)
-c_unicode_type =      UnicodeType()
 c_char_ptr_type =     CCharPtrType()
+c_utf8_char_array_type = CUTF8CharArrayType(None)
 c_char_ptr_ptr_type = CPtrType(c_char_ptr_type)
 c_py_ssize_t_ptr_type =  CPtrType(c_py_ssize_t_type)
 c_int_ptr_type =      CPtrType(c_int_type)
index b60b504a4c24d6b25e98c99fefe7d30f4fe07063..5c6de05319da000d7115bbf66d540ac0c66f1c65 100644 (file)
@@ -505,7 +505,7 @@ class Scope:
         else:
             cname = self.new_const_cname()
         if value.is_unicode:
-            c_type = PyrexTypes.c_unicode_type
+            c_type = PyrexTypes.c_utf8_char_array_type
             value = value.utf8encode()
         else:
             c_type = PyrexTypes.c_char_array_type