Logo ROOT  
Reference Guide
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;
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), fArgsVec(nullptr), fNArgs(0), fTemps(nullptr) {}
47 CallContext(const CallContext&) = delete;
49 ~CallContext() { if (fTemps) Cleanup(); delete fArgsVec; }
50
52 kNone = 0x0000,
53 kIsSorted = 0x0001, // if method overload priority determined
54 kIsCreator = 0x0002, // if method creates python-owned objects
55 kIsConstructor = 0x0004, // if method is a C++ constructor
56 kHaveImplicit = 0x0008, // indicate that implicit converters are available
57 kAllowImplicit = 0x0010, // indicate that implicit coversions are allowed
58 kNoImplicit = 0x0020, // disable implicit to prevent recursion
59 kUseHeuristics = 0x0040, // if method applies heuristics memory policy
60 kUseStrict = 0x0080, // if method applies strict memory policy
61 kReleaseGIL = 0x0100, // if method should release the GIL
62 kSetLifeline = 0x0200, // if return value is part of 'this'
63 kNeverLifeLine = 0x0400, // if the return value is never part of 'this'
64 kProtected = 0x0800, // if method should return on signals
65 kUseFFI = 0x1000, // not implemented
66 kIsPseudoFunc = 0x2000, // internal, used for introspection
67 };
68
69// memory handling
71 static bool SetMemoryPolicy(ECallFlags e);
72
73 void AddTemporary(PyObject* pyobj);
74 void Cleanup();
75
76// signal safety
78 static bool SetGlobalSignalPolicy(bool setProtected);
79
80 Parameter* GetArgs(size_t sz) {
81 if (sz != (size_t)-1) fNArgs = sz;
82 if (fNArgs <= SMALL_ARGS_N) return fArgs;
83 if (!fArgsVec) fArgsVec = new std::vector<Parameter>();
84 fArgsVec->resize(fNArgs);
85 return fArgsVec->data();
86 }
87
89 if (fNArgs <= SMALL_ARGS_N) return fArgs;
90 return fArgsVec->data();
91 }
92
93 size_t GetSize() { return fNArgs; }
94
95public:
96// info/status
97 uint64_t fFlags;
99
100private:
101// payload
103 std::vector<Parameter>* fArgsVec;
104 size_t fNArgs;
107};
108
109inline bool IsSorted(uint64_t flags) {
110 return flags & CallContext::kIsSorted;
111}
112
113inline bool IsCreator(uint64_t flags) {
114 return flags & CallContext::kIsCreator;
115}
116
117inline bool IsConstructor(uint64_t flags) {
118 return flags & CallContext::kIsConstructor;
119}
120
121inline bool HaveImplicit(CallContext* ctxt) {
122 return ctxt ? (!(ctxt->fFlags & CallContext::kNoImplicit) && (ctxt->fFlags & CallContext::kHaveImplicit)) : false;
123}
124
125inline bool AllowImplicit(CallContext* ctxt) {
126 return ctxt ? (!(ctxt->fFlags & CallContext::kNoImplicit) && (ctxt->fFlags & CallContext::kAllowImplicit)) : false;
127}
128
129inline bool NoImplicit(CallContext* ctxt) {
130 return ctxt ? (ctxt->fFlags & CallContext::kNoImplicit) : false;
131}
132
133inline bool ReleasesGIL(CallContext* ctxt) {
134 return ctxt ? (ctxt->fFlags & CallContext::kReleaseGIL) : false;
135}
136
137inline bool UseStrictOwnership(CallContext* ctxt) {
138 if (ctxt && (ctxt->fFlags & CallContext::kUseStrict))
139 return true;
140 if (ctxt && (ctxt->fFlags & CallContext::kUseHeuristics))
141 return false;
142
144}
145
146} // namespace CPyCppyy
147
148#endif // !CPYCPPYY_CALLCONTEXT_H
uint8_t
Definition: Converters.cxx:858
_object PyObject
Definition: PyMethodBase.h:41
#define e(i)
Definition: RSha256.hxx:103
bool HaveImplicit(CallContext *ctxt)
Definition: CallContext.h:121
bool NoImplicit(CallContext *ctxt)
Definition: CallContext.h:129
const int SMALL_ARGS_N
Definition: CallContext.h:13
bool IsCreator(uint64_t flags)
Definition: CallContext.h:113
bool AllowImplicit(CallContext *ctxt)
Definition: CallContext.h:125
bool UseStrictOwnership(CallContext *ctxt)
Definition: CallContext.h:137
bool IsConstructor(uint64_t flags)
Definition: CallContext.h:117
bool IsSorted(uint64_t flags)
Definition: CallContext.h:109
bool ReleasesGIL(CallContext *ctxt)
Definition: CallContext.h:133
size_t TCppScope_t
Definition: cpp_cppyy.h:18
static ECallFlags sMemoryPolicy
Definition: CallContext.h:70
static bool SetGlobalSignalPolicy(bool setProtected)
Definition: CallContext.cxx:53
Cppyy::TCppScope_t fCurScope
Definition: CallContext.h:98
Parameter * GetArgs(size_t sz)
Definition: CallContext.h:80
CallContext & operator=(const CallContext &)=delete
std::vector< Parameter > * fArgsVec
Definition: CallContext.h:103
static bool SetMemoryPolicy(ECallFlags e)
Definition: CallContext.cxx:41
Parameter * GetArgs()
Definition: CallContext.h:88
Parameter fArgs[SMALL_ARGS_N]
Definition: CallContext.h:102
CallContext(const CallContext &)=delete
static ECallFlags sSignalPolicy
Definition: CallContext.h:77
void AddTemporary(PyObject *pyobj)
Definition: CallContext.cxx:16
union CPyCppyy::Parameter::Value fValue
unsigned long long fULLong
Definition: callcontext.h:26
unsigned short fUShort
Definition: callcontext.h:19