Author: Manuel Jacob
Branch: refactor-translator
Changeset: r68770:128d10637045
Date: 2014-01-19 21:18 +0100
http://bitbucket.org/pypy/pypy/changeset/128d10637045/
Log: hg merge default
diff --git a/lib_pypy/_ctypes/structure.py b/lib_pypy/_ctypes/structure.py
--- a/lib_pypy/_ctypes/structure.py
+++ b/lib_pypy/_ctypes/structure.py
@@ -2,6 +2,8 @@
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):
@@ -104,8 +106,11 @@
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:
diff --git a/pypy/module/test_lib_pypy/ctypes_tests/test_keepalive.py
b/pypy/module/test_lib_pypy/ctypes_tests/test_keepalive.py
--- a/pypy/module/test_lib_pypy/ctypes_tests/test_keepalive.py
+++ b/pypy/module/test_lib_pypy/ctypes_tests/test_keepalive.py
@@ -31,7 +31,17 @@
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)),
diff --git a/rpython/translator/c/extfunc.py b/rpython/translator/c/extfunc.py
--- a/rpython/translator/c/extfunc.py
+++ b/rpython/translator/c/extfunc.py
@@ -1,19 +1,9 @@
-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
@@ -29,14 +19,13 @@
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
diff --git a/rpython/translator/c/node.py b/rpython/translator/c/node.py
--- a/rpython/translator/c/node.py
+++ b/rpython/translator/c/node.py
@@ -916,15 +916,6 @@
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
diff --git a/rpython/translator/c/src/asm_ppc.c
b/rpython/translator/c/src/asm_ppc.c
deleted file mode 100644
--- a/rpython/translator/c/src/asm_ppc.c
+++ /dev/null
@@ -1,24 +0,0 @@
-#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();
-}
diff --git a/rpython/translator/c/src/asm_ppc.h
b/rpython/translator/c/src/asm_ppc.h
deleted file mode 100644
--- a/rpython/translator/c/src/asm_ppc.h
+++ /dev/null
@@ -1,1 +0,0 @@
-void LL_flush_icache(long base, long size);
diff --git a/rpython/translator/driver.py b/rpython/translator/driver.py
--- a/rpython/translator/driver.py
+++ b/rpython/translator/driver.py
@@ -89,7 +89,7 @@
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")
@@ -119,11 +119,11 @@
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
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit