[pypy-commit] pypy default: Implement another hack
fijal
noreply at buildbot.pypy.org
Fri Feb 28 16:21:54 CET 2014
Author: Maciej Fijalkowski <fijall at gmail.com>
Branch:
Changeset: r69549:85643c8758f1
Date: 2014-02-28 17:21 +0200
http://bitbucket.org/pypy/pypy/changeset/85643c8758f1/
Log: Implement another hack
diff --git a/include/PyPy.h b/include/PyPy.h
--- a/include/PyPy.h
+++ b/include/PyPy.h
@@ -46,6 +46,12 @@
*/
int pypy_execute_source(char *source);
+/* a similar function, but inside Python code it'll register
+ a magic argument c_argument as int, which will be passed as void* from C.
+ Useful for passing pointers to arbitrary structs that contain callbacks
+ to register */
+int pypy_execute_source_ptr(char *source, void* ptr);
+
#ifdef __cplusplus
}
diff --git a/pypy/goal/targetpypystandalone.py b/pypy/goal/targetpypystandalone.py
--- a/pypy/goal/targetpypystandalone.py
+++ b/pypy/goal/targetpypystandalone.py
@@ -129,6 +129,19 @@
if before: before()
return rffi.cast(rffi.INT, res)
+ @entrypoint('main', [rffi.CCHARP, lltype.Signed],
+ c_name='pypy_execute_source_ptr')
+ def pypy_execute_source_ptr(ll_source, ll_ptr):
+ after = rffi.aroundstate.after
+ if after: after()
+ source = rffi.charp2str(ll_source)
+ space.setitem(w_globals, space.wrap('c_argument'),
+ space.wrap(ll_ptr))
+ res = _pypy_execute_source(source)
+ before = rffi.aroundstate.before
+ if before: before()
+ return rffi.cast(rffi.INT, res)
+
@entrypoint('main', [], c_name='pypy_init_threads')
def pypy_init_threads():
if not space.config.objspace.usemodules.thread:
@@ -166,6 +179,7 @@
return 0
return entry_point, {'pypy_execute_source': pypy_execute_source,
+ 'pypy_execute_source_ptr': pypy_execute_source_ptr,
'pypy_init_threads': pypy_init_threads,
'pypy_thread_attach': pypy_thread_attach,
'pypy_setup_home': pypy_setup_home}
More information about the pypy-commit
mailing list