Qucs-S S-parameter Viewer & RF Synthesis Tools
Loading...
Searching...
No Matches
greenlet_internal.hpp
1/* -*- indent-tabs-mode: nil; tab-width: 4; -*- */
2#ifndef GREENLET_INTERNAL_H
3#define GREENLET_INTERNAL_H
4#ifdef __clang__
5# pragma clang diagnostic push
6# pragma clang diagnostic ignored "-Wunused-function"
7#endif
8
14#define PY_SSIZE_T_CLEAN
15#include "greenlet_compiler_compat.hpp"
16#include "greenlet_cpython_compat.hpp"
17#include "greenlet_exceptions.hpp"
18#include "TGreenlet.hpp"
19#include "greenlet_allocator.hpp"
20
21#include <vector>
22#include <string>
23
24#define GREENLET_MODULE
25struct _greenlet;
26typedef struct _greenlet PyGreenlet;
27namespace greenlet {
28
29 class ThreadState;
30 // We can't use the PythonAllocator for this, because we push to it
31 // from the thread state destructor, which doesn't have the GIL,
32 // and Python's allocators can only be called with the GIL.
33 typedef std::vector<ThreadState*> cleanup_queue_t;
34
35};
36
37
38#define implementation_ptr_t greenlet::Greenlet*
39
40
41#include "greenlet.h"
42
43void
44greenlet::refs::MainGreenletExactChecker(void *p)
45{
46 if (!p) {
47 return;
48 }
49 // We control the class of the main greenlet exactly.
50 if (Py_TYPE(p) != &PyGreenlet_Type) {
51 std::string err("MainGreenlet: Expected exactly a greenlet, not a ");
52 err += Py_TYPE(p)->tp_name;
53 throw greenlet::TypeError(err);
54 }
55
56 // Greenlets from dead threads no longer respond to main() with a
57 // true value; so in that case we need to perform an additional
58 // check.
59 Greenlet* g = static_cast<PyGreenlet*>(p)->pimpl;
60 if (g->main()) {
61 return;
62 }
63 if (!dynamic_cast<MainGreenlet*>(g)) {
64 std::string err("MainGreenlet: Expected exactly a main greenlet, not a ");
65 err += Py_TYPE(p)->tp_name;
66 throw greenlet::TypeError(err);
67 }
68}
69
70
71
72template <typename T, greenlet::refs::TypeChecker TC>
74{
75 return reinterpret_cast<PyGreenlet*>(this->p)->pimpl;
76}
77
78template <typename T, greenlet::refs::TypeChecker TC>
80{
81 return reinterpret_cast<PyGreenlet*>(this->p)->pimpl;
82}
83
84#include <memory>
85#include <stdexcept>
86
87
88extern PyTypeObject PyGreenlet_Type;
89
90
91
95static PyObject* green_switch(PyGreenlet* self, PyObject* args, PyObject* kwargs);
96
97
98#ifdef __clang__
99# pragma clang diagnostic pop
100#endif
101
102
103#endif
104
105// Local Variables:
106// flycheck-clang-include-path: ("../../include" "/opt/local/Library/Frameworks/Python.framework/Versions/3.10/include/python3.10")
107// End:
Definition TGreenlet.hpp:343
Definition greenlet_exceptions.hpp:104
Definition greenlet_refs.hpp:560
Definition greenlet_refs.hpp:471
Definition __init__.py:1
Definition greenlet.h:22