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