PyPy.h 2.2 KB

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