[pypy-commit] pypy default: ARMv4 doesn't have BLX. Add support for older ARM

2013-10-06 Thread stefanor
Author: Stefano Rivera 
Branch: 
Changeset: r67161:f1e9c4f357e1
Date: 2013-10-06 09:49 +0200
http://bitbucket.org/pypy/pypy/changeset/f1e9c4f357e1/

Log:ARMv4 doesn't have BLX. Add support for older ARM

diff --git a/rpython/translator/c/src/stacklet/switch_arm_gcc.h 
b/rpython/translator/c/src/stacklet/switch_arm_gcc.h
--- a/rpython/translator/c/src/stacklet/switch_arm_gcc.h
+++ b/rpython/translator/c/src/stacklet/switch_arm_gcc.h
@@ -1,3 +1,10 @@
+#if __ARM_ARCH__ >= 5
+# define call_reg(x) "blx " #x "\n"
+#elif defined (__ARM_ARCH_4T__)
+# define call_reg(x) "mov lr, pc ; bx " #x "\n"
+#else
+# define call_reg(x) "mov lr, pc ; mov pc, " #x "\n"
+#endif
 
 static void __attribute__((optimize("O3"))) *slp_switch(void 
*(*save_state)(void*, void*),
 void *(*restore_state)(void*, void*),
@@ -11,7 +18,7 @@
 "mov r5, %[extra]\n"
 "mov r0, sp\n" /* arg 1: current (old) stack pointer */
 "mov r1, r5\n" /* arg 2: extra   */
-"blx r3\n" /* call save_state()  */
+call_reg(r3)   /* call save_state()  */
 
 /* skip the rest if the return value is null */
 "cmp r0, #0\n"
@@ -23,7 +30,7 @@
stack is not restored yet.  It contains only garbage here. */
 "mov r1, r5\n" /* arg 2: extra   */
/* arg 1: current (new) 
stack pointer is already in r0*/
-"blx r4\n" /* call restore_state()   */
+call_reg(r4)   /* call restore_state()   */
 
 /* The stack's content is now restored. */
 "zero:\n"
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: Add an assert that seems to fail in issue1619

2013-10-06 Thread arigo
Author: Armin Rigo 
Branch: 
Changeset: r67162:7e05f0998a32
Date: 2013-10-06 10:45 +0200
http://bitbucket.org/pypy/pypy/changeset/7e05f0998a32/

Log:Add an assert that seems to fail in issue1619

diff --git a/rpython/jit/metainterp/resume.py b/rpython/jit/metainterp/resume.py
--- a/rpython/jit/metainterp/resume.py
+++ b/rpython/jit/metainterp/resume.py
@@ -783,6 +783,7 @@
 v = self.virtuals_cache.get_int(index)
 if not v:
 v = self.rd_virtuals[index]
+ll_assert(bool(v), "resume.py: null rd_virtuals[index]")
 assert v.is_about_raw and isinstance(v, VRawBufferStateInfo)
 v = v.allocate_int(self, index)
 ll_assert(v == self.virtuals_cache.get_int(index), "resume.py: bad 
cache")
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy fileops2: (fijal, arigo) work on fileops

2013-10-06 Thread fijal
Author: Maciej Fijalkowski 
Branch: fileops2
Changeset: r67163:7c6969e0bd84
Date: 2013-10-06 10:51 +0200
http://bitbucket.org/pypy/pypy/changeset/7c6969e0bd84/

Log:(fijal, arigo) work on fileops

diff --git a/rpython/flowspace/specialcase.py b/rpython/flowspace/specialcase.py
--- a/rpython/flowspace/specialcase.py
+++ b/rpython/flowspace/specialcase.py
@@ -1,3 +1,4 @@
+import os
 from rpython.flowspace.model import Constant, const
 
 SPECIAL_CASES = {}
@@ -37,6 +38,18 @@
 return space.frame.do_operation('simple_call', const(isinstance),
 w_instance, w_type)
 
+@register_flow_sc(open)
+def sc_open(space, *args_w):
+from rpython.rlib.rfile import create_file
+
+return space.frame.do_operation("simple_call", const(create_file), *args_w)
+
+@register_flow_sc(os.tmpfile)
+def sc_os_tmpfile(space):
+from rpython.rlib.rfile import create_temp_rfile
+
+return space.frame.do_operation("simple_call", const(create_temp_rfile))
+
 # _
 # a simplified version of the basic printing routines, for RPython programs
 class StdOutBuffer:
diff --git a/rpython/rlib/rfile.py b/rpython/rlib/rfile.py
--- a/rpython/rlib/rfile.py
+++ b/rpython/rlib/rfile.py
@@ -1,55 +1,158 @@
 
-""" This file makes open() and friends RPython
+""" This file makes open() and friends RPython. Note that RFile should not
+be used directly and instead it's magically appearing each time you call
+python builtin open()
 """
 
 import os
-from rpython.annotator.model import SomeObject, SomeString, SomeInteger
-from rpython.rtyper.extregistry import ExtRegistryEntry
-from rpython.rtyper.extfunc import register_external
+from rpython.rtyper.lltypesystem import rffi, lltype
+from rpython.translator.tool.cbuild import ExternalCompilationInfo
+from rpython.rlib.rarithmetic import r_uint, intmask
+from rpython.rlib import rposix
+from rpython.rlib.rstring import StringBuilder
 
-class SomeFile(SomeObject):
-def method_write(self, s_arg):
-assert isinstance(s_arg, SomeString)
+eci = ExternalCompilationInfo(includes=['stdio.h'])
 
-def method_read(self, s_arg=None):
-if s_arg is not None:
-assert isinstance(s_arg, SomeInteger)
-return SomeString(can_be_None=False)
+def llexternal(*args):
+return rffi.llexternal(*args, compilation_info=eci)
 
-def method_close(self):
-pass
+FILE = lltype.Struct('FILE') # opaque type maybe
 
-def method_seek(self, s_arg, s_whence=None):
-assert isinstance(s_arg, SomeInteger)
-if s_whence is not None:
-assert isinstance(s_whence, SomeInteger)
+c_open = llexternal('fopen', [rffi.CCHARP, rffi.CCHARP], lltype.Ptr(FILE))
+c_close = llexternal('fclose', [lltype.Ptr(FILE)], rffi.INT)
+c_write = llexternal('fwrite', [rffi.CCHARP, rffi.SIZE_T, rffi.SIZE_T,
+ lltype.Ptr(FILE)], rffi.SIZE_T)
+c_read = llexternal('fread', [rffi.CCHARP, rffi.SIZE_T, rffi.SIZE_T,
+   lltype.Ptr(FILE)], rffi.SIZE_T)
+c_feof = llexternal('feof', [lltype.Ptr(FILE)], rffi.INT)
+c_ferror = llexternal('ferror', [lltype.Ptr(FILE)], rffi.INT)
+c_clearerror = llexternal('clearerr', [lltype.Ptr(FILE)], lltype.Void)
+c_fseek = llexternal('fseek', [lltype.Ptr(FILE), rffi.LONG, rffi.INT],
+  rffi.INT)
+c_tmpfile = llexternal('tmpfile', [], lltype.Ptr(FILE))
+c_fileno = llexternal('fileno', [lltype.Ptr(FILE)], rffi.INT)
+c_ftell = llexternal('ftell', [lltype.Ptr(FILE)], lltype.Signed)
+c_fflush = llexternal('fflush', [lltype.Ptr(FILE)], lltype.Signed)
 
-def rtyper_makekey(self):
-return self.__class__,
+BASE_BUF_SIZE = 4096
 
-def rtyper_makerepr(self, rtyper):
-from rpython.rtyper.lltypesystem.rfile import FileRepr
+def create_file(filename, mode="r", buffering=-1):
+assert buffering == -1
+assert filename is not None
+assert mode is not None
+ll_name = rffi.str2charp(filename)
+try:
+ll_mode = rffi.str2charp(mode)
+try:
+ll_f = c_open(ll_name, ll_mode)
+if not ll_f:
+errno = rposix.get_errno()
+raise OSError(errno, os.strerror(errno))
+finally:
+lltype.free(ll_mode, flavor='raw')
+finally:
+lltype.free(ll_name, flavor='raw')
+return RFile(ll_f)
 
-return FileRepr(rtyper)
+def create_temp_rfile():
+res = c_tmpfile()
+if not res:
+errno = rposix.get_errno()
+raise OSError(errno, os.strerror(errno))
+return RFile(res)
 
-class FileEntry(ExtRegistryEntry):
-_about_ = open
+class RFile(object):
+def __init__(self, ll_file):
+self.ll_file = ll_file
 
-def compute_result_annotation(self, s_name, s_mode=None):
-assert isinstance(s_name, SomeString)
-if s_mode is not None:
-assert isinstance(s_mode, SomeString)
-return SomeFile()
+def write(self, value)

[pypy-commit] cffi split-verify: Clean up a few things, fix python3 compat.

2013-10-06 Thread jerith
Author: Jeremy Thurgood 
Branch: split-verify
Changeset: r1352:34923698f6a2
Date: 2013-10-06 12:19 +0200
http://bitbucket.org/cffi/cffi/changeset/34923698f6a2/

Log:Clean up a few things, fix python3 compat.

diff --git a/cffi/api.py b/cffi/api.py
--- a/cffi/api.py
+++ b/cffi/api.py
@@ -480,14 +480,12 @@
 # XXX: We use force_generic_engine here because vengine_cpy collects
 #  types when it writes the source.
 import os.path
-from .verifier import Verifier, _caller_dir_pycache, _get_so_suffix
-tmpdir = _caller_dir_pycache()
+from .verifier import Verifier, _get_so_suffix
 self.ffi.verifier = Verifier(
-self.ffi, source, tmpdir, libname, force_generic_engine=True,
-**kwargs)
-libfilename = libname + _get_so_suffix()
+self.ffi, source, force_generic_engine=True, **kwargs)
+libfilename = '_'.join([self._module_name, libname])
 self.ffi.verifier.make_library(
-os.path.join(self._module_path, libfilename))
+os.path.join(self._module_path, libfilename + _get_so_suffix()))
 self._module_source += '\n'.join([
 "def load_%s():",
 "from cffi.verifier import Verifier",
@@ -498,7 +496,7 @@
 "verifier._has_module = True",
 "return verifier._load_library()",
 "",
-]) % (libname, libname)
+]) % (libname, libfilename)
 
 def write_ffi_module(self):
 import os
diff --git a/testing/test_makelib.py b/testing/test_makelib.py
--- a/testing/test_makelib.py
+++ b/testing/test_makelib.py
@@ -3,6 +3,13 @@
 from cffi import FFIBuilder
 
 
+def _clean_modules(tmpdir, module_name):
+sys.path.remove(str(tmpdir))
+for name in list(sys.modules.keys()):
+if name and name.endswith(module_name):
+sys.modules.pop(name)
+
+
 def test_ffibuilder_makelib(tmpdir):
 builder = FFIBuilder("foo_ffi", str(tmpdir))
 builder.cdef("""
@@ -15,10 +22,7 @@
 try:
 import foo_ffi
 finally:
-sys.path.remove(str(tmpdir))
-for name in sys.modules.keys():
-if name.endswith('foo_ffi'):
-sys.modules.pop(name)
+_clean_modules(tmpdir, 'foo_ffi')
 
 lib = foo_ffi.load_foo()
 assert lib.sin(12.3) == math.sin(12.3)
@@ -36,10 +40,7 @@
 try:
 import foo_ffi
 finally:
-sys.path.remove(str(tmpdir))
-for name in sys.modules.keys():
-if name.endswith('foo_ffi'):
-sys.modules.pop(name)
+_clean_modules(tmpdir, 'foo_ffi')
 
 lib = foo_ffi.load_foo()
 assert lib.sin(12.3) == math.sin(12.3)
@@ -58,10 +59,7 @@
 try:
 import foo_ffi
 finally:
-sys.path.remove(str(tmpdir))
-for name in sys.modules.keys():
-if name.endswith('foo_ffi'):
-sys.modules.pop(name)
+_clean_modules(tmpdir, 'foo_ffi')
 
 lib_foo = foo_ffi.load_foo()
 assert lib_foo.sin(12.3) == math.sin(12.3)
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] cffi split-verify: Collect built filepaths.

2013-10-06 Thread jerith
Author: Jeremy Thurgood 
Branch: split-verify
Changeset: r1353:e179cc8d6f7a
Date: 2013-10-06 13:13 +0200
http://bitbucket.org/cffi/cffi/changeset/e179cc8d6f7a/

Log:Collect built filepaths.

diff --git a/cffi/api.py b/cffi/api.py
--- a/cffi/api.py
+++ b/cffi/api.py
@@ -455,6 +455,7 @@
 self._module_name = module_name
 self._module_path = module_path
 self.ffi = FFI(backend=backend)
+self._built_files = []
 self._module_source = "\n".join([
 "from cffi import FFI",
 "",
@@ -484,8 +485,9 @@
 self.ffi.verifier = Verifier(
 self.ffi, source, force_generic_engine=True, **kwargs)
 libfilename = '_'.join([self._module_name, libname])
-self.ffi.verifier.make_library(
-os.path.join(self._module_path, libfilename + _get_so_suffix()))
+libfilepath = os.path.join(
+self._module_path, libfilename + _get_so_suffix())
+self.ffi.verifier.make_library(libfilepath)
 self._module_source += '\n'.join([
 "def load_%s():",
 "from cffi.verifier import Verifier",
@@ -497,6 +499,7 @@
 "return verifier._load_library()",
 "",
 ]) % (libname, libfilename)
+self._built_files.append(libfilepath)
 
 def write_ffi_module(self):
 import os
@@ -505,9 +508,14 @@
 except OSError:
 pass
 
-module_filename = self._module_name + '.py'
-file = open(os.path.join(self._module_path, module_filename), 'w')
+module_filepath = os.path.join(
+self._module_path, self._module_name + '.py')
+file = open(module_filepath, 'w')
 try:
 file.write(self._module_source)
 finally:
 file.close()
+self._built_files.append(module_filepath)
+
+def list_built_files(self):
+return self._built_files
diff --git a/testing/test_makelib.py b/testing/test_makelib.py
--- a/testing/test_makelib.py
+++ b/testing/test_makelib.py
@@ -1,6 +1,7 @@
 import math
 import sys
 from cffi import FFIBuilder
+from cffi.verifier import _get_so_suffix
 
 
 def _clean_modules(tmpdir, module_name):
@@ -18,6 +19,11 @@
 builder.makelib('foo', '#include ')
 builder.write_ffi_module()
 
+assert builder.list_built_files() == [
+str(tmpdir.join('foo_ffi_foo' + _get_so_suffix())),
+str(tmpdir.join('foo_ffi.py')),
+]
+
 sys.path.append(str(tmpdir))
 try:
 import foo_ffi
@@ -36,6 +42,10 @@
 builder.add_dlopen('foo', "m")
 builder.write_ffi_module()
 
+assert builder.list_built_files() == [
+str(tmpdir.join('foo_ffi.py')),
+]
+
 sys.path.append(str(tmpdir))
 try:
 import foo_ffi
@@ -55,6 +65,11 @@
 builder.add_dlopen('bar', "m")
 builder.write_ffi_module()
 
+assert builder.list_built_files() == [
+str(tmpdir.join('foo_ffi_foo' + _get_so_suffix())),
+str(tmpdir.join('foo_ffi.py')),
+]
+
 sys.path.append(str(tmpdir))
 try:
 import foo_ffi
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] cffi split-verify: Move FFIBuilder into its own module.

2013-10-06 Thread jerith
Author: Jeremy Thurgood 
Branch: split-verify
Changeset: r1354:e5fe5874e20f
Date: 2013-10-06 13:21 +0200
http://bitbucket.org/cffi/cffi/changeset/e5fe5874e20f/

Log:Move FFIBuilder into its own module.

diff --git a/cffi/__init__.py b/cffi/__init__.py
--- a/cffi/__init__.py
+++ b/cffi/__init__.py
@@ -1,7 +1,8 @@
 __all__ = ['FFI', 'VerificationError', 'VerificationMissing', 'CDefError',
-   'FFIError']
+   'FFIError', 'FFIBuilder']
 
-from .api import FFI, CDefError, FFIError, FFIBuilder
+from .api import FFI, CDefError, FFIError
+from .builder import FFIBuilder
 from .ffiplatform import VerificationError, VerificationMissing
 
 __version__ = "0.7.2"
diff --git a/cffi/api.py b/cffi/api.py
--- a/cffi/api.py
+++ b/cffi/api.py
@@ -448,74 +448,3 @@
 return None
 else:
 return ffi._get_cached_btype(tp)
-
-
-class FFIBuilder(object):
-def __init__(self, module_name, module_path, backend=None):
-self._module_name = module_name
-self._module_path = module_path
-self.ffi = FFI(backend=backend)
-self._built_files = []
-self._module_source = "\n".join([
-"from cffi import FFI",
-"",
-"ffi = FFI()",
-"",
-])
-
-def cdef(self, csource, override=False):
-self.ffi.cdef(csource, override=override)
-self._module_source += "ffi.cdef(%r, override=%r)\n" % (
-csource, override)
-
-def add_dlopen(self, libname, name, flags=0):
-lib = self.ffi.dlopen(name, flags=flags)
-self._module_source += '\n'.join([
-"def load_%s():",
-"return ffi.dlopen(%r, flags=%r)",
-"",
-]) % (libname, name, flags)
-return lib
-
-def makelib(self, libname, source='', **kwargs):
-# XXX: We use force_generic_engine here because vengine_cpy collects
-#  types when it writes the source.
-import os.path
-from .verifier import Verifier, _get_so_suffix
-self.ffi.verifier = Verifier(
-self.ffi, source, force_generic_engine=True, **kwargs)
-libfilename = '_'.join([self._module_name, libname])
-libfilepath = os.path.join(
-self._module_path, libfilename + _get_so_suffix())
-self.ffi.verifier.make_library(libfilepath)
-self._module_source += '\n'.join([
-"def load_%s():",
-"from cffi.verifier import Verifier",
-"import os.path",
-"module_path = os.path.dirname(__file__)",
-"verifier = Verifier(",
-"ffi, None, module_path, %r, force_generic_engine=True)",
-"verifier._has_module = True",
-"return verifier._load_library()",
-"",
-]) % (libname, libfilename)
-self._built_files.append(libfilepath)
-
-def write_ffi_module(self):
-import os
-try:
-os.makedirs(self._module_path)
-except OSError:
-pass
-
-module_filepath = os.path.join(
-self._module_path, self._module_name + '.py')
-file = open(module_filepath, 'w')
-try:
-file.write(self._module_source)
-finally:
-file.close()
-self._built_files.append(module_filepath)
-
-def list_built_files(self):
-return self._built_files
diff --git a/cffi/builder.py b/cffi/builder.py
new file mode 100644
--- /dev/null
+++ b/cffi/builder.py
@@ -0,0 +1,72 @@
+from .api import FFI
+
+
+class FFIBuilder(object):
+def __init__(self, module_name, module_path, backend=None):
+self._module_name = module_name
+self._module_path = module_path
+self.ffi = FFI(backend=backend)
+self._built_files = []
+self._module_source = "\n".join([
+"from cffi import FFI",
+"",
+"ffi = FFI()",
+"",
+])
+
+def cdef(self, csource, override=False):
+self.ffi.cdef(csource, override=override)
+self._module_source += "ffi.cdef(%r, override=%r)\n" % (
+csource, override)
+
+def add_dlopen(self, libname, name, flags=0):
+lib = self.ffi.dlopen(name, flags=flags)
+self._module_source += '\n'.join([
+"def load_%s():",
+"return ffi.dlopen(%r, flags=%r)",
+"",
+]) % (libname, name, flags)
+return lib
+
+def makelib(self, libname, source='', **kwargs):
+# XXX: We use force_generic_engine here because vengine_cpy collects
+#  types when it writes the source.
+import os.path
+from .verifier import Verifier, _get_so_suffix
+self.ffi.verifier = Verifier(
+self.ffi, source, force_generic_engine=True, **kwargs)
+libfilename = '_'.join([self._module_name, libname])
+libfilepath = os.path.join(
+self._module_path, libfilename + _get_so_suffix())
+  

[pypy-commit] pypy default: Make the test more similar to pypy/module/_cffi_backend.

2013-10-06 Thread arigo
Author: Armin Rigo 
Branch: 
Changeset: r67164:d0b269c45840
Date: 2013-10-06 13:22 +0200
http://bitbucket.org/pypy/pypy/changeset/d0b269c45840/

Log:Make the test more similar to pypy/module/_cffi_backend. Crashes
when a guard fails in the middle of the virtualized raw-malloc
buffer.

diff --git a/rpython/jit/backend/llgraph/runner.py 
b/rpython/jit/backend/llgraph/runner.py
--- a/rpython/jit/backend/llgraph/runner.py
+++ b/rpython/jit/backend/llgraph/runner.py
@@ -381,6 +381,8 @@
 res = self.llinterp.eval_graph(ptr._obj.graph, args)
 else:
 res = ptr._obj._callable(*args)
+if RESULT is lltype.Void:
+return None
 return support.cast_result(RESULT, res)
 
 def _do_call(self, func, args_i, args_r, args_f, calldescr):
diff --git a/rpython/jit/metainterp/test/test_fficall.py 
b/rpython/jit/metainterp/test/test_fficall.py
--- a/rpython/jit/metainterp/test/test_fficall.py
+++ b/rpython/jit/metainterp/test/test_fficall.py
@@ -86,15 +86,17 @@
 data = rffi.ptradd(exchange_buffer, ofs)
 rffi.cast(lltype.Ptr(TYPE), data)[0] = write_rvalue
 
-def f():
+def f(i):
 exbuf = lltype.malloc(rffi.CCHARP.TO, (len(avalues)+2) * 16,
-  flavor='raw', zero=True)
-ofs = 16
+  flavor='raw')
+
+targetptr = rffi.ptradd(exbuf, 16)
 for avalue in unroll_avalues:
 TYPE = rffi.CArray(lltype.typeOf(avalue))
-data = rffi.ptradd(exbuf, ofs)
-rffi.cast(lltype.Ptr(TYPE), data)[0] = avalue
-ofs += 16
+if i == 9:# a guard that can fail
+pass
+rffi.cast(lltype.Ptr(TYPE), targetptr)[0] = avalue
+targetptr = rffi.ptradd(targetptr, 16)
 
 jit_ffi_call(cif_description, func_addr, exbuf)
 
@@ -102,8 +104,7 @@
 res = 654321
 else:
 TYPE = rffi.CArray(lltype.typeOf(rvalue))
-data = rffi.ptradd(exbuf, ofs)
-res = rffi.cast(lltype.Ptr(TYPE), data)[0]
+res = rffi.cast(lltype.Ptr(TYPE), targetptr)[0]
 lltype.free(exbuf, flavor='raw')
 if lltype.typeOf(res) is lltype.SingleFloat:
 res = float(res)
@@ -117,9 +118,9 @@
 return res == rvalue
 
 with FakeFFI(fake_call_impl_any):
-res = f()
+res = f(-42)
 assert matching_result(res, rvalue)
-res = self.interp_operations(f, [],
+res = self.interp_operations(f, [-42],
 supports_floats = supports_floats,
   supports_longlong = supports_longlong,
   supports_singlefloats = supports_singlefloats)
@@ -132,6 +133,19 @@
 self.check_operations_history(call_may_force=0,
   
call_release_gil=expected_call_release_gil)
 
+##
+driver = jit.JitDriver(reds=['i'], greens=[])
+def main():
+i = 0
+while 1:
+driver.jit_merge_point(i=i)
+res = f(i)
+i += 1
+if i == 12:
+return res
+self.meta_interp(main, [])
+
+
 def test_simple_call_int(self):
 self._run([types.signed] * 2, types.signed, [456, 789], -42)
 
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: progressing on d0b269c45840: the issue is that VRawSliceValue()

2013-10-06 Thread arigo
Author: Armin Rigo 
Branch: 
Changeset: r67165:3e6b3a2d6bf7
Date: 2013-10-06 13:47 +0200
http://bitbucket.org/pypy/pypy/changeset/3e6b3a2d6bf7/

Log:progressing on d0b269c45840: the issue is that VRawSliceValue()
fails to override get_args_for_fail() and inherits the default one,
which does nothing. This change shares some repeated code and shows
the problem more directly.

diff --git a/rpython/jit/metainterp/optimizeopt/virtualize.py 
b/rpython/jit/metainterp/optimizeopt/virtualize.py
--- a/rpython/jit/metainterp/optimizeopt/virtualize.py
+++ b/rpython/jit/metainterp/optimizeopt/virtualize.py
@@ -45,6 +45,15 @@
 return value
 return OptValue(self.force_box(optforce))
 
+def get_args_for_fail(self, modifier):
+# checks for recursion: it is False unless
+# we have already seen the very same keybox
+if self.box is None and not modifier.already_seen_virtual(self.keybox):
+self._get_args_for_fail(modifier)
+
+def _get_args_for_fail(self, modifier):
+raise NotImplementedError("abstract base")
+
 def make_virtual_info(self, modifier, fieldnums):
 if fieldnums is None:
 return self._make_virtual(modifier)
@@ -193,16 +202,13 @@
 self._cached_sorted_fields = lst
 return lst
 
-def get_args_for_fail(self, modifier):
-if self.box is None and not modifier.already_seen_virtual(self.keybox):
-# checks for recursion: it is False unless
-# we have already seen the very same keybox
-lst = self._get_field_descr_list()
-fieldboxes = [self._fields[ofs].get_key_box() for ofs in lst]
-modifier.register_virtual_fields(self.keybox, fieldboxes)
-for ofs in lst:
-fieldvalue = self._fields[ofs]
-fieldvalue.get_args_for_fail(modifier)
+def _get_args_for_fail(self, modifier):
+lst = self._get_field_descr_list()
+fieldboxes = [self._fields[ofs].get_key_box() for ofs in lst]
+modifier.register_virtual_fields(self.keybox, fieldboxes)
+for ofs in lst:
+fieldvalue = self._fields[ofs]
+fieldvalue.get_args_for_fail(modifier)
 
 class VirtualValue(AbstractVirtualStructValue):
 level = optimizer.LEVEL_KNOWNCLASS
@@ -254,18 +260,15 @@
 def set_item_value(self, i, newval):
 raise NotImplementedError
 
-def get_args_for_fail(self, modifier):
-if self.box is None and not modifier.already_seen_virtual(self.keybox):
-# checks for recursion: it is False unless
-# we have already seen the very same keybox
-itemboxes = []
-for i in range(self.getlength()):
-itemvalue = self.get_item_value(i)
-itemboxes.append(itemvalue.get_key_box())
-modifier.register_virtual_fields(self.keybox, itemboxes)
-for i in range(self.getlength()):
-itemvalue = self.get_item_value(i)
-itemvalue.get_args_for_fail(modifier)
+def _get_args_for_fail(self, modifier):
+itemboxes = []
+for i in range(self.getlength()):
+itemvalue = self.get_item_value(i)
+itemboxes.append(itemvalue.get_key_box())
+modifier.register_virtual_fields(self.keybox, itemboxes)
+for i in range(self.getlength()):
+itemvalue = self.get_item_value(i)
+itemvalue.get_args_for_fail(modifier)
 
 
 class VArrayValue(AbstractVArrayValue):
@@ -370,17 +373,16 @@
 descrs.append(item_descrs)
 return descrs
 
-def get_args_for_fail(self, modifier):
-if self.box is None and not modifier.already_seen_virtual(self.keybox):
-itemdescrs = self._get_list_of_descrs()
-itemboxes = []
-for i in range(len(self._items)):
-for descr in itemdescrs[i]:
-itemboxes.append(self._items[i][descr].get_key_box())
-modifier.register_virtual_fields(self.keybox, itemboxes)
-for i in range(len(self._items)):
-for descr in itemdescrs[i]:
-self._items[i][descr].get_args_for_fail(modifier)
+def _get_args_for_fail(self, modifier):
+itemdescrs = self._get_list_of_descrs()
+itemboxes = []
+for i in range(len(self._items)):
+for descr in itemdescrs[i]:
+itemboxes.append(self._items[i][descr].get_key_box())
+modifier.register_virtual_fields(self.keybox, itemboxes)
+for i in range(len(self._items)):
+for descr in itemdescrs[i]:
+self._items[i][descr].get_args_for_fail(modifier)
 
 def force_at_end_of_preamble(self, already_forced, optforce):
 if self in already_forced:
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] cffi split-verify: Better API for generated module.

2013-10-06 Thread jerith
Author: Jeremy Thurgood 
Branch: split-verify
Changeset: r1355:b1c528ee24ae
Date: 2013-10-06 14:35 +0200
http://bitbucket.org/cffi/cffi/changeset/b1c528ee24ae/

Log:Better API for generated module.

diff --git a/cffi/builder.py b/cffi/builder.py
--- a/cffi/builder.py
+++ b/cffi/builder.py
@@ -1,31 +1,136 @@
 from .api import FFI
 
 
+MODULE_BOILERPLATE = """
+#  #
+# NOTE: This module is generated by cffi. DO NOT EDIT IT MANUALLY. #
+#  #
+
+from functools import wraps
+from cffi import FFI
+
+
+_ffi = FFI()
+
+
+### The functions below are proxies for `_ffi` to make things more convenient.
+
+
+@wraps(_ffi.typeof)
+def typeof(cdecl):
+return _ffi.typeof(cdecl)
+
+
+@wraps(_ffi.sizeof)
+def sizeof(cdecl):
+return _ffi.sizeof(cdecl)
+
+
+@wraps(_ffi.alignof)
+def alignof(cdecl):
+return _ffi.alignof(cdecl)
+
+
+@wraps(_ffi.offsetof)
+def offsetof(cdecl):
+return _ffi.offsetof(cdecl)
+
+
+@wraps(_ffi.new)
+def new(cdecl, init=None):
+return _ffi.new(cdecl, init=init)
+
+
+@wraps(_ffi.cast)
+def cast(cdecl, source):
+return _ffi.cast(cdecl, source)
+
+
+@wraps(_ffi.string)
+def string(cdecl, maxlen=-1):
+return _ffi.string(cdecl, maxlen=-1)
+
+
+@wraps(_ffi.buffer)
+def buffer(cdecl, maxlen=-1):
+return _ffi.buffer(cdecl, maxlen=-1)
+
+
+@wraps(_ffi.callback)
+def callback(cdecl, python_callable=None, error=None):
+return _ffi.callback(cdecl, python_callable=python_callable, error=error)
+
+
+@wraps(_ffi.getctype)
+def getctype(cdecl, replace_with=''):
+return _ffi.getctype(cdecl, replace_with=replace_with)
+
+
+@wraps(_ffi.gc)
+def gc(cdata, destructor):
+return _ffi.gc(cdata, destructor)
+
+
+def _get_errno():
+return _ffi.errno
+def _set_errno(errno):
+_ffi.errno = errno
+errno = property(_get_errno, _set_errno, None,
+ "the value of 'errno' from/to the C calls")
+
+
+@wraps(_ffi.addressof)
+def addressof(cdata, field=None):
+return _ffi.addressof(cdata, field=field)
+
+
+@wraps(_ffi.new_handle)
+def new_handle(x):
+return _ffi.new_handle(x)
+
+
+@wraps(_ffi.from_handle)
+def from_handle(x):
+return _ffi.from_handle(x)
+
+
+### The functions below are generated by cffi.
+"""
+
+
+DLOPEN_FUNC_TEMPLATE = """
+def load_%s():
+return _ffi.dlopen(%r, flags=%r)
+"""
+
+
+MAKELIB_FUNC_TEMPLATE = """
+def load_%s():
+import os.path
+from cffi.verifier import Verifier
+module_path = os.path.dirname(__file__)
+verifier = Verifier(_ffi, None, module_path, %r, force_generic_engine=True)
+verifier._has_module = True
+return verifier._load_library()
+"""
+
+
 class FFIBuilder(object):
 def __init__(self, module_name, module_path, backend=None):
 self._module_name = module_name
 self._module_path = module_path
 self.ffi = FFI(backend=backend)
 self._built_files = []
-self._module_source = "\n".join([
-"from cffi import FFI",
-"",
-"ffi = FFI()",
-"",
-])
+self._module_source = MODULE_BOILERPLATE
 
 def cdef(self, csource, override=False):
 self.ffi.cdef(csource, override=override)
-self._module_source += "ffi.cdef(%r, override=%r)\n" % (
+self._module_source += "_ffi.cdef(%r, override=%r)\n" % (
 csource, override)
 
 def add_dlopen(self, libname, name, flags=0):
 lib = self.ffi.dlopen(name, flags=flags)
-self._module_source += '\n'.join([
-"def load_%s():",
-"return ffi.dlopen(%r, flags=%r)",
-"",
-]) % (libname, name, flags)
+self._module_source += DLOPEN_FUNC_TEMPLATE % (libname, name, flags)
 return lib
 
 def makelib(self, libname, source='', **kwargs):
@@ -39,18 +144,8 @@
 libfilepath = os.path.join(
 self._module_path, libfilename + _get_so_suffix())
 self.ffi.verifier.make_library(libfilepath)
-self._module_source += '\n'.join([
-"def load_%s():",
-"from cffi.verifier import Verifier",
-"import os.path",
-"module_path = os.path.dirname(__file__)",
-"verifier = Verifier(",
-"ffi, None, module_path, %r, force_generic_engine=True)",
-"verifier._has_module = True",
-"return verifier._load_library()",
-"",
-]) % (libname, libfilename)
-self._built_files.append(libfilepath)
+self._module_source += MAKELIB_FUNC_TEMPLATE % (libname, libfilename)
+self._built_files.append(libfilename + _get_so_suffix())
 
 def write_ffi_module(self):
 import os
@@ -59,14 +154,14 @@
 except OSError:
 pass
 
-module_filepath = os.path.join(
-self._module_path, self._module_name + '.py')
+   

[pypy-commit] pypy default: Add the missing VRawSliceInfo, improve the test, fix.

2013-10-06 Thread arigo
Author: Armin Rigo 
Branch: 
Changeset: r67166:1cd66e3ec8aa
Date: 2013-10-06 14:41 +0200
http://bitbucket.org/pypy/pypy/changeset/1cd66e3ec8aa/

Log:Add the missing VRawSliceInfo, improve the test, fix.

diff --git a/rpython/jit/metainterp/optimizeopt/virtualize.py 
b/rpython/jit/metainterp/optimizeopt/virtualize.py
--- a/rpython/jit/metainterp/optimizeopt/virtualize.py
+++ b/rpython/jit/metainterp/optimizeopt/virtualize.py
@@ -483,6 +483,15 @@
 def getitem_raw(self, offset, length, descr):
 return self.rawbuffer_value.getitem_raw(self.offset+offset, length, 
descr)
 
+def _get_args_for_fail(self, modifier):
+box = self.rawbuffer_value.get_key_box()
+modifier.register_virtual_fields(self.keybox, [box])
+self.rawbuffer_value.get_args_for_fail(modifier)
+
+def _make_virtual(self, modifier):
+return modifier.make_vrawslice(self.offset)
+
+
 class OptVirtualize(optimizer.Optimization):
 "Virtualize objects until they escape."
 
diff --git a/rpython/jit/metainterp/resume.py b/rpython/jit/metainterp/resume.py
--- a/rpython/jit/metainterp/resume.py
+++ b/rpython/jit/metainterp/resume.py
@@ -284,7 +284,10 @@
 return VArrayStructInfo(arraydescr, fielddescrs)
 
 def make_vrawbuffer(self, size, offsets, descrs):
-return VRawBufferStateInfo(size, offsets, descrs)
+return VRawBufferInfo(size, offsets, descrs)
+
+def make_vrawslice(self, offset):
+return VRawSliceInfo(offset)
 
 def make_vstrplain(self, is_unicode=False):
 if is_unicode:
@@ -554,10 +557,13 @@
 debug_print("\t\t", str(untag(i)))
 
 
-class VRawBufferStateInfo(AbstractVirtualInfo):
+class VAbstractRawInfo(AbstractVirtualInfo):
 kind = INT
 is_about_raw = True
 
+
+class VRawBufferInfo(VAbstractRawInfo):
+
 def __init__(self, size, offsets, descrs):
 self.size = size
 self.offsets = offsets
@@ -580,6 +586,25 @@
 debug_print("\t\t", str(untag(i)))
 
 
+class VRawSliceInfo(VAbstractRawInfo):
+
+def __init__(self, offset):
+self.offset = offset
+
+@specialize.argtype(1)
+def allocate_int(self, decoder, index):
+assert len(self.fieldnums) == 1
+base_buffer = decoder.decode_int(self.fieldnums[0])
+buffer = decoder.int_add_const(base_buffer, self.offset)
+decoder.virtuals_cache.set_int(index, buffer)
+return buffer
+
+def debug_prints(self):
+debug_print("\tvrawsliceinfo", " at ",  compute_unique_id(self))
+for i in self.fieldnums:
+debug_print("\t\t", str(untag(i)))
+
+
 class VArrayStructInfo(AbstractVirtualInfo):
 def __init__(self, arraydescr, fielddescrs):
 self.arraydescr = arraydescr
@@ -784,7 +809,7 @@
 if not v:
 v = self.rd_virtuals[index]
 ll_assert(bool(v), "resume.py: null rd_virtuals[index]")
-assert v.is_about_raw and isinstance(v, VRawBufferStateInfo)
+assert v.is_about_raw and isinstance(v, VAbstractRawInfo)
 v = v.allocate_int(self, index)
 ll_assert(v == self.virtuals_cache.get_int(index), "resume.py: bad 
cache")
 return v
@@ -1117,6 +1142,10 @@
 def write_a_float(self, index, box):
 self.boxes_f[index] = box
 
+def int_add_const(self, intbox, offset):
+return self.metainterp.execute_and_record(rop.INT_ADD, None, intbox,
+  ConstInt(offset))
+
 # -- when resuming for blackholing, get direct values --
 
 def blackhole_from_resumedata(blackholeinterpbuilder, jitdriver_sd, storage,
@@ -1408,6 +1437,9 @@
 def write_a_float(self, index, float):
 self.blackholeinterp.setarg_f(index, float)
 
+def int_add_const(self, base, offset):
+return base + offset
+
 # 
 
 def dump_storage(storage, liveboxes):
diff --git a/rpython/jit/metainterp/test/test_fficall.py 
b/rpython/jit/metainterp/test/test_fficall.py
--- a/rpython/jit/metainterp/test/test_fficall.py
+++ b/rpython/jit/metainterp/test/test_fficall.py
@@ -93,7 +93,7 @@
 targetptr = rffi.ptradd(exbuf, 16)
 for avalue in unroll_avalues:
 TYPE = rffi.CArray(lltype.typeOf(avalue))
-if i == 9:# a guard that can fail
+if i >= 9:# a guard that can fail
 pass
 rffi.cast(lltype.Ptr(TYPE), targetptr)[0] = avalue
 targetptr = rffi.ptradd(targetptr, 16)
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] cffi split-verify: Add cffi.packaging module which has everything you need for your setup.py

2013-10-06 Thread stefanor
Author: Stefano Rivera 
Branch: split-verify
Changeset: r1356:5e2da61b8aa5
Date: 2013-10-06 15:02 +0200
http://bitbucket.org/cffi/cffi/changeset/5e2da61b8aa5/

Log:Add cffi.packaging module which has everything you need for your
setup.py

diff --git a/cffi/packaging.py b/cffi/packaging.py
new file mode 100644
--- /dev/null
+++ b/cffi/packaging.py
@@ -0,0 +1,21 @@
+from distutils.command.build_ext import build_ext as _build_ext
+from distutils.core import Extension
+import os
+
+
+class FFIExtension(Extension):
+def __init__(self, ffi_builder):
+self.ffi_builder = ffi_builder
+Extension.__init__(self, '', [])
+
+
+class build_ext(_build_ext):
+def build_extension(self, ext):
+if isinstance(ext, FFIExtension):
+files = ext.ffi_builder(self.build_temp)
+for name in files:
+self.copy_file(
+os.path.join(self.build_temp, name),
+os.path.join(self.build_lib, name))
+else:
+super(build_ext, self).build_extension(ext)
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: Test fix

2013-10-06 Thread arigo
Author: Armin Rigo 
Branch: 
Changeset: r67167:551d3b942fd0
Date: 2013-10-06 15:18 +0200
http://bitbucket.org/pypy/pypy/changeset/551d3b942fd0/

Log:Test fix

diff --git a/rpython/jit/metainterp/test/test_fficall.py 
b/rpython/jit/metainterp/test/test_fficall.py
--- a/rpython/jit/metainterp/test/test_fficall.py
+++ b/rpython/jit/metainterp/test/test_fficall.py
@@ -133,17 +133,17 @@
 self.check_operations_history(call_may_force=0,
   
call_release_gil=expected_call_release_gil)
 
-##
-driver = jit.JitDriver(reds=['i'], greens=[])
-def main():
-i = 0
-while 1:
-driver.jit_merge_point(i=i)
-res = f(i)
-i += 1
-if i == 12:
-return res
-self.meta_interp(main, [])
+##
+driver = jit.JitDriver(reds=['i'], greens=[])
+def main():
+i = 0
+while 1:
+driver.jit_merge_point(i=i)
+res = f(i)
+i += 1
+if i == 12:
+return res
+self.meta_interp(main, [])
 
 
 def test_simple_call_int(self):
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: A test crashing on a recent pypy, which I hope is fixed now

2013-10-06 Thread arigo
Author: Armin Rigo 
Branch: 
Changeset: r67168:b355653b712a
Date: 2013-10-06 15:31 +0200
http://bitbucket.org/pypy/pypy/changeset/b355653b712a/

Log:A test crashing on a recent pypy, which I hope is fixed now by
1cd66e3ec8aa.

diff --git a/pypy/module/pypyjit/test_pypy_c/test_ffi.py 
b/pypy/module/pypyjit/test_pypy_c/test_ffi.py
--- a/pypy/module/pypyjit/test_pypy_c/test_ffi.py
+++ b/pypy/module/pypyjit/test_pypy_c/test_ffi.py
@@ -277,3 +277,28 @@
 f1 = call_release_gil(..., descr=)
 ...
 """)
+
+def test__cffi_bug1(self):
+from rpython.rlib.test.test_clibffi import get_libm_name
+def main(libm_name):
+try:
+import _cffi_backend
+except ImportError:
+sys.stderr.write('SKIP: cannot import _cffi_backend\n')
+return 0
+
+libm = _cffi_backend.load_library(libm_name)
+BDouble = _cffi_backend.new_primitive_type("double")
+BSin = _cffi_backend.new_function_type([BDouble], BDouble)
+sin = libm.load_function(BSin, 'sin')
+
+def f(*args):
+for i in range(300):
+sin(*args)
+
+f(1.0)
+f(1)
+#
+libm_name = get_libm_name(sys.platform)
+log = self.run(main, [libm_name])
+# assert did not crash
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] cffi split-verify: Fix (and test) ffi proxy functions.

2013-10-06 Thread jerith
Author: Jeremy Thurgood 
Branch: split-verify
Changeset: r1357:9f5e04349245
Date: 2013-10-06 15:36 +0200
http://bitbucket.org/cffi/cffi/changeset/9f5e04349245/

Log:Fix (and test) ffi proxy functions.

diff --git a/cffi/builder.py b/cffi/builder.py
--- a/cffi/builder.py
+++ b/cffi/builder.py
@@ -13,85 +13,34 @@
 _ffi = FFI()
 
 
-### The functions below are proxies for `_ffi` to make things more convenient.
+### Proxy `_ffi` methods to make things more convenient.
 
 
-@wraps(_ffi.typeof)
-def typeof(cdecl):
-return _ffi.typeof(cdecl)
+typeof = _ffi.typeof
+sizeof = _ffi.sizeof
+alignof = _ffi.alignof
+offsetof = _ffi.offsetof
+new = _ffi.new
+cast = _ffi.cast
+string = _ffi.string
+buffer = _ffi.buffer
+callback = _ffi.callback
+getctype = _ffi.getctype
+gc = _ffi.gc
 
 
-@wraps(_ffi.sizeof)
-def sizeof(cdecl):
-return _ffi.sizeof(cdecl)
+# Can't have properties on modules. :-(
 
+def get_errno():
+return _ffi.errno
 
-@wraps(_ffi.alignof)
-def alignof(cdecl):
-return _ffi.alignof(cdecl)
+def set_errno(errno):
+_ffi.errno = errno
 
 
-@wraps(_ffi.offsetof)
-def offsetof(cdecl):
-return _ffi.offsetof(cdecl)
-
-
-@wraps(_ffi.new)
-def new(cdecl, init=None):
-return _ffi.new(cdecl, init=init)
-
-
-@wraps(_ffi.cast)
-def cast(cdecl, source):
-return _ffi.cast(cdecl, source)
-
-
-@wraps(_ffi.string)
-def string(cdecl, maxlen=-1):
-return _ffi.string(cdecl, maxlen=-1)
-
-
-@wraps(_ffi.buffer)
-def buffer(cdecl, maxlen=-1):
-return _ffi.buffer(cdecl, maxlen=-1)
-
-
-@wraps(_ffi.callback)
-def callback(cdecl, python_callable=None, error=None):
-return _ffi.callback(cdecl, python_callable=python_callable, error=error)
-
-
-@wraps(_ffi.getctype)
-def getctype(cdecl, replace_with=''):
-return _ffi.getctype(cdecl, replace_with=replace_with)
-
-
-@wraps(_ffi.gc)
-def gc(cdata, destructor):
-return _ffi.gc(cdata, destructor)
-
-
-def _get_errno():
-return _ffi.errno
-def _set_errno(errno):
-_ffi.errno = errno
-errno = property(_get_errno, _set_errno, None,
- "the value of 'errno' from/to the C calls")
-
-
-@wraps(_ffi.addressof)
-def addressof(cdata, field=None):
-return _ffi.addressof(cdata, field=field)
-
-
-@wraps(_ffi.new_handle)
-def new_handle(x):
-return _ffi.new_handle(x)
-
-
-@wraps(_ffi.from_handle)
-def from_handle(x):
-return _ffi.from_handle(x)
+addressof = _ffi.addressof
+new_handle = _ffi.new_handle
+from_handle = _ffi.from_handle
 
 
 ### The functions below are generated by cffi.
diff --git a/testing/test_makelib.py b/testing/test_makelib.py
--- a/testing/test_makelib.py
+++ b/testing/test_makelib.py
@@ -80,3 +80,73 @@
 assert lib_foo.sin(12.3) == math.sin(12.3)
 lib_bar = foo_ffi.load_bar()
 assert lib_bar.sin(12.3) == math.sin(12.3)
+
+
+def test_ffi_module_functions(tmpdir):
+builder = FFIBuilder("foo_ffi", str(tmpdir))
+builder.cdef("""
+double sin(double x);
+""")
+builder.makelib('foo', '#include ')
+builder.write_ffi_module()
+
+sys.path.append(str(tmpdir))
+try:
+import foo_ffi
+finally:
+_clean_modules(tmpdir, 'foo_ffi')
+
+assert foo_ffi.typeof == foo_ffi._ffi.typeof
+assert foo_ffi.sizeof == foo_ffi._ffi.sizeof
+assert foo_ffi.alignof == foo_ffi._ffi.alignof
+assert foo_ffi.offsetof == foo_ffi._ffi.offsetof
+assert foo_ffi.new == foo_ffi._ffi.new
+assert foo_ffi.cast == foo_ffi._ffi.cast
+assert foo_ffi.string == foo_ffi._ffi.string
+assert foo_ffi.buffer == foo_ffi._ffi.buffer
+assert foo_ffi.callback == foo_ffi._ffi.callback
+assert foo_ffi.getctype == foo_ffi._ffi.getctype
+assert foo_ffi.gc == foo_ffi._ffi.gc
+
+foo_ffi.set_errno(7)
+assert foo_ffi.get_errno() == 7
+
+assert foo_ffi.addressof == foo_ffi._ffi.addressof
+assert foo_ffi.new_handle == foo_ffi._ffi.new_handle
+assert foo_ffi.from_handle == foo_ffi._ffi.from_handle
+
+
+def test_ffi_do_some_stuff(tmpdir):
+builder = FFIBuilder("foo_ffi", str(tmpdir))
+builder.cdef("""
+struct foo_s { int x; int y; };
+int grid_distance(struct foo_s offset);
+""")
+builder.makelib('foo', """
+struct foo_s { int x; int y; };
+int grid_distance(struct foo_s offset) {
+return offset.x + offset.y;
+}
+""")
+builder.write_ffi_module()
+
+sys.path.append(str(tmpdir))
+try:
+import foo_ffi
+finally:
+_clean_modules(tmpdir, 'foo_ffi')
+
+my_struct = foo_ffi.new('struct foo_s *', {'x': 1, 'y': 2})
+assert foo_ffi.typeof(my_struct) == foo_ffi.typeof("struct foo_s *")
+assert foo_ffi.sizeof('struct foo_s') == 2 * foo_ffi.sizeof('int')
+assert foo_ffi.alignof('struct foo_s') == foo_ffi.sizeof('int')
+assert foo_ffi.typeof(foo_ffi.cast('long', 42)) == foo_ffi.typeof('long')
+assert foo_ffi.string(foo_ffi.new('char *', b"\x00")) == b""
+
+def cb(n):
+return n + 1
+f = foo_ffi.callback("int(*)(int)

[pypy-commit] cffi split-verify: I think this is the most horrible thing I have written in months, but... pickle all the _declarations.

2013-10-06 Thread jerith
Author: Jeremy Thurgood 
Branch: split-verify
Changeset: r1358:1e40024fb288
Date: 2013-10-06 18:09 +0200
http://bitbucket.org/cffi/cffi/changeset/1e40024fb288/

Log:I think this is the most horrible thing I have written in months,
but... pickle all the _declarations.

diff --git a/cffi/builder.py b/cffi/builder.py
--- a/cffi/builder.py
+++ b/cffi/builder.py
@@ -1,3 +1,5 @@
+import pickle
+
 from .api import FFI
 
 
@@ -6,7 +8,7 @@
 # NOTE: This module is generated by cffi. DO NOT EDIT IT MANUALLY. #
 #  #
 
-from functools import wraps
+import pickle
 from cffi import FFI
 
 
@@ -74,8 +76,6 @@
 
 def cdef(self, csource, override=False):
 self.ffi.cdef(csource, override=override)
-self._module_source += "_ffi.cdef(%r, override=%r)\n" % (
-csource, override)
 
 def add_dlopen(self, libname, name, flags=0):
 lib = self.ffi.dlopen(name, flags=flags)
@@ -97,6 +97,9 @@
 self._built_files.append(libfilename + _get_so_suffix())
 
 def write_ffi_module(self):
+self._module_source += (
+"_ffi._parser._declarations = pickle.loads(%r)" %
+pickle.dumps(self.ffi._parser._declarations, 2))
 import os
 try:
 os.makedirs(self._module_path)
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] cffi split-verify: Add verifier_distutils_module, so that we can transition all the other zintegration tests to FFIBuilder

2013-10-06 Thread stefanor
Author: Stefano Rivera 
Branch: split-verify
Changeset: r1360:e898f9567c25
Date: 2013-10-06 19:04 +0200
http://bitbucket.org/cffi/cffi/changeset/e898f9567c25/

Log:Add verifier_distutils_module, so that we can transition all the
other zintegration tests to FFIBuilder

diff --git a/testing/snippets/verifier_distutils_module/setup.py 
b/testing/snippets/verifier_distutils_module/setup.py
new file mode 100644
--- /dev/null
+++ b/testing/snippets/verifier_distutils_module/setup.py
@@ -0,0 +1,7 @@
+
+from distutils.core import setup
+import snip_basic_verify
+
+setup(
+py_modules=['snip_basic_verify'],
+ext_modules=[snip_basic_verify.ffi.verifier.get_extension()])
diff --git a/testing/snippets/verifier_distutils_module/snip_basic_verify.py 
b/testing/snippets/verifier_distutils_module/snip_basic_verify.py
new file mode 100644
--- /dev/null
+++ b/testing/snippets/verifier_distutils_module/snip_basic_verify.py
@@ -0,0 +1,17 @@
+
+from cffi import FFI
+import sys
+
+ffi = FFI()
+ffi.cdef(""" // some declarations from the man page
+struct passwd {
+char *pw_name;
+...;
+};
+struct passwd *getpwuid(int uid);
+""")
+C = ffi.verify("""   // passed to the real C compiler
+#include 
+#include 
+""", libraries=[],# or a list of libraries to link with
+ force_generic_engine=hasattr(sys, '_force_generic_engine_'))
diff --git a/testing/test_zintegration.py b/testing/test_zintegration.py
--- a/testing/test_zintegration.py
+++ b/testing/test_zintegration.py
@@ -83,6 +83,13 @@
 assert snip_infrastructure.func() == 42
 ''')
 
+def test_verifier_distutils_module():
+run_setup_and_program("verifier_distutils_module", '''
+import snip_basic_verify
+p = snip_basic_verify.C.getpwuid(0)
+assert snip_basic_verify.ffi.string(p.pw_name) == b"root"
+''')
+
 def test_distutils_module():
 run_setup_and_program("distutils_module", '''
 import snip_basic_verify
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] cffi split-verify: PEP-8 order the test_zintegration imports

2013-10-06 Thread stefanor
Author: Stefano Rivera 
Branch: split-verify
Changeset: r1359:34e95a90b3e1
Date: 2013-10-06 18:59 +0200
http://bitbucket.org/cffi/cffi/changeset/34e95a90b3e1/

Log:PEP-8 order the test_zintegration imports

diff --git a/testing/test_zintegration.py b/testing/test_zintegration.py
--- a/testing/test_zintegration.py
+++ b/testing/test_zintegration.py
@@ -1,8 +1,13 @@
-import py, os, sys, shutil
 import imp
+import os
+import shutil
 import subprocess
+import sys
+
+import py
 from testing.udir import udir
 
+
 def create_venv(name):
 tmpdir = udir.join(name)
 try:
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] cffi split-verify: Create lib_dir if it doesn't exist

2013-10-06 Thread stefanor
Author: Stefano Rivera 
Branch: split-verify
Changeset: r1362:70f2aa466b82
Date: 2013-10-06 19:21 +0200
http://bitbucket.org/cffi/cffi/changeset/70f2aa466b82/

Log:Create lib_dir if it doesn't exist

diff --git a/cffi/packaging.py b/cffi/packaging.py
--- a/cffi/packaging.py
+++ b/cffi/packaging.py
@@ -13,6 +13,8 @@
 def build_extension(self, ext):
 if isinstance(ext, FFIExtension):
 files = ext.ffi_builder(self.build_temp)
+if not os.path.isdir(self.build_lib):
+os.mkdir(self.build_lib)
 for name in files:
 self.copy_file(
 os.path.join(self.build_temp, name),
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] cffi split-verify: Avoid setting force_generic_engine twice

2013-10-06 Thread stefanor
Author: Stefano Rivera 
Branch: split-verify
Changeset: r1361:7e2fb851e5b5
Date: 2013-10-06 19:19 +0200
http://bitbucket.org/cffi/cffi/changeset/7e2fb851e5b5/

Log:Avoid setting force_generic_engine twice

diff --git a/cffi/builder.py b/cffi/builder.py
--- a/cffi/builder.py
+++ b/cffi/builder.py
@@ -85,10 +85,10 @@
 def makelib(self, libname, source='', **kwargs):
 # XXX: We use force_generic_engine here because vengine_cpy collects
 #  types when it writes the source.
+kwargs['force_generic_engine'] = True
 import os.path
 from .verifier import Verifier, _get_so_suffix
-self.ffi.verifier = Verifier(
-self.ffi, source, force_generic_engine=True, **kwargs)
+self.ffi.verifier = Verifier(self.ffi, source, **kwargs)
 libfilename = '_'.join([self._module_name, libname])
 libfilepath = os.path.join(
 self._module_path, libfilename + _get_so_suffix())
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] cffi split-verify: Port distutils_module to FFIBuilder

2013-10-06 Thread stefanor
Author: Stefano Rivera 
Branch: split-verify
Changeset: r1363:a983c3e85b1c
Date: 2013-10-06 19:28 +0200
http://bitbucket.org/cffi/cffi/changeset/a983c3e85b1c/

Log:Port distutils_module to FFIBuilder

diff --git a/testing/snippets/distutils_module/ffibuilder.py 
b/testing/snippets/distutils_module/ffibuilder.py
new file mode 100644
--- /dev/null
+++ b/testing/snippets/distutils_module/ffibuilder.py
@@ -0,0 +1,21 @@
+import sys
+
+from cffi import FFIBuilder
+
+
+def build_ffi(path):
+builder = FFIBuilder('snip_basic_module', path)
+builder.cdef(""" // some declarations from the man page
+struct passwd {
+char *pw_name;
+...;
+};
+struct passwd *getpwuid(int uid);
+""")
+builder.makelib('passwd', """   // passed to the real C compiler
+#include 
+#include 
+""", libraries=[],  # or a list of libraries to link with
+ force_generic_engine=hasattr(sys, '_force_generic_engine_'))
+builder.write_ffi_module()
+return builder.list_built_files()
diff --git a/testing/snippets/distutils_module/setup.py 
b/testing/snippets/distutils_module/setup.py
--- a/testing/snippets/distutils_module/setup.py
+++ b/testing/snippets/distutils_module/setup.py
@@ -1,7 +1,10 @@
+from distutils.core import setup
 
-from distutils.core import setup
-import snip_basic_verify
+from cffi.packaging import FFIExtension, build_ext
+
+import ffibuilder
 
 setup(
-py_modules=['snip_basic_verify'],
-ext_modules=[snip_basic_verify.ffi.verifier.get_extension()])
+ext_modules=[FFIExtension(ffibuilder.build_ffi)],
+cmdclass={'build_ext': build_ext},
+)
diff --git a/testing/snippets/distutils_module/snip_basic_verify.py 
b/testing/snippets/distutils_module/snip_basic_verify.py
deleted file mode 100644
--- a/testing/snippets/distutils_module/snip_basic_verify.py
+++ /dev/null
@@ -1,17 +0,0 @@
-
-from cffi import FFI
-import sys
-
-ffi = FFI()
-ffi.cdef(""" // some declarations from the man page
-struct passwd {
-char *pw_name;
-...;
-};
-struct passwd *getpwuid(int uid);
-""")
-C = ffi.verify("""   // passed to the real C compiler
-#include 
-#include 
-""", libraries=[],# or a list of libraries to link with
- force_generic_engine=hasattr(sys, '_force_generic_engine_'))
diff --git a/testing/test_zintegration.py b/testing/test_zintegration.py
--- a/testing/test_zintegration.py
+++ b/testing/test_zintegration.py
@@ -92,9 +92,10 @@
 
 def test_distutils_module():
 run_setup_and_program("distutils_module", '''
-import snip_basic_verify
-p = snip_basic_verify.C.getpwuid(0)
-assert snip_basic_verify.ffi.string(p.pw_name) == b"root"
+import snip_basic_module
+lib = snip_basic_module.load_passwd()
+p = lib.getpwuid(0)
+assert snip_basic_module.string(p.pw_name) == b"root"
 ''')
 
 def test_distutils_package_1():
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: implement, test more of numpy c api

2013-10-06 Thread mattip
Author: Matti Picus 
Branch: 
Changeset: r67169:0be2466b3263
Date: 2013-10-06 22:46 +0300
http://bitbucket.org/pypy/pypy/changeset/0be2466b3263/

Log:implement, test more of numpy c api

diff --git a/pypy/module/cpyext/ndarrayobject.py 
b/pypy/module/cpyext/ndarrayobject.py
--- a/pypy/module/cpyext/ndarrayobject.py
+++ b/pypy/module/cpyext/ndarrayobject.py
@@ -149,14 +149,17 @@
  only used if the array is constructed that way. Almost always this
  parameter is NULL.
 """
-if min_depth !=0 or max_depth != 0:
-raise OperationError(space.w_NotImplementedError, space.wrap(
-'_PyArray_FromAny called with not-implemented min_dpeth or 
max_depth argument'))
 if requirements not in (0, NPY_DEFAULT):
 raise OperationError(space.w_NotImplementedError, space.wrap(
 '_PyArray_FromAny called with not-implemented requirements 
argument'))
 w_array = array(space, w_obj, w_dtype=w_dtype, copy=False)
-if w_array.is_scalar():
+if min_depth !=0 and len(w_array.get_shape()) < min_depth:
+raise OperationError(space.w_ValueError, space.wrap(
+'object of too small depth for desired array'))
+elif max_depth !=0 and len(w_array.get_shape()) > max_depth:
+raise OperationError(space.w_ValueError, space.wrap(
+'object of too deep for desired array'))
+elif w_array.is_scalar():
 # since PyArray_DATA() fails on scalars, create a 1D array and set 
empty
 # shape. So the following combination works for *reading* scalars:
 # PyObject *arr = PyArray_FromAny(obj);
diff --git a/pypy/module/cpyext/test/test_ndarrayobject.py 
b/pypy/module/cpyext/test/test_ndarrayobject.py
--- a/pypy/module/cpyext/test/test_ndarrayobject.py
+++ b/pypy/module/cpyext/test/test_ndarrayobject.py
@@ -90,15 +90,16 @@
 def test_FromAny(self, space, api):
 a = array(space, [10, 5, 3])
 assert api._PyArray_FromAny(a, NULL, 0, 0, 0, NULL) is a
-self.raises(space, api, NotImplementedError, api._PyArray_FromAny,
-a, NULL, 0, 3, 0, NULL)
+assert api._PyArray_FromAny(a, NULL, 1, 4, 0, NULL) is a
+self.raises(space, api, ValueError, api._PyArray_FromAny,
+a, NULL, 4, 5, 0, NULL)
 
 def test_FromObject(self, space, api):
 a = array(space, [10, 5, 3])
 assert api._PyArray_FromObject(a, a.get_dtype().num, 0, 0) is a
-exc = self.raises(space, api, NotImplementedError, 
api._PyArray_FromObject,
-a, 11, 0, 3)
-assert exc.errorstr(space).find('FromObject') >= 0
+exc = self.raises(space, api, ValueError, api._PyArray_FromObject,
+a, 11, 4, 5)
+assert exc.errorstr(space).find('desired') >= 0
 
 def test_list_from_fixedptr(self, space, api):
 A = lltype.GcArray(lltype.Float)
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] cffi split-verify: More whitespace

2013-10-06 Thread stefanor
Author: Stefano Rivera 
Branch: split-verify
Changeset: r1364:b3310f1eaa75
Date: 2013-10-06 23:52 +0200
http://bitbucket.org/cffi/cffi/changeset/b3310f1eaa75/

Log:More whitespace

diff --git a/cffi/builder.py b/cffi/builder.py
--- a/cffi/builder.py
+++ b/cffi/builder.py
@@ -98,7 +98,7 @@
 
 def write_ffi_module(self):
 self._module_source += (
-"_ffi._parser._declarations = pickle.loads(%r)" %
+"_ffi._parser._declarations = pickle.loads(%r)\n" %
 pickle.dumps(self.ffi._parser._declarations, 2))
 import os
 try:
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] cffi split-verify: Allow specifying a parent package

2013-10-06 Thread stefanor
Author: Stefano Rivera 
Branch: split-verify
Changeset: r1365:32908a1690ea
Date: 2013-10-07 01:03 +0200
http://bitbucket.org/cffi/cffi/changeset/32908a1690ea/

Log:Allow specifying a parent package

diff --git a/cffi/builder.py b/cffi/builder.py
--- a/cffi/builder.py
+++ b/cffi/builder.py
@@ -1,3 +1,4 @@
+import os
 import pickle
 
 from .api import FFI
@@ -67,13 +68,22 @@
 
 
 class FFIBuilder(object):
-def __init__(self, module_name, module_path, backend=None):
+def __init__(self, module_name, build_path, backend=None):
+module_package = ''
+if '.' in module_name:
+module_package, module_name = module_name.rsplit('.', 1)
+self._module_package = module_package
 self._module_name = module_name
-self._module_path = module_path
+self._build_path = build_path
 self.ffi = FFI(backend=backend)
 self._built_files = []
 self._module_source = MODULE_BOILERPLATE
 
+def _filename(self, name, suffix='.py'):
+parts = self._module_package.split('.')
+parts.append(name + suffix)
+return os.path.join(*parts)
+
 def cdef(self, csource, override=False):
 self.ffi.cdef(csource, override=override)
 
@@ -86,34 +96,32 @@
 # XXX: We use force_generic_engine here because vengine_cpy collects
 #  types when it writes the source.
 kwargs['force_generic_engine'] = True
-import os.path
 from .verifier import Verifier, _get_so_suffix
 self.ffi.verifier = Verifier(self.ffi, source, **kwargs)
-libfilename = '_'.join([self._module_name, libname])
-libfilepath = os.path.join(
-self._module_path, libfilename + _get_so_suffix())
-self.ffi.verifier.make_library(libfilepath)
-self._module_source += MAKELIB_FUNC_TEMPLATE % (libname, libfilename)
-self._built_files.append(libfilename + _get_so_suffix())
+barefilename = '_'.join([self._module_name, libname])
+libfile_path = self._filename(barefilename, _get_so_suffix())
+libfile_build_path = os.path.join(self._build_path, libfile_path)
+self.ffi.verifier.make_library(libfile_build_path)
+self._module_source += MAKELIB_FUNC_TEMPLATE % (libname, barefilename)
+self._built_files.append(libfile_path)
 
 def write_ffi_module(self):
 self._module_source += (
 "_ffi._parser._declarations = pickle.loads(%r)\n" %
 pickle.dumps(self.ffi._parser._declarations, 2))
-import os
 try:
-os.makedirs(self._module_path)
+os.makedirs(self._build_path)
 except OSError:
 pass
 
-module_filename = self._module_name + '.py'
-module_filepath = os.path.join(self._module_path, module_filename)
-file = open(module_filepath, 'w')
+module_path = self._filename(self._module_name)
+module_build_path = os.path.join(self._build_path, module_path)
+file = open(module_build_path, 'w')
 try:
 file.write(self._module_source)
 finally:
 file.close()
-self._built_files.append(module_filename)
+self._built_files.append(module_path)
 
 def list_built_files(self):
 return self._built_files
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] cffi split-verify: Port test_distutils_package_1 to FFIBuilder

2013-10-06 Thread stefanor
Author: Stefano Rivera 
Branch: split-verify
Changeset: r1366:51fa627e8b31
Date: 2013-10-07 01:04 +0200
http://bitbucket.org/cffi/cffi/changeset/51fa627e8b31/

Log:Port test_distutils_package_1 to FFIBuilder

diff --git a/testing/snippets/distutils_module/setup.py 
b/testing/snippets/distutils_module/setup.py
--- a/testing/snippets/distutils_module/setup.py
+++ b/testing/snippets/distutils_module/setup.py
@@ -4,6 +4,7 @@
 
 import ffibuilder
 
+
 setup(
 ext_modules=[FFIExtension(ffibuilder.build_ffi)],
 cmdclass={'build_ext': build_ext},
diff --git a/testing/snippets/distutils_package_1/setup.py 
b/testing/snippets/distutils_package_1/setup.py
--- a/testing/snippets/distutils_package_1/setup.py
+++ b/testing/snippets/distutils_package_1/setup.py
@@ -1,7 +1,12 @@
+from distutils.core import setup
 
-from distutils.core import setup
-import snip_basic_verify1
+from cffi.packaging import FFIExtension, build_ext
+
+import snip_basic_module1.ffibuilder
+
 
 setup(
-packages=['snip_basic_verify1'],
-ext_modules=[snip_basic_verify1.ffi.verifier.get_extension()])
+packages=['snip_basic_module1'],
+ext_modules=[FFIExtension(snip_basic_module1.ffibuilder.build_ffi)],
+cmdclass={'build_ext': build_ext},
+)
diff --git 
a/testing/snippets/distutils_package_1/snip_basic_module1/__init__.py 
b/testing/snippets/distutils_package_1/snip_basic_module1/__init__.py
new file mode 100644
diff --git 
a/testing/snippets/distutils_package_1/snip_basic_verify1/__init__.py 
b/testing/snippets/distutils_package_1/snip_basic_module1/ffibuilder.py
rename from testing/snippets/distutils_package_1/snip_basic_verify1/__init__.py
rename to testing/snippets/distutils_package_1/snip_basic_module1/ffibuilder.py
--- a/testing/snippets/distutils_package_1/snip_basic_verify1/__init__.py
+++ b/testing/snippets/distutils_package_1/snip_basic_module1/ffibuilder.py
@@ -1,17 +1,21 @@
-
-from cffi import FFI
 import sys
 
-ffi = FFI()
-ffi.cdef(""" // some declarations from the man page
+from cffi import FFIBuilder
+
+
+def build_ffi(path):
+builder = FFIBuilder('snip_basic_module1._ffi', path)
+builder.cdef(""" // some declarations from the man page
 struct passwd {
 char *pw_name;
 ...;
 };
 struct passwd *getpwuid(int uid);
-""")
-C = ffi.verify("""   // passed to the real C compiler
-#include 
-#include 
-""", libraries=[],# or a list of libraries to link with
- force_generic_engine=hasattr(sys, '_force_generic_engine_'))
+""")
+builder.makelib('passwd', """   // passed to the real C compiler
+#include 
+#include 
+""", libraries=[],# or a list of libraries to link with
+ force_generic_engine=hasattr(sys, '_force_generic_engine_'))
+builder.write_ffi_module()
+return builder.list_built_files()
diff --git a/testing/test_zintegration.py b/testing/test_zintegration.py
--- a/testing/test_zintegration.py
+++ b/testing/test_zintegration.py
@@ -92,17 +92,18 @@
 
 def test_distutils_module():
 run_setup_and_program("distutils_module", '''
-import snip_basic_module
-lib = snip_basic_module.load_passwd()
+import snip_basic_module as _ffi
+lib = _ffi.load_passwd()
 p = lib.getpwuid(0)
-assert snip_basic_module.string(p.pw_name) == b"root"
+assert _ffi.string(p.pw_name) == b"root"
 ''')
 
 def test_distutils_package_1():
 run_setup_and_program("distutils_package_1", '''
-import snip_basic_verify1
-p = snip_basic_verify1.C.getpwuid(0)
-assert snip_basic_verify1.ffi.string(p.pw_name) == b"root"
+from snip_basic_module1 import _ffi
+lib = _ffi.load_passwd()
+p = lib.getpwuid(0)
+assert _ffi.string(p.pw_name) == b"root"
 ''')
 
 def test_distutils_package_2():
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] cffi split-verify: Support ext_package

2013-10-06 Thread stefanor
Author: Stefano Rivera 
Branch: split-verify
Changeset: r1367:8c8fbba389fe
Date: 2013-10-07 01:36 +0200
http://bitbucket.org/cffi/cffi/changeset/8c8fbba389fe/

Log:Support ext_package

diff --git a/cffi/packaging.py b/cffi/packaging.py
--- a/cffi/packaging.py
+++ b/cffi/packaging.py
@@ -12,12 +12,15 @@
 class build_ext(_build_ext):
 def build_extension(self, ext):
 if isinstance(ext, FFIExtension):
-files = ext.ffi_builder(self.build_temp)
-if not os.path.isdir(self.build_lib):
-os.mkdir(self.build_lib)
+pkg = self.package.split('.') if self.package else []
+temp = os.path.join(self.build_temp, *pkg)
+lib = os.path.join(self.build_lib, *pkg)
+
+files = ext.ffi_builder(temp)
+if not os.path.isdir(lib):
+os.makedirs(lib)
 for name in files:
-self.copy_file(
-os.path.join(self.build_temp, name),
-os.path.join(self.build_lib, name))
+self.copy_file(os.path.join(temp, name),
+   os.path.join(lib, name))
 else:
 super(build_ext, self).build_extension(ext)
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] cffi split-verify: Port distutils_package_2 to FFIBuilder

2013-10-06 Thread stefanor
Author: Stefano Rivera 
Branch: split-verify
Changeset: r1369:1e3bfa8c08ae
Date: 2013-10-07 01:37 +0200
http://bitbucket.org/cffi/cffi/changeset/1e3bfa8c08ae/

Log:Port distutils_package_2 to FFIBuilder

diff --git a/testing/snippets/distutils_package_2/setup.py 
b/testing/snippets/distutils_package_2/setup.py
--- a/testing/snippets/distutils_package_2/setup.py
+++ b/testing/snippets/distutils_package_2/setup.py
@@ -1,8 +1,13 @@
+from distutils.core import setup
 
-from distutils.core import setup
-import snip_basic_verify2
+from cffi.packaging import FFIExtension, build_ext
+
+import snip_basic_module2.ffibuilder
+
 
 setup(
-packages=['snip_basic_verify2'],
-ext_package='snip_basic_verify2',
-ext_modules=[snip_basic_verify2.ffi.verifier.get_extension()])
+packages=['snip_basic_module2'],
+ext_package='snip_basic_module2',
+ext_modules=[FFIExtension(snip_basic_module2.ffibuilder.build_ffi)],
+cmdclass={'build_ext': build_ext},
+)
diff --git 
a/testing/snippets/distutils_package_2/snip_basic_module2/__init__.py 
b/testing/snippets/distutils_package_2/snip_basic_module2/__init__.py
new file mode 100644
diff --git 
a/testing/snippets/distutils_package_2/snip_basic_verify2/__init__.py 
b/testing/snippets/distutils_package_2/snip_basic_module2/ffibuilder.py
rename from testing/snippets/distutils_package_2/snip_basic_verify2/__init__.py
rename to testing/snippets/distutils_package_2/snip_basic_module2/ffibuilder.py
--- a/testing/snippets/distutils_package_2/snip_basic_verify2/__init__.py
+++ b/testing/snippets/distutils_package_2/snip_basic_module2/ffibuilder.py
@@ -1,18 +1,21 @@
-
-from cffi import FFI
 import sys
 
-ffi = FFI()
-ffi.cdef(""" // some declarations from the man page
+from cffi import FFIBuilder
+
+
+def build_ffi(path):
+builder = FFIBuilder('_ffi', path)
+builder.cdef(""" // some declarations from the man page
 struct passwd {
 char *pw_name;
 ...;
 };
 struct passwd *getpwuid(int uid);
-""")
-C = ffi.verify("""   // passed to the real C compiler
-#include 
-#include 
-""", libraries=[],# or a list of libraries to link with
- ext_package='snip_basic_verify2',
- force_generic_engine=hasattr(sys, '_force_generic_engine_'))
+""")
+builder.makelib('passwd', """   // passed to the real C compiler
+#include 
+#include 
+""", libraries=[],# or a list of libraries to link with
+ force_generic_engine=hasattr(sys, '_force_generic_engine_'))
+builder.write_ffi_module()
+return builder.list_built_files()
diff --git a/testing/test_zintegration.py b/testing/test_zintegration.py
--- a/testing/test_zintegration.py
+++ b/testing/test_zintegration.py
@@ -108,9 +108,10 @@
 
 def test_distutils_package_2():
 run_setup_and_program("distutils_package_2", '''
-import snip_basic_verify2
-p = snip_basic_verify2.C.getpwuid(0)
-assert snip_basic_verify2.ffi.string(p.pw_name) == b"root"
+from snip_basic_module2 import _ffi
+lib = _ffi.load_passwd()
+p = lib.getpwuid(0)
+assert _ffi.string(p.pw_name) == b"root"
 ''')
 
 def test_setuptools_module():
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] cffi split-verify: We'd want to ship ffibuilder in the sdist

2013-10-06 Thread stefanor
Author: Stefano Rivera 
Branch: split-verify
Changeset: r1368:3b261ee4ef91
Date: 2013-10-07 01:37 +0200
http://bitbucket.org/cffi/cffi/changeset/3b261ee4ef91/

Log:We'd want to ship ffibuilder in the sdist

diff --git a/testing/snippets/distutils_module/setup.py 
b/testing/snippets/distutils_module/setup.py
--- a/testing/snippets/distutils_module/setup.py
+++ b/testing/snippets/distutils_module/setup.py
@@ -6,6 +6,7 @@
 
 
 setup(
+data_files=['ffibuilder.py'],
 ext_modules=[FFIExtension(ffibuilder.build_ffi)],
 cmdclass={'build_ext': build_ext},
 )
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] cffi split-verify: Port setuptools tests to FFIBuilder

2013-10-06 Thread stefanor
Author: Stefano Rivera 
Branch: split-verify
Changeset: r1370:49b84f34cf9c
Date: 2013-10-07 01:51 +0200
http://bitbucket.org/cffi/cffi/changeset/49b84f34cf9c/

Log:Port setuptools tests to FFIBuilder

diff --git a/testing/snippets/setuptools_module/ffibuilder.py 
b/testing/snippets/setuptools_module/ffibuilder.py
new file mode 100644
--- /dev/null
+++ b/testing/snippets/setuptools_module/ffibuilder.py
@@ -0,0 +1,21 @@
+import sys
+
+from cffi import FFIBuilder
+
+
+def build_ffi(path):
+builder = FFIBuilder('snip_setuptools_module', path)
+builder.cdef(""" // some declarations from the man page
+struct passwd {
+char *pw_name;
+...;
+};
+struct passwd *getpwuid(int uid);
+""")
+builder.makelib('passwd', """   // passed to the real C compiler
+#include 
+#include 
+""", libraries=[],  # or a list of libraries to link with
+ force_generic_engine=hasattr(sys, '_force_generic_engine_'))
+builder.write_ffi_module()
+return builder.list_built_files()
diff --git a/testing/snippets/setuptools_module/setup.py 
b/testing/snippets/setuptools_module/setup.py
--- a/testing/snippets/setuptools_module/setup.py
+++ b/testing/snippets/setuptools_module/setup.py
@@ -1,8 +1,12 @@
+from setuptools import setup
 
-from setuptools import setup
-import snip_setuptools_verify
+from cffi.packaging import FFIExtension, build_ext
+
+import ffibuilder
+
 
 setup(
-zip_safe=False,
-py_modules=['snip_setuptools_verify'],
-ext_modules=[snip_setuptools_verify.ffi.verifier.get_extension()])
+data_files=['ffibuilder.py'],
+ext_modules=[FFIExtension(ffibuilder.build_ffi)],
+cmdclass={'build_ext': build_ext},
+)
diff --git a/testing/snippets/setuptools_module/snip_setuptools_verify.py 
b/testing/snippets/setuptools_module/snip_setuptools_verify.py
deleted file mode 100644
--- a/testing/snippets/setuptools_module/snip_setuptools_verify.py
+++ /dev/null
@@ -1,17 +0,0 @@
-
-from cffi import FFI
-import sys
-
-ffi = FFI()
-ffi.cdef(""" // some declarations from the man page
-struct passwd {
-char *pw_name;
-...;
-};
-struct passwd *getpwuid(int uid);
-""")
-C = ffi.verify("""   // passed to the real C compiler
-#include 
-#include 
-""", libraries=[],# or a list of libraries to link with
- force_generic_engine=hasattr(sys, '_force_generic_engine_'))
diff --git a/testing/snippets/setuptools_package_1/setup.py 
b/testing/snippets/setuptools_package_1/setup.py
--- a/testing/snippets/setuptools_package_1/setup.py
+++ b/testing/snippets/setuptools_package_1/setup.py
@@ -1,8 +1,11 @@
+from setuptools import setup
 
-from setuptools import setup
-import snip_setuptools_verify1
+from cffi.packaging import FFIExtension, build_ext
+
+import snip_setuptools_module1.ffibuilder
 
 setup(
-zip_safe=False,
-packages=['snip_setuptools_verify1'],
-ext_modules=[snip_setuptools_verify1.ffi.verifier.get_extension()])
+packages=['snip_setuptools_module1'],
+ext_modules=[FFIExtension(snip_setuptools_module1.ffibuilder.build_ffi)],
+cmdclass={'build_ext': build_ext},
+)
diff --git 
a/testing/snippets/setuptools_package_1/snip_setuptools_module1/__init__.py 
b/testing/snippets/setuptools_package_1/snip_setuptools_module1/__init__.py
new file mode 100644
diff --git 
a/testing/snippets/setuptools_package_1/snip_setuptools_module1/ffibuilder.py 
b/testing/snippets/setuptools_package_1/snip_setuptools_module1/ffibuilder.py
new file mode 100644
--- /dev/null
+++ 
b/testing/snippets/setuptools_package_1/snip_setuptools_module1/ffibuilder.py
@@ -0,0 +1,21 @@
+import sys
+
+from cffi import FFIBuilder
+
+
+def build_ffi(path):
+builder = FFIBuilder('snip_setuptools_module1._ffi', path)
+builder.cdef(""" // some declarations from the man page
+struct passwd {
+char *pw_name;
+...;
+};
+struct passwd *getpwuid(int uid);
+""")
+builder.makelib('passwd', """   // passed to the real C compiler
+#include 
+#include 
+""", libraries=[],# or a list of libraries to link with
+ force_generic_engine=hasattr(sys, '_force_generic_engine_'))
+builder.write_ffi_module()
+return builder.list_built_files()
diff --git 
a/testing/snippets/setuptools_package_1/snip_setuptools_verify1/__init__.py 
b/testing/snippets/setuptools_package_1/snip_setuptools_verify1/__init__.py
deleted file mode 100644
--- a/testing/snippets/setuptools_package_1/snip_setuptools_verify1/__init__.py
+++ /dev/null
@@ -1,17 +0,0 @@
-
-from cffi import FFI
-import sys
-
-ffi = FFI()
-ffi.cdef(""" // some declarations from the man page
-struct passwd {
-char *pw_name;
-...;
-};
-struct passwd *getpwuid(int uid);
-""")
-C = ffi.verify("""   // passed to the real C compiler
-#include 
-#include 
-""", libraries=[],# or a list of libraries to link with
- force_generic_engine=hasattr(sys, '_force_generic_engine_'))
diff --git a/testing/snippets/se

[pypy-commit] cffi split-verify: Bootstrapping documentation

2013-10-06 Thread stefanor
Author: Stefano Rivera 
Branch: split-verify
Changeset: r1371:d18e79b97f2e
Date: 2013-10-07 01:58 +0200
http://bitbucket.org/cffi/cffi/changeset/d18e79b97f2e/

Log:Bootstrapping documentation

diff --git a/doc/source/index.rst b/doc/source/index.rst
--- a/doc/source/index.rst
+++ b/doc/source/index.rst
@@ -355,6 +355,21 @@
 for more details about the ``verifier`` object.
 
 
+Bootstrapping CFFI
+--
+
+Your ``setup.py`` now needs CFFI to be importable at build time.
+You can let tell ``setuptools`` to download it before you import
+anything from CFFI::
+
+  from setuptools import setup, Distribution
+
+  Distribution(attrs=dict(setup_requires=['cffi']))
+
+  from cffi.packaging import FFIExtension, build_ext
+  ...
+
+
 Cleaning up the __pycache__ directory
 -
 
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit