[pypy-svn] r45735 - in pypy/branch/pypy-more-rtti-inprogress/rpython: lltypesystem lltypesystem/test module

fijal at codespeak.net fijal at codespeak.net
Thu Aug 16 17:14:03 CEST 2007


Author: fijal
Date: Thu Aug 16 17:14:03 2007
New Revision: 45735

Modified:
   pypy/branch/pypy-more-rtti-inprogress/rpython/lltypesystem/rffi.py
   pypy/branch/pypy-more-rtti-inprogress/rpython/lltypesystem/test/test_ll2ctypes.py
   pypy/branch/pypy-more-rtti-inprogress/rpython/lltypesystem/test/test_rffi.py
   pypy/branch/pypy-more-rtti-inprogress/rpython/module/ll_os.py
   pypy/branch/pypy-more-rtti-inprogress/rpython/module/ll_os_stat.py
   pypy/branch/pypy-more-rtti-inprogress/rpython/module/ll_termios.py
Log:
Rename CXxx to CXxxPtr and make Cxx return xx (CStruct now
returns a struct, not a pointer to this and so on)


Modified: pypy/branch/pypy-more-rtti-inprogress/rpython/lltypesystem/rffi.py
==============================================================================
--- pypy/branch/pypy-more-rtti-inprogress/rpython/lltypesystem/rffi.py	(original)
+++ pypy/branch/pypy-more-rtti-inprogress/rpython/lltypesystem/rffi.py	Thu Aug 16 17:14:03 2007
@@ -94,7 +94,16 @@
     # Hack: prefix all attribute names with 'c_' to cope with names starting
     # with '_'.  The genc backend removes the 'c_' prefixes...
     c_fields = [('c_' + key, value) for key, value in fields]
-    return lltype.Ptr(lltype.Struct(name, *c_fields, **kwds))
+    return lltype.Struct(name, *c_fields, **kwds)
+
+def CStructPtr(*args, **kwds):
+    return lltype.Ptr(CStruct(*args, **kwds))
+
+#def CArray(field):
+#    return lltype.Array(field, hints={'nolength':True})
+
+#def CArrayPtr(field):
+#    return lltype.Ptr(CArray(fld))
 
 def COpaque(name, hints=None, **kwds):
     if hints is None:
@@ -109,7 +118,10 @@
             result.append(size)
         return result[0]
     hints['getsize'] = lazy_getsize
-    return lltype.Ptr(lltype.OpaqueType(name, hints))
+    return lltype.OpaqueType(name, hints)
+
+def COpaquePtr(*args, **kwds):
+    return lltype.Ptr(COpaque(*args, **kwds))
 
 def CExternVariable(TYPE, name):
     """Return a pair of functions - a getter and a setter - to access

Modified: pypy/branch/pypy-more-rtti-inprogress/rpython/lltypesystem/test/test_ll2ctypes.py
==============================================================================
--- pypy/branch/pypy-more-rtti-inprogress/rpython/lltypesystem/test/test_ll2ctypes.py	(original)
+++ pypy/branch/pypy-more-rtti-inprogress/rpython/lltypesystem/test/test_ll2ctypes.py	Thu Aug 16 17:14:03 2007
@@ -228,8 +228,8 @@
 
     def test_opaque_obj(self):
         includes = ['sys/time.h', 'time.h']
-        TIMEVALP = rffi.COpaque('struct timeval', includes=includes)
-        TIMEZONEP = rffi.COpaque('struct timezone', includes=includes)
+        TIMEVALP = rffi.COpaquePtr('struct timeval', includes=includes)
+        TIMEZONEP = rffi.COpaquePtr('struct timezone', includes=includes)
         gettimeofday = rffi.llexternal('gettimeofday', [TIMEVALP, TIMEZONEP],
                                        rffi.INT, includes=includes)
         ll_timevalp = lltype.malloc(TIMEVALP.TO, flavor='raw')

Modified: pypy/branch/pypy-more-rtti-inprogress/rpython/lltypesystem/test/test_rffi.py
==============================================================================
--- pypy/branch/pypy-more-rtti-inprogress/rpython/lltypesystem/test/test_rffi.py	(original)
+++ pypy/branch/pypy-more-rtti-inprogress/rpython/lltypesystem/test/test_rffi.py	Thu Aug 16 17:14:03 2007
@@ -125,7 +125,7 @@
       return (z->one + z->three);
     }
     """
-    TP = CStruct('xx', ('one', Signed), ('two', Char), ('three', Signed))
+    TP = CStructPtr('xx', ('one', Signed), ('two', Char), ('three', Signed))
 
     c_file = udir.join("structxx.c")
     c_file.write(c_source)
@@ -228,7 +228,7 @@
     h_file = udir.join("opaque.h")
     h_file.write(h_source)
 
-    STUFFP = COpaque('struct stuff', includes=['opaque.h'],
+    STUFFP = COpaquePtr('struct stuff', includes=['opaque.h'],
                      include_dirs=[str(udir)])
 
     ll_get = llexternal('get', [STUFFP], lltype.Char, includes=['opaque.h'],
@@ -248,9 +248,25 @@
         import ctypes
     except ImportError:
         py.test.skip("Cannot test without ctypes")
-    from pypy.rpython.lltypesystem import ll2ctypes
-    ll2ctypes._setup_ctypes_cache()
-    for ll, ctp in ll2ctypes._ctypes_cache.items():
+    cache = {
+        lltype.Signed:   ctypes.c_long,
+        lltype.Unsigned: ctypes.c_ulong,
+        lltype.Char:     ctypes.c_ubyte,
+        DOUBLE:     ctypes.c_double,
+        SIGNEDCHAR: ctypes.c_byte,
+        UCHAR:      ctypes.c_ubyte,
+        SHORT:      ctypes.c_short,
+        USHORT:     ctypes.c_ushort,
+        INT:        ctypes.c_int,
+        UINT:       ctypes.c_uint,
+        LONG:       ctypes.c_long,
+        ULONG:      ctypes.c_ulong,
+        LONGLONG:   ctypes.c_longlong,
+        ULONGLONG:  ctypes.c_ulonglong,
+        SIZE_T:     ctypes.c_size_t,
+        }
+
+    for ll, ctp in cache.items():
         assert sizeof(ll) == ctypes.sizeof(ctp)
     assert not size_and_sign(lltype.Signed)[1]
     assert not size_and_sign(lltype.Char)[1]

Modified: pypy/branch/pypy-more-rtti-inprogress/rpython/module/ll_os.py
==============================================================================
--- pypy/branch/pypy-more-rtti-inprogress/rpython/module/ll_os.py	(original)
+++ pypy/branch/pypy-more-rtti-inprogress/rpython/module/ll_os.py	Thu Aug 16 17:14:03 2007
@@ -104,8 +104,8 @@
     @registering(os.utime)
     def register_os_utime(self):
         TIME_T = rffi.INT    # XXX do the right thing
-        UTIMEBUFP = rffi.CStruct('utimbuf', ('actime', TIME_T),
-                                 ('modtime', TIME_T))
+        UTIMEBUFP = rffi.CStructPtr('utimbuf', ('actime', TIME_T),
+                                    ('modtime', TIME_T))
 
         # XXX sys/types.h is not portable at all
         os_utime = rffi.llexternal('utime', [rffi.CCHARP, UTIMEBUFP],
@@ -187,7 +187,7 @@
                       ('version', UTCHARP),
                       ('machine', UTCHARP),
                       ('domainname', UTCHARP)]
-            UTSNAMEP = rffi.CStruct('utsname', *fields)
+            UTSNAMEP = rffi.CStructPtr('utsname', *fields)
     
             os_uname = rffi.llexternal('uname', [UTSNAMEP], rffi.INT,
                                        includes=['sys/utsname.h'])
@@ -485,9 +485,9 @@
             XXX   # FindFirstFile, FindNextFile
         else:
             INCL = ['sys/types.h', 'dirent.h']
-            DIRP = rffi.COpaque('DIR', includes=INCL)
+            DIRP = rffi.COpaquePtr('DIR', includes=INCL)
             NAME_MAX = platform.intdefined('NAME_MAX', includes=INCL)
-            DIRENTP = rffi.CStruct('dirent',
+            DIRENTP = rffi.CStructPtr('dirent',
                 ('d_name', lltype.FixedSizeArray(lltype.Char, NAME_MAX+1)),
                                    )
             # XXX so far, DIRENTP cannot be handled by ll2ctypes because

Modified: pypy/branch/pypy-more-rtti-inprogress/rpython/module/ll_os_stat.py
==============================================================================
--- pypy/branch/pypy-more-rtti-inprogress/rpython/module/ll_os_stat.py	(original)
+++ pypy/branch/pypy-more-rtti-inprogress/rpython/module/ll_os_stat.py	Thu Aug 16 17:14:03 2007
@@ -20,9 +20,9 @@
 if 0:  #sys.platform.startswith('linux2'):
     # XXX assume the tv_nsec way of accessing the sub-second timestamps
     # XXX also assume, as in Linux, that it's in a 'struct timespec'
-    TIMESPEC = rffi.CStruct('timespec',
-                            ('tv_sec', lltype.Signed),
-                            ('tv_nsec', lltype.Signed))
+    TIMESPEC = rffi.CStructPtr('timespec',
+                               ('tv_sec', lltype.Signed),
+                               ('tv_nsec', lltype.Signed))
     ModTime = rffi.DOUBLE
 else:
     # XXX add support for more platforms
@@ -120,7 +120,7 @@
 else:
     _name_struct_stat = 'stat'
     INCLUDES = ['sys/types.h', 'sys/stat.h', 'unistd.h']
-STRUCT_STAT = rffi.CStruct(_name_struct_stat, *LL_STAT_FIELDS)
+STRUCT_STAT = rffi.CStructPtr(_name_struct_stat, *LL_STAT_FIELDS)
 
 
 def build_stat_result(st):

Modified: pypy/branch/pypy-more-rtti-inprogress/rpython/module/ll_termios.py
==============================================================================
--- pypy/branch/pypy-more-rtti-inprogress/rpython/module/ll_termios.py	(original)
+++ pypy/branch/pypy-more-rtti-inprogress/rpython/module/ll_termios.py	Thu Aug 16 17:14:03 2007
@@ -29,9 +29,9 @@
 
 termios.error.__init__ = termios_error_init
 
-TERMIOSP = rffi.CStruct('termios', ('c_iflag', TCFLAG_T), ('c_oflag', TCFLAG_T),
-                        ('c_cflag', TCFLAG_T), ('c_lflag', TCFLAG_T),
-                        ('c_cc', lltype.FixedSizeArray(CC_T, NCCS)))
+TERMIOSP = rffi.CStructPtr('termios', ('c_iflag', TCFLAG_T), ('c_oflag', TCFLAG_T),
+                           ('c_cflag', TCFLAG_T), ('c_lflag', TCFLAG_T),
+                           ('c_cc', lltype.FixedSizeArray(CC_T, NCCS)))
 
 def c_external(name, args, result):
     return rffi.llexternal(name, args, result, includes=includes)



More information about the Pypy-commit mailing list