home *** CD-ROM | disk | FTP | other *** search
/ Freelog 33 / Freelog033.iso / Progr / Python-2.2.1.exe / CEVAL.H < prev    next >
Encoding:
C/C++ Source or Header  |  2001-08-02  |  3.9 KB  |  132 lines

  1. #ifndef Py_CEVAL_H
  2. #define Py_CEVAL_H
  3. #ifdef __cplusplus
  4. extern "C" {
  5. #endif
  6.  
  7.  
  8. /* Interface to random parts in ceval.c */
  9.  
  10. DL_IMPORT(PyObject *) PyEval_CallObjectWithKeywords
  11.     (PyObject *, PyObject *, PyObject *);
  12.  
  13. /* DLL-level Backwards compatibility: */
  14. #undef PyEval_CallObject
  15. DL_IMPORT(PyObject *) PyEval_CallObject(PyObject *, PyObject *);
  16.  
  17. /* Inline this */
  18. #define PyEval_CallObject(func,arg) \
  19.         PyEval_CallObjectWithKeywords(func, arg, (PyObject *)NULL)
  20.  
  21. DL_IMPORT(PyObject *) PyEval_CallFunction(PyObject *obj, char *format, ...);
  22. DL_IMPORT(PyObject *) PyEval_CallMethod(PyObject *obj,
  23.                                         char *methodname, char *format, ...);
  24.  
  25. DL_IMPORT(void) PyEval_SetProfile(Py_tracefunc, PyObject *);
  26. DL_IMPORT(void) PyEval_SetTrace(Py_tracefunc, PyObject *);
  27.  
  28. DL_IMPORT(PyObject *) PyEval_GetBuiltins(void);
  29. DL_IMPORT(PyObject *) PyEval_GetGlobals(void);
  30. DL_IMPORT(PyObject *) PyEval_GetLocals(void);
  31. DL_IMPORT(PyObject *) PyEval_GetOwner(void);
  32. DL_IMPORT(PyObject *) PyEval_GetFrame(void);
  33. DL_IMPORT(int) PyEval_GetRestricted(void);
  34.  
  35. /* Look at the current frame's (if any) code's co_flags, and turn on
  36.    the corresponding compiler flags in cf->cf_flags.  Return 1 if any
  37.    flag was set, else return 0. */
  38. DL_IMPORT(int) PyEval_MergeCompilerFlags(PyCompilerFlags *cf);
  39.  
  40. DL_IMPORT(int) Py_FlushLine(void);
  41.  
  42. DL_IMPORT(int) Py_AddPendingCall(int (*func)(void *), void *arg);
  43. DL_IMPORT(int) Py_MakePendingCalls(void);
  44.  
  45. DL_IMPORT(void) Py_SetRecursionLimit(int);
  46. DL_IMPORT(int) Py_GetRecursionLimit(void);
  47.  
  48. DL_IMPORT(char *) PyEval_GetFuncName(PyObject *);
  49. DL_IMPORT(char *) PyEval_GetFuncDesc(PyObject *);
  50.  
  51. /* Interface for threads.
  52.  
  53.    A module that plans to do a blocking system call (or something else
  54.    that lasts a long time and doesn't touch Python data) can allow other
  55.    threads to run as follows:
  56.  
  57.     ...preparations here...
  58.     Py_BEGIN_ALLOW_THREADS
  59.     ...blocking system call here...
  60.     Py_END_ALLOW_THREADS
  61.     ...interpret result here...
  62.  
  63.    The Py_BEGIN_ALLOW_THREADS/Py_END_ALLOW_THREADS pair expands to a
  64.    {}-surrounded block.
  65.    To leave the block in the middle (e.g., with return), you must insert
  66.    a line containing Py_BLOCK_THREADS before the return, e.g.
  67.  
  68.     if (...premature_exit...) {
  69.         Py_BLOCK_THREADS
  70.         PyErr_SetFromErrno(PyExc_IOError);
  71.         return NULL;
  72.     }
  73.  
  74.    An alternative is:
  75.  
  76.     Py_BLOCK_THREADS
  77.     if (...premature_exit...) {
  78.         PyErr_SetFromErrno(PyExc_IOError);
  79.         return NULL;
  80.     }
  81.     Py_UNBLOCK_THREADS
  82.  
  83.    For convenience, that the value of 'errno' is restored across
  84.    Py_END_ALLOW_THREADS and Py_BLOCK_THREADS.
  85.  
  86.    WARNING: NEVER NEST CALLS TO Py_BEGIN_ALLOW_THREADS AND
  87.    Py_END_ALLOW_THREADS!!!
  88.  
  89.    The function PyEval_InitThreads() should be called only from
  90.    initthread() in "threadmodule.c".
  91.  
  92.    Note that not yet all candidates have been converted to use this
  93.    mechanism!
  94. */
  95.  
  96. extern DL_IMPORT(PyThreadState *) PyEval_SaveThread(void);
  97. extern DL_IMPORT(void) PyEval_RestoreThread(PyThreadState *);
  98.  
  99. #ifdef WITH_THREAD
  100.  
  101. extern DL_IMPORT(void) PyEval_InitThreads(void);
  102. extern DL_IMPORT(void) PyEval_AcquireLock(void);
  103. extern DL_IMPORT(void) PyEval_ReleaseLock(void);
  104. extern DL_IMPORT(void) PyEval_AcquireThread(PyThreadState *tstate);
  105. extern DL_IMPORT(void) PyEval_ReleaseThread(PyThreadState *tstate);
  106. extern DL_IMPORT(void) PyEval_ReInitThreads(void);
  107.  
  108. #define Py_BEGIN_ALLOW_THREADS { \
  109.             PyThreadState *_save; \
  110.             _save = PyEval_SaveThread();
  111. #define Py_BLOCK_THREADS    PyEval_RestoreThread(_save);
  112. #define Py_UNBLOCK_THREADS    _save = PyEval_SaveThread();
  113. #define Py_END_ALLOW_THREADS    PyEval_RestoreThread(_save); \
  114.          }
  115.  
  116. #else /* !WITH_THREAD */
  117.  
  118. #define Py_BEGIN_ALLOW_THREADS {
  119. #define Py_BLOCK_THREADS
  120. #define Py_UNBLOCK_THREADS
  121. #define Py_END_ALLOW_THREADS }
  122.  
  123. #endif /* !WITH_THREAD */
  124.  
  125. extern DL_IMPORT(int) _PyEval_SliceIndex(PyObject *, int *);
  126.  
  127.  
  128. #ifdef __cplusplus
  129. }
  130. #endif
  131. #endif /* !Py_CEVAL_H */
  132.