Debian Codegraph @

pypy/doc/pypy.h.rst

raw
1 :orphan:
2
3 .. code-block:: c
4
5 #ifndef _PYPY_H_
6 #define _PYPY_H_
7
8 /* This header is meant to be included in programs that use PyPy as an
9 embedded library.
10
11 NOTE: this is deprecated. Instead, use cffi's embedding support:
12 http://cffi.readthedocs.org/en/latest/embedding.html
13 */
14
15 #ifdef __cplusplus
16 extern "C" {
17 #endif
18
19 // call this first
20 void rpython_startup_code(void);
21
22 // pypy_init_threads has to be called in case you want to use threads
23 void pypy_init_threads(void);
24
25 /* Initialize the home directory of PyPy. It is necessary to call this.
26
27 Call it with "home" being the file name of the libpypy.so, for
28 example; it will be used as a starting point when searching for the
29 lib-python and lib_pypy directories. They are searched from
30 "home/..", "home/../..", etc. Returns 0 if everything was fine. If
31 an error occurs, returns 1 and (if verbose != 0) prints some
32 information to stderr.
33 */
34 int pypy_setup_home(char *home, int verbose);
35
36
37 /* If your program has multiple threads, then you need to call
38 pypy_thread_attach() once in each other thread that just started
39 and in which you want to run Python code (including via callbacks,
40 see below). DO NOT CALL IT IN THE MAIN THREAD
41 */
42 void pypy_thread_attach(void);
43
44
45 /* The main entry point: executes "source" as plain Python code.
46 Returns 0 if everything was fine. If a Python exception is
47 uncaught, it is printed to stderr and 1 is returned.
48
49 Usually, the Python code from "source" should use cffi to fill in
50 global variables of "function pointer" type in your program. Use
51 cffi callbacks to do so. Once it is done, there is no need to call
52 pypy_execute_source() any more: from C, you call directly the
53 functions (which are "callbacks" from the point of view of Python).
54 */
55 int pypy_execute_source(char *source);
56
57 /* a similar function, but inside Python code it'll register
58 a magic argument c_argument as int, which will be passed as void* from C.
59 Useful for passing pointers to arbitrary structs that contain callbacks
60 to register */
61 int pypy_execute_source_ptr(char *source, void* ptr);
62
63
64 /* The 3.x versions of PyPy don't include the Windows pragma to
65 automatically link python3?.lib. This is apparently not commonly
66 done on Windows anyway. */
67
68
69 #ifdef __cplusplus
70 }
71 #endif
72
73 #endif