[pypy-commit] pypy numpy-record-dtypes: (fijal, agaynor) boilerplate - export string/unicode

fijal noreply at buildbot.pypy.org
Wed Feb 8 22:50:49 CET 2012


Author: Maciej Fijalkowski <fijall at gmail.com>
Branch: numpy-record-dtypes
Changeset: r52259:80adf83f04d7
Date: 2012-02-08 22:40 +0100
http://bitbucket.org/pypy/pypy/changeset/80adf83f04d7/

Log:	(fijal, agaynor) boilerplate - export string/unicode

diff --git a/pypy/module/micronumpy/__init__.py b/pypy/module/micronumpy/__init__.py
--- a/pypy/module/micronumpy/__init__.py
+++ b/pypy/module/micronumpy/__init__.py
@@ -69,8 +69,9 @@
         'intp': 'types.IntP.BoxType',
         'uintp': 'types.UIntP.BoxType',
         'flexible': 'interp_boxes.W_FlexibleBox',
-        #'str_': 'interp_boxes.W_StringBox',
-        #'unicode_': 'interp_boxes.W_UnicodeBox',
+        'character': 'interp_boxes.W_CharacterBox',
+        'str_': 'interp_boxes.W_StringBox',
+        'unicode_': 'interp_boxes.W_UnicodeBox',
         'void': 'interp_boxes.W_VoidBox',
     }
 
diff --git a/pypy/module/micronumpy/interp_boxes.py b/pypy/module/micronumpy/interp_boxes.py
--- a/pypy/module/micronumpy/interp_boxes.py
+++ b/pypy/module/micronumpy/interp_boxes.py
@@ -3,6 +3,8 @@
 from pypy.interpreter.gateway import interp2app
 from pypy.interpreter.typedef import TypeDef
 from pypy.objspace.std.floattype import float_typedef
+from pypy.objspace.std.stringtype import str_typedef
+from pypy.objspace.std.unicodetype import unicode_typedef
 from pypy.objspace.std.inttype import int_typedef
 from pypy.rlib.rarithmetic import LONG_BIT
 from pypy.tool.sourcetools import func_with_new_name
@@ -169,6 +171,14 @@
 class W_VoidBox(W_FlexibleBox):
     pass
 
+class W_CharacterBox(W_FlexibleBox):
+    pass
+
+class W_StringBox(W_CharacterBox):
+    pass
+
+class W_UnicodeBox(W_CharacterBox):
+    pass
 
 W_GenericBox.typedef = TypeDef("generic",
     __module__ = "numpypy",
@@ -300,3 +310,16 @@
 W_VoidBox.typedef = TypeDef("void", W_FlexibleBox.typedef,
     __module__ = "numpypy",
 )
+
+W_CharacterBox.typedef = TypeDef("character", W_FlexibleBox.typedef,
+    __module__ = "numpypy",
+)
+
+W_StringBox.typedef = TypeDef("string_", (str_typedef, W_CharacterBox.typedef),
+    __module__ = "numpypy",
+)
+
+W_UnicodeBox.typedef = TypeDef("unicode_", (unicode_typedef, W_CharacterBox.typedef),
+    __module__ = "numpypy",
+)
+                                          
diff --git a/pypy/module/micronumpy/test/test_dtypes.py b/pypy/module/micronumpy/test/test_dtypes.py
--- a/pypy/module/micronumpy/test/test_dtypes.py
+++ b/pypy/module/micronumpy/test/test_dtypes.py
@@ -440,7 +440,6 @@
                                        numpy.integer, numpy.number,
                                        numpy.generic, object)
         assert numpy.bool_.__mro__ == (numpy.bool_, numpy.generic, object)
-        #assert numpy.str_.__mro__ == 
 
     def test_alternate_constructs(self):
         from _numpypy import dtype
@@ -458,6 +457,12 @@
         from _numpypy import dtype
         assert dtype('i4').alignment == 4
 
+    def test_str_unicode(self):
+        from _numpypy import str_, unicode_, character, flexible, generic
+        
+        assert str_.mro() == [str_, str, basestring, character, flexible, generic, object]
+        assert unicode_.mro() == [unicode_, unicode, basestring, character, flexible, generic, object]
+
 class AppTestRecordDtypes(BaseNumpyAppTest):
     def test_create(self):
         from _numpypy import dtype, void
@@ -476,3 +481,4 @@
         assert d.names == ("x", "y", "z", "value")
         raises(KeyError, 'd["xyz"]')
         raises(KeyError, 'd.fields["xyz"]')
+
diff --git a/pypy/module/micronumpy/types.py b/pypy/module/micronumpy/types.py
--- a/pypy/module/micronumpy/types.py
+++ b/pypy/module/micronumpy/types.py
@@ -603,6 +603,21 @@
     def get_element_size(self):
         return self.size
 
+class BaseStringType(object):
+    _mixin_ = True
+    
+    def __init__(self, size):
+        self.size = size
+
+    def get_element_size(self):
+        return self.size * rffi.sizeof(self.T)
+
+class StringType(BaseType, BaseStringType):
+    T = lltype.Char
+
+class UnicodeType(BaseType, BaseStringType):
+    T = lltype.UniChar
+
 class RecordType(CompositeType):
     pass
 
diff --git a/pypy/rlib/clibffi.py b/pypy/rlib/clibffi.py
--- a/pypy/rlib/clibffi.py
+++ b/pypy/rlib/clibffi.py
@@ -228,6 +228,7 @@
     (rffi.LONGLONG, _signed_type_for(rffi.LONGLONG)),
     (lltype.UniChar, _unsigned_type_for(lltype.UniChar)),
     (lltype.Bool, _unsigned_type_for(lltype.Bool)),
+    (lltype.Char, _signed_type_for(lltype.Char)),
     ]
 
 __float_type_map = [


More information about the pypy-commit mailing list