home *** CD-ROM | disk | FTP | other *** search
/ PC World 2002 May / PCWorld_2002-05_cd.bin / Software / TemaCD / activepython / ActivePython-2.1.1.msi / Python21_include_ceval.h < prev    next >
Encoding:
C/C++ Source or Header  |  2001-07-26  |  3.5 KB  |  122 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(PyObject *) PyEval_GetBuiltins(void);
  26. DL_IMPORT(PyObject *) PyEval_GetGlobals(void);
  27. DL_IMPORT(PyObject *) PyEval_GetLocals(void);
  28. DL_IMPORT(PyObject *) PyEval_GetOwner(void);
  29. DL_IMPORT(PyObject *) PyEval_GetFrame(void);
  30. DL_IMPORT(int) PyEval_GetRestricted(void);
  31. DL_IMPORT(int) PyEval_GetNestedScopes(void);
  32.  
  33. DL_IMPORT(int) Py_FlushLine(void);
  34.  
  35. DL_IMPORT(int) Py_AddPendingCall(int (*func)(void *), void *arg);
  36. DL_IMPORT(int) Py_MakePendingCalls(void);
  37.  
  38. DL_IMPORT(void) Py_SetRecursionLimit(int);
  39. DL_IMPORT(int) Py_GetRecursionLimit(void);
  40.  
  41. /* Interface for threads.
  42.  
  43.    A module that plans to do a blocking system call (or something else
  44.    that lasts a long time and doesn't touch Python data) can allow other
  45.    threads to run as follows:
  46.  
  47.     ...preparations here...
  48.     Py_BEGIN_ALLOW_THREADS
  49.     ...blocking system call here...
  50.     Py_END_ALLOW_THREADS
  51.     ...interpret result here...
  52.  
  53.    The Py_BEGIN_ALLOW_THREADS/Py_END_ALLOW_THREADS pair expands to a
  54.    {}-surrounded block.
  55.    To leave the block in the middle (e.g., with return), you must insert
  56.    a line containing Py_BLOCK_THREADS before the return, e.g.
  57.  
  58.     if (...premature_exit...) {
  59.         Py_BLOCK_THREADS
  60.         PyErr_SetFromErrno(PyExc_IOError);
  61.         return NULL;
  62.     }
  63.  
  64.    An alternative is:
  65.  
  66.     Py_BLOCK_THREADS
  67.     if (...premature_exit...) {
  68.         PyErr_SetFromErrno(PyExc_IOError);
  69.         return NULL;
  70.     }
  71.     Py_UNBLOCK_THREADS
  72.  
  73.    For convenience, that the value of 'errno' is restored across
  74.    Py_END_ALLOW_THREADS and Py_BLOCK_THREADS.
  75.  
  76.    WARNING: NEVER NEST CALLS TO Py_BEGIN_ALLOW_THREADS AND
  77.    Py_END_ALLOW_THREADS!!!
  78.  
  79.    The function PyEval_InitThreads() should be called only from
  80.    initthread() in "threadmodule.c".
  81.  
  82.    Note that not yet all candidates have been converted to use this
  83.    mechanism!
  84. */
  85.  
  86. extern DL_IMPORT(PyThreadState *) PyEval_SaveThread(void);
  87. extern DL_IMPORT(void) PyEval_RestoreThread(PyThreadState *);
  88.  
  89. #ifdef WITH_THREAD
  90.  
  91. extern DL_IMPORT(void) PyEval_InitThreads(void);
  92. extern DL_IMPORT(void) PyEval_AcquireLock(void);
  93. extern DL_IMPORT(void) PyEval_ReleaseLock(void);
  94. extern DL_IMPORT(void) PyEval_AcquireThread(PyThreadState *tstate);
  95. extern DL_IMPORT(void) PyEval_ReleaseThread(PyThreadState *tstate);
  96. extern DL_IMPORT(void) PyEval_ReInitThreads(void);
  97.  
  98. #define Py_BEGIN_ALLOW_THREADS { \
  99.             PyThreadState *_save; \
  100.             _save = PyEval_SaveThread();
  101. #define Py_BLOCK_THREADS    PyEval_RestoreThread(_save);
  102. #define Py_UNBLOCK_THREADS    _save = PyEval_SaveThread();
  103. #define Py_END_ALLOW_THREADS    PyEval_RestoreThread(_save); \
  104.          }
  105.  
  106. #else /* !WITH_THREAD */
  107.  
  108. #define Py_BEGIN_ALLOW_THREADS {
  109. #define Py_BLOCK_THREADS
  110. #define Py_UNBLOCK_THREADS
  111. #define Py_END_ALLOW_THREADS }
  112.  
  113. #endif /* !WITH_THREAD */
  114.  
  115. extern DL_IMPORT(int) _PyEval_SliceIndex(PyObject *, int *);
  116.  
  117.  
  118. #ifdef __cplusplus
  119. }
  120. #endif
  121. #endif /* !Py_CEVAL_H */
  122.