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// convention to pass flag for direct calls (similar to Python's vector calls)
16#define DIRECT_CALL ((size_t)1 << (8 * sizeof(size_t) - 1))
17
18#ifndef CPYCPPYY_PARAMETER
19#define CPYCPPYY_PARAMETER
20// general place holder for function parameters
21struct Parameter {
22 union Value {
23 bool fBool;
24 int8_t fInt8;
25 int16_t fInt16;
26 int32_t fInt32;
27 uint8_t fUInt8;
28 uint16_t fUInt16;
29 uint32_t fUInt32;
30 short fShort;
31 unsigned short fUShort;
32 int fInt;
33 unsigned int fUInt;
34 long fLong;
35 intptr_t fIntPtr;
36 unsigned long fULong;
37 long long fLLong;
38 unsigned long long fULLong;
39 int64_t fInt64;
40 uint64_t fUInt64;
41 float fFloat;
42 double fDouble;
43 long double fLDouble;
44 void* fVoidp;
45 } fValue;
46 void* fRef;
47 char fTypeCode;
48};
49#endif // CPYCPPYY_PARAMETER
50
51// extra call information
53 CallContext() : fCurScope(0), fPyContext(nullptr), fFlags(0),
54 fArgsVec(nullptr), fNArgs(0), fTemps(nullptr) {}
55 CallContext(const CallContext&) = delete;
57 ~CallContext() { if (fTemps) Cleanup(); delete fArgsVec; }
58
60 kNone = 0x000000,
61 kIsSorted = 0x000001, // if method overload priority determined
62 kIsCreator = 0x000002, // if method creates python-owned objects
63 kIsConstructor = 0x000004, // if method is a C++ constructor
64 kHaveImplicit = 0x000008, // indicate that implicit converters are available
65 kAllowImplicit = 0x000010, // indicate that implicit conversions are allowed
66 kNoImplicit = 0x000020, // disable implicit to prevent recursion
67 kCallDirect = 0x000040, // call wrapped method directly, no inheritance
68 kFromDescr = 0x000080, // initiated from a descriptor
69 kUseHeuristics = 0x000100, // if method applies heuristics memory policy
70 kUseStrict = 0x000200, // if method applies strict memory policy
71 kReleaseGIL = 0x000400, // if method should release the GIL
72 kSetLifeLine = 0x000800, // if return value is part of 'this'
73 kNeverLifeLine = 0x001000, // if the return value is never part of 'this'
74 kPyException = 0x002000, // Python exception during method execution
75 kCppException = 0x004000, // C++ exception during method execution
76 kProtected = 0x008000, // if method should return on signals
77 kUseFFI = 0x010000, // not implemented
78 kIsPseudoFunc = 0x020000, // internal, used for introspection
79 };
80
81// memory handling
83 static bool SetMemoryPolicy(ECallFlags e);
84
86 void Cleanup();
87
88// signal safety
90 static bool SetGlobalSignalPolicy(bool setProtected);
91
92 Parameter* GetArgs(size_t sz) {
93 if (sz != (size_t)-1) fNArgs = sz;
94 if (fNArgs <= SMALL_ARGS_N) return fArgs;
95 if (!fArgsVec) fArgsVec = new std::vector<Parameter>();
96 fArgsVec->resize(fNArgs);
97 return fArgsVec->data();
98 }
99
101 if (fNArgs <= SMALL_ARGS_N) return fArgs;
102 return fArgsVec->data();
103 }
104
105 size_t GetSize() { return fNArgs; }
106 size_t GetEncodedSize() { return fNArgs | ((fFlags & kCallDirect) ? DIRECT_CALL : 0); }
107
108public:
109// info/status
112 uint32_t fFlags;
113
114private:
116
117// payload
119 std::vector<Parameter>* fArgsVec;
120 size_t fNArgs;
122};
123
124inline bool IsSorted(uint64_t flags) {
125 return flags & CallContext::kIsSorted;
126}
127
128inline bool IsCreator(uint64_t flags) {
129 return flags & CallContext::kIsCreator;
130}
131
132inline bool IsConstructor(uint64_t flags) {
133 return flags & CallContext::kIsConstructor;
134}
135
137 return ctxt ? (!(ctxt->fFlags & CallContext::kNoImplicit) && (ctxt->fFlags & CallContext::kHaveImplicit)) : false;
138}
139
141 return ctxt ? (!(ctxt->fFlags & CallContext::kNoImplicit) && (ctxt->fFlags & CallContext::kAllowImplicit)) : false;
142}
143
145 return ctxt ? (ctxt->fFlags & CallContext::kNoImplicit) : false;
146}
147
149 return ctxt ? (ctxt->fFlags & CallContext::kReleaseGIL) : false;
150}
151
153 if (ctxt && (ctxt->fFlags & CallContext::kUseStrict))
154 return true;
155 if (ctxt && (ctxt->fFlags & CallContext::kUseHeuristics))
156 return false;
157
159}
160
161template<CallContext::ECallFlags F>
163public:
171 if (!fPrior) fCtxt->fFlags &= ~F;
172 }
173
174private:
176 bool fPrior;
177};
178
179} // namespace CPyCppyy
180
181#endif // !CPYCPPYY_CALLCONTEXT_H
_object PyObject
#define e(i)
Definition RSha256.hxx:103
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
CallContextRAII(CallContext *ctxt)
CallContextRAII & operator=(const CallContextRAII &)=delete
CallContextRAII(const CallContextRAII &)=delete
#define DIRECT_CALL
#define F(x, y, z)
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:82
static bool SetGlobalSignalPolicy(bool setProtected)
Cppyy::TCppScope_t fCurScope
Parameter * GetArgs(size_t sz)
Definition CallContext.h:92
CallContext & operator=(const CallContext &)=delete
std::vector< Parameter > * fArgsVec
static bool SetMemoryPolicy(ECallFlags e)
Parameter * GetArgs()
Parameter fArgs[SMALL_ARGS_N]
CallContext(const CallContext &)=delete
static ECallFlags sSignalPolicy
Definition CallContext.h:89
void AddTemporary(PyObject *pyobj)
union CPyCppyy::Parameter::Value fValue
unsigned long long fULLong
Definition callcontext.h:26