Commits

Manuel Jacob  committed 128d106 Merge

hg merge default

  • Participants
  • Parent commits e22c2e7, 681802e
  • Branches refactor-translator

Comments (0)

Files changed (7)

File lib_pypy/_ctypes/structure.py

 import _rawffi
 from _ctypes.basics import _CData, _CDataMeta, keepalive_key,\
      store_reference, ensure_objects, CArgObject
+from _ctypes.array import Array
+from _ctypes.pointer import _Pointer
 import inspect
 
 def names_and_fields(self, _fields_, superclass, anonymous_fields=None):
     def __set__(self, obj, value):
         fieldtype = self.ctype
         cobj = fieldtype.from_param(value)
-        if ensure_objects(cobj) is not None:
-            key = keepalive_key(self.num)
+        key = keepalive_key(self.num)
+        if issubclass(fieldtype, _Pointer) and isinstance(cobj, Array):
+            # if our value is an Array we need the whole thing alive
+            store_reference(obj, key, cobj)
+        elif ensure_objects(cobj) is not None:
             store_reference(obj, key, cobj._objects)
         arg = cobj._get_buffer_value()
         if fieldtype._fficompositesize is not None:

File pypy/module/test_lib_pypy/ctypes_tests/test_keepalive.py

         assert p._objects == {}
         assert len(x._objects) == 1
         assert x._objects['0'] is p._objects
-        
+
+    def test_simple_structure_and_pointer_with_array(self):
+        class X(Structure):
+            _fields_ = [('array', POINTER(c_int))]
+
+        x = X()
+        a = (c_int * 3)(1, 2, 3)
+        assert x._objects is None
+        x.array = a
+        assert x._objects['0'] is a
+
     def test_structure_with_pointers(self):
         class X(Structure):
             _fields_ = [('x', POINTER(c_int)),

File rpython/translator/c/extfunc.py

-import types
 from rpython.annotator import model as annmodel
 from rpython.flowspace.model import FunctionGraph
 from rpython.rtyper.lltypesystem import lltype
+from rpython.rtyper.lltypesystem.rstr import STR
 from rpython.translator.c.support import cdecl
-from rpython.rtyper.lltypesystem.rstr import STR, mallocstr
-from rpython.rtyper.lltypesystem import rstr
-from rpython.rtyper.lltypesystem import rlist
 
-# table of functions hand-written in src/ll_*.h
-# Note about *.im_func: The annotator and the rtyper expect direct
-# references to functions, so we cannot insert classmethods here.
-
-EXTERNALS = {'LL_flush_icache': 'LL_flush_icache'}
-
-#______________________________________________________
 
 def predeclare_common_types(db, rtyper):
     # Common types
             return frags[0]
 
     for func, funcobj in db.externalfuncs.items():
-        c_name = EXTERNALS[func]
         # construct a define LL_NEED_<modname> to make it possible to isolate in-development externals and headers
-        modname = module_name(c_name)
+        modname = module_name(func)
         if modname not in modules:
             modules[modname] = True
             yield 'LL_NEED_%s' % modname.upper(), 1
         funcptr = funcobj._as_ptr()
-        yield c_name, funcptr
+        yield func, funcptr
 
 def predeclare_exception_data(db, rtyper):
     # Exception-related types and constants

File rpython/translator/c/node.py

             return sandbox_stub(fnobj, db)
         db.externalfuncs[fnobj._external_name] = fnobj
         return []
-    elif fnobj._callable in extfunc.EXTERNALS:
-        # -- deprecated case --
-        # 'fnobj' is one of the ll_xyz() functions with the suggested_primitive
-        # flag in rpython.rtyper.module.*.  The corresponding C wrappers are
-        # written by hand in src/ll_*.h, and declared in extfunc.EXTERNALS.
-        if sandbox and not fnobj._name.startswith('ll_stack_'): # XXX!!! Temporary
-            return sandbox_stub(fnobj, db)
-        db.externalfuncs[fnobj._callable] = fnobj
-        return []
     elif hasattr(fnobj, 'graph'):
         if sandbox and sandbox != "if_external":
             # apply the sandbox transformation

File rpython/translator/c/src/asm_ppc.c

-#include "src/asm_ppc.h"
-
-#define __dcbst(base, index)    \
-  __asm__ ("dcbst %0, %1" : /*no result*/ : "b%" (index), "r" (base) : "memory")
-#define __icbi(base, index)    \
-  __asm__ ("icbi %0, %1" : /*no result*/ : "b%" (index), "r" (base) : "memory")
-#define __sync() __asm__ volatile ("sync")
-#define __isync()       \
-  __asm__ volatile ("isync")
-
-void
-LL_flush_icache(long base, long size)
-{
-	long i;
-
-	for (i = 0; i < size; i += 32){
-		__dcbst(base, i);
-	}
-	__sync();
-	for (i = 0; i < size; i += 32){
-		__icbi(base, i);
-	}
-	__isync();
-}

File rpython/translator/c/src/asm_ppc.h

-void LL_flush_icache(long base, long size);

File rpython/translator/driver.py

             targetdir = cbuilder.targetdir
             fname = dump_static_data_info(self.driver.log, database, targetdir)
             dstname = self.driver.compute_exe_name() + '.staticdata.info'
-            shutil.copy(str(fname), str(dstname))
+            shutil_copy(str(fname), str(dstname))
             self.driver.log.info('Static data info written to %s' % dstname)
 
     @taskdef("Compiling c source")
             newexename = self.driver.compute_exe_name()
             if sys.platform == 'win32':
                 newexename = newexename.new(ext='exe')
-            shutil.copy(str(exename), str(newexename))
+            shutil_copy(str(exename), str(newexename))
             if self.cbuilder.shared_library_name is not None:
                 soname = self.cbuilder.shared_library_name
                 newsoname = newexename.new(basename=soname.basename)
-                shutil.copy(str(soname), str(newsoname))
+                shutil_copy(str(soname), str(newsoname))
                 self.driver.log.info("copied: %s" % (newsoname,))
                 if sys.platform == 'win32':
                     # the import library is named python27.lib, according