Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
CallContext.h
Go to the documentation of this file.
1#ifndef CPYCPPYY_CALLCONTEXT_H
2#define CPYCPPYY_CALLCONTEXT_H
3
4// Standard
5#include <vector>
6
7#include <sys/types.h>
8
9
10namespace CPyCppyy {
11
12// small number that allows use of stack for argument passing
13const int SMALL_ARGS_N = 8;
14
15#ifndef CPYCPPYY_PARAMETER
16#define CPYCPPYY_PARAMETER
17// general place holder for function parameters
18struct Parameter {
19 union Value {
20 bool fBool;
21 int8_t fInt8;
22 uint8_t fUInt8;
23 short fShort;
24 unsigned short fUShort;
25 int fInt;
26 unsigned int fUInt;
27 long fLong;
28 intptr_t fIntPtr;
29 unsigned long fULong;
30 long long fLLong;
31 unsigned long long fULLong;
32 int64_t fInt64;
33 uint64_t fUInt64;
34 float fFloat;
35 double fDouble;
36 long double fLDouble;
37 void* fVoidp;
38 } fValue;
39 void* fRef;
40 char fTypeCode;
41};
42#endif // CPYCPPYY_PARAMETER
43
44// extra call information
46 CallContext() : fFlags(0), fCurScope(0), fPyContext(nullptr),
47 fArgsVec(nullptr), fNArgs(0), fTemps(nullptr) {}
48 CallContext(const CallContext&) = delete;
50 ~CallContext() { if (fTemps) Cleanup(); delete fArgsVec; }
51
53 kNone = 0x0000,
54 kIsSorted = 0x0001, // if method overload priority determined
55 kIsCreator = 0x0002, // if method creates python-owned objects
56 kIsConstructor = 0x0004, // if method is a C++ constructor
57 kHaveImplicit = 0x0008, // indicate that implicit converters are available
58 kAllowImplicit = 0x0010, // indicate that implicit coversions are allowed
59 kNoImplicit = 0x0020, // disable implicit to prevent recursion
60 kUseHeuristics = 0x0040, // if method applies heuristics memory policy
61 kUseStrict = 0x0080, // if method applies strict memory policy
62 kReleaseGIL = 0x0100, // if method should release the GIL
63 kSetLifeLine = 0x0200, // if return value is part of 'this'
64 kNeverLifeLine = 0x0400, // if the return value is never part of 'this'
65 kProtected = 0x0800, // if method should return on signals
66 kUseFFI = 0x1000, // not implemented
67 kIsPseudoFunc = 0x2000, // internal, used for introspection
68 };
69
70// memory handling
72 static bool SetMemoryPolicy(ECallFlags e);
73
74 void AddTemporary(PyObject* pyobj);
75 void Cleanup();
76
77// signal safety
79 static bool SetGlobalSignalPolicy(bool setProtected);
80
81 Parameter* GetArgs(size_t sz) {
82 if (sz != (size_t)-1) fNArgs = sz;
83 if (fNArgs <= SMALL_ARGS_N) return fArgs;
84 if (!fArgsVec) fArgsVec = new std::vector<Parameter>();
85 fArgsVec->resize(fNArgs);
86 return fArgsVec->data();
87 }
88
90 if (fNArgs <= SMALL_ARGS_N) return fArgs;
91 return fArgsVec->data();
92 }
93
94 size_t GetSize() { return fNArgs; }
95
96public:
97// info/status
98 uint64_t fFlags;
100 PyObject* fPyContext; // used to set lifelines
101
102private:
103// payload
105 std::vector<Parameter>* fArgsVec;
106 size_t fNArgs;
109};
110
111inline bool IsSorted(uint64_t flags) {
112 return flags & CallContext::kIsSorted;
113}
114
115inline bool IsCreator(uint64_t flags) {
116 return flags & CallContext::kIsCreator;
117}
118
119inline bool IsConstructor(uint64_t flags) {
120 return flags & CallContext::kIsConstructor;
121}
122
123inline bool HaveImplicit(CallContext* ctxt) {
124 return ctxt ? (!(ctxt->fFlags & CallContext::kNoImplicit) && (ctxt->fFlags & CallContext::kHaveImplicit)) : false;
125}
126
127inline bool AllowImplicit(CallContext* ctxt) {
128 return ctxt ? (!(ctxt->fFlags & CallContext::kNoImplicit) && (ctxt->fFlags & CallContext::kAllowImplicit)) : false;
129}
130
131inline bool NoImplicit(CallContext* ctxt) {
132 return ctxt ? (ctxt->fFlags & CallContext::kNoImplicit) : false;
133}
134
135inline bool ReleasesGIL(CallContext* ctxt) {
136 return ctxt ? (ctxt->fFlags & CallContext::kReleaseGIL) : false;
137}
138
139inline bool UseStrictOwnership(CallContext* ctxt) {
140 if (ctxt && (ctxt->fFlags & CallContext::kUseStrict))
141 return true;
142 if (ctxt && (ctxt->fFlags & CallContext::kUseHeuristics))
143 return false;
144
146}
147
148} // namespace CPyCppyy
149
150#endif // !CPYCPPYY_CALLCONTEXT_H
_object PyObject
#define e(i)
Definition RSha256.hxx:103
Set of helper functions that are invoked from the pythonizors, on the Python side.
bool HaveImplicit(CallContext *ctxt)
bool NoImplicit(CallContext *ctxt)
const int SMALL_ARGS_N
Definition CallContext.h:13
bool IsCreator(uint64_t flags)
bool AllowImplicit(CallContext *ctxt)
bool UseStrictOwnership(CallContext *ctxt)
bool IsConstructor(uint64_t flags)
bool IsSorted(uint64_t flags)
bool ReleasesGIL(CallContext *ctxt)
size_t TCppScope_t
Definition cpp_cppyy.h:18
static ECallFlags sMemoryPolicy
Definition CallContext.h:71
static bool SetGlobalSignalPolicy(bool setProtected)
Cppyy::TCppScope_t fCurScope
Definition CallContext.h:99
Parameter * GetArgs(size_t sz)
Definition CallContext.h:81
CallContext & operator=(const CallContext &)=delete
std::vector< Parameter > * fArgsVec
static bool SetMemoryPolicy(ECallFlags e)
Parameter * GetArgs()
Definition CallContext.h:89
Parameter fArgs[SMALL_ARGS_N]
CallContext(const CallContext &)=delete
static ECallFlags sSignalPolicy
Definition CallContext.h:78
void AddTemporary(PyObject *pyobj)
union CPyCppyy::Parameter::Value fValue
unsigned long long fULLong
Definition callcontext.h:26