[pypy-commit] pypy s390x-backend: splitting tests in zarch backend, should speed up things quite a bit

2016-01-29 Thread plan_rich
Author: Richard Plangger 
Branch: s390x-backend
Changeset: r82002:986957b12f49
Date: 2016-01-29 10:30 +0100
http://bitbucket.org/pypy/pypy/changeset/986957b12f49/

Log:splitting tests in zarch backend, should speed up things quite a bit

diff --git a/pypy/testrunner_cfg.py b/pypy/testrunner_cfg.py
--- a/pypy/testrunner_cfg.py
+++ b/pypy/testrunner_cfg.py
@@ -5,6 +5,7 @@
 'translator/c', 'rlib',
 'memory/test', 'jit/metainterp',
 'jit/backend/arm', 'jit/backend/x86',
+'jit/backend/zarch',
 ]
 
 def collect_one_testdir(testdirs, reldir, tests):
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy cffi-embedding-win32: first stab at fixing embedding for win32

2016-01-29 Thread mattip
Author: mattip 
Branch: cffi-embedding-win32
Changeset: r82003:237a8c5c0202
Date: 2016-01-29 16:06 +0200
http://bitbucket.org/pypy/pypy/changeset/237a8c5c0202/

Log:first stab at fixing embedding for win32

diff --git a/pypy/module/_cffi_backend/embedding.py 
b/pypy/module/_cffi_backend/embedding.py
--- a/pypy/module/_cffi_backend/embedding.py
+++ b/pypy/module/_cffi_backend/embedding.py
@@ -84,11 +84,68 @@
 return rffi.cast(rffi.INT, res)
 
 # 
+if os.name == 'nt':
+do_startup = r'''
+#include 
+#define WIN32_LEAN_AND_MEAN
+#include 
+RPY_EXPORTED void rpython_startup_code(void);
+RPY_EXPORTED int pypy_setup_home(char *, int);
 
+static unsigned char _cffi_ready = 0;
+static const char *volatile _cffi_module_name;
 
-eci = ExternalCompilationInfo(separate_module_sources=[
-r"""
-/* XXX Windows missing */
+static void _cffi_init_error(const char *msg, const char *extra)
+{
+fprintf(stderr,
+"\nPyPy initialization failure when loading module '%s':\n%s%s\n",
+_cffi_module_name, msg, extra);
+}
+
+BOOL CALLBACK _cffi_init(PINIT_ONCE InitOnce, PVOID Parameter, PVOID *lpContex)
+{
+
+HMODULE hModule;
+TCHAR home[_MAX_PATH];
+rpython_startup_code();
+RPyGilAllocate();
+
+GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | 
+   GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT,
+   (LPCTSTR)&_cffi_init, &hModule);
+if (hModule == 0 ) {
+/* TODO turn the int into a string with FormatMessage */
+
+_cffi_init_error("dladdr() failed: ", "");
+return TRUE;
+}
+GetModuleFileName(hModule, home, _MAX_PATH);
+if (pypy_setup_home(home, 1) != 0) {
+_cffi_init_error("pypy_setup_home() failed", "");
+return TRUE;
+}
+_cffi_ready = 1;
+fprintf(stderr, "startup succeeded, home %s\n", home);
+return TRUE;
+}
+
+RPY_EXPORTED
+int pypy_carefully_make_gil(const char *name)
+{
+/* For CFFI: this initializes the GIL and loads the home path.
+   It can be called completely concurrently from unrelated threads.
+   It assumes that we don't hold the GIL before (if it exists), and we
+   don't hold it afterwards.
+*/
+static INIT_ONCE s_init_once;
+
+_cffi_module_name = name;/* not really thread-safe, but better than
+nothing */
+InitOnceExecuteOnce(&s_init_once, _cffi_init, NULL, NULL);
+return (int)_cffi_ready - 1;
+}'''
+else:
+do_startup = r"""
 #include 
 #include 
 #include 
@@ -141,6 +198,7 @@
 pthread_once(&once_control, _cffi_init);
 return (int)_cffi_ready - 1;
 }
-"""])
+"""
+eci = ExternalCompilationInfo(separate_module_sources=[do_startup])
 
 declare_c_function = rffi.llexternal_use_eci(eci)
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] extradoc extradoc: Slides

2016-01-29 Thread arigo
Author: Armin Rigo 
Branch: extradoc
Changeset: r5597:a7b5322ad0b4
Date: 2016-01-29 21:51 +0100
http://bitbucket.org/pypy/extradoc/changeset/a7b5322ad0b4/

Log:Slides

diff --git a/talk/fosdem2016/slides b/talk/fosdem2016/slides
new file mode 100644
--- /dev/null
+++ b/talk/fosdem2016/slides
@@ -0,0 +1,405 @@
+=
+CFFI and PyPy
+=
+
+
+CFFI
+
+
+* successful project according to PyPI
+
+* 3.4 million downloads last month
+
+* total 19.2 millions, 27th place on `pypi-ranking.info`
+
+  - Django is 28th
+
+* some high-visibility projects have switched to it (Cryptography)
+
+
+PyPy
+
+
+* harder to say, but probably not so successful
+
+* more later
+
+
+CFFI
+
+
+
+
+CFFI
+
+
+* call C from Python
+
+* CFFI = C Foreign Function Interface
+
+* shares ideas from Cython, ctypes, and LuaJIT's FFI
+
+
+CFFI demo
+=
+
+::
+
+  $ man getpwuid
+
+  SYNOPSIS
+ #include 
+ #include 
+
+ struct passwd *getpwnam(const char *name);
+
+
+CFFI demo
+=
+
+::
+
+   .
+   .
+   .
+   The passwd structure is defined in  as follows:
+
+   struct passwd {
+   char   *pw_name;   /* username */
+   char   *pw_passwd; /* user password */
+   uid_t   pw_uid;/* user ID */
+   .
+   .
+   .
+
+
+CFFI demo
+=
+
+::
+
+  from cffi import FFI
+  ffi = cffi.FFI()
+
+  ffi.cdef("""
+  typedef int... uid_t;
+  struct passwd {
+  uid_t pw_uid;
+  ...;
+  };
+  struct passwd *getpwnam(const char *name);
+  """)
+
+
+CFFI demo
+=
+
+::
+
+  ffi.set_source("_pwuid_cffi", """
+  #include 
+  #include 
+  """)
+
+  ffi.compile()
+
+--- ^^ put that in pwuid_build.py
+
+
+CFFI demo
+=
+
+::
+
+  python pwuid_build.py
+
+creates ``_pwuid_cffi.so``
+
+
+CFFI demo
+=
+
+::
+
+  from _pwuid_cffi import lib
+
+  print lib.getpwnam("arigo").pw_uid
+
+
+CFFI demo
+=
+
+::
+
+  from _pwuid_cffi import ffi, lib
+
+* ``lib`` gives access to all functions from the cdef
+
+* ``ffi`` gives access to a few general helpers, e.g.
+
+   - ``ffi.cast("float", 42)``
+
+   - ``p = ffi.new("struct passwd *")``
+
+   - ``p = ffi.new("char[10]"); p[0] = 'X'; s = lib.getpwnam(p)``
+
+   - ``p = ffi.new_handle(random_obj); ...; random_obj = ffi.from_handle(p)``
+
+
+CFFI
+
+
+* supports more or less the whole C
+
+* there is more than my short explanation suggests
+
+* read the docs: http://cffi.readthedocs.org/
+
+
+
+PyPy
+
+
+
+PyPy
+
+
+* a Python interpreter
+
+* different from the standard, which is CPython
+
+* main goal of PyPy: speed
+
+
+PyPy
+
+
+::
+
+$ pypy
+
+Python 2.7.10 (5f8302b8bf9f, Nov 18 2015, 10:46:46)
+[PyPy 4.0.1 with GCC 4.8.4] on linux2
+Type "help", "copyright", "credits" or "license" for more information.
+ 2+3
+5
+
+
+
+PyPy
+
+
+* run ``pypy my_program.py``
+
+* starts working like an interpreter
+
+* then a Just-in-Time Compiler kicks in
+
+* generate and execute machine code from the Python program
+
+* good or great speed-ups for the majority of long-running code
+
+
+PyPy
+
+
+* different techniques than CPython also for "garbage collection"
+
+* works very well (arguably better than CPython's reference counting)
+
+
+PyPy: Garbage Collection
+
+
+* "**moving,** generational, incremental GC"
+
+* objects don't have reference counters
+
+* allocated in a "nursery"
+
+* when nursery full, find surviving nursery objects and move them out
+
+* usually work on nursery objects only (fast), but rarely also perform
+  a full GC
+
+
+PyPy: C extensions
+==
+
+* PyPy works great for running Python
+
+* less great when there are CPython C extension modules involved
+
+
+PyPy: C extensions
+==
+
+* not directly possible: we have moving, non-reference-counted objects,
+  and the C code expects non-moving, reference-counted objects
+
+
+PyPy: C extensions
+==
+
+* PyPy has still some support for them, called its ``cpyext`` module
+
+* similar to IronPython's Ironclad
+
+* emulate all objects for C extensions with a shadow, non-movable,
+  reference-counted object
+
+
+PyPy: C extensions
+==
+
+* ``cpyext`` is slow
+
+* ``cpyext`` is actually *really, really* slow
+
+  - but we're working on making it *only* slow
+
+
+PyPy: C extensions
+==
+
+* ``cpyext`` will "often" work, but there are a some high-profile C
+  extension modules that are not supported so far
+
+* notably, ``numpy``
+
+* (it is future work)
+
+
+PyPy: ad
+
+
+* but, hey, if you need performance out of Python and don't rely
+  critically on C extension modules, then give PyPy a try
+
+  - typical area where it works well: web services
+
+
+CPython C API: the problem
+==
+
+* CPython comes with a C API
+
+* very large number of functions
+
+* as