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 
10 namespace CPyCppyy {
11 
12 // small number that allows use of stack for argument passing
13 const int SMALL_ARGS_N = 8;
14 
15 #ifndef CPYCPPYY_PARAMETER
16 #define CPYCPPYY_PARAMETER
17 // general place holder for function parameters
18 struct 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
45 struct CallContext {
46  CallContext() : fFlags(0), fCurScope(0), fArgsVec(nullptr), fNArgs(0), fTemps(nullptr) {}
47  CallContext(const CallContext&) = delete;
48  CallContext& operator=(const CallContext&) = delete;
49  ~CallContext() { if (fTemps) Cleanup(); delete fArgsVec; }
50 
51  enum ECallFlags {
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 
95 public:
96 // info/status
97  uint64_t fFlags;
99 
100 private:
101 // payload
103  std::vector<Parameter>* fArgsVec;
104  size_t fNArgs;
107 };
108 
109 inline bool IsSorted(uint64_t flags) {
110  return flags & CallContext::kIsSorted;
111 }
112 
113 inline bool IsCreator(uint64_t flags) {
114  return flags & CallContext::kIsCreator;
115 }
116 
117 inline bool IsConstructor(uint64_t flags) {
118  return flags & CallContext::kIsConstructor;
119 }
120 
121 inline bool HaveImplicit(CallContext* ctxt) {
122  return ctxt ? (!(ctxt->fFlags & CallContext::kNoImplicit) && (ctxt->fFlags & CallContext::kHaveImplicit)) : false;
123 }
124 
125 inline bool AllowImplicit(CallContext* ctxt) {
126  return ctxt ? (!(ctxt->fFlags & CallContext::kNoImplicit) && (ctxt->fFlags & CallContext::kAllowImplicit)) : false;
127 }
128 
129 inline bool NoImplicit(CallContext* ctxt) {
130  return ctxt ? (ctxt->fFlags & CallContext::kNoImplicit) : false;
131 }
132 
133 inline bool ReleasesGIL(CallContext* ctxt) {
134  return ctxt ? (ctxt->fFlags & CallContext::kReleaseGIL) : false;
135 }
136 
137 inline 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
unsigned short fUShort
Definition: callcontext.h:19
bool HaveImplicit(CallContext *ctxt)
Definition: CallContext.h:121
static ECallFlags sMemoryPolicy
Definition: CallContext.h:70
Parameter * GetArgs(size_t sz)
Definition: CallContext.h:80
size_t TCppScope_t
Definition: cpp_cppyy.h:18
void AddTemporary(PyObject *pyobj)
Definition: CallContext.cxx:16
union CPyCppyy::Parameter::Value fValue
static bool SetGlobalSignalPolicy(bool setProtected)
Definition: CallContext.cxx:53
bool IsCreator(uint64_t flags)
Definition: CallContext.h:113
CallContext & operator=(const CallContext &)=delete
bool IsConstructor(uint64_t flags)
Definition: CallContext.h:117
bool NoImplicit(CallContext *ctxt)
Definition: CallContext.h:129
Parameter * GetArgs()
Definition: CallContext.h:88
_object PyObject
Definition: PyMethodBase.h:41
static ECallFlags sSignalPolicy
Definition: CallContext.h:77
uint8_t
Definition: Converters.cxx:858
std::vector< Parameter > * fArgsVec
Definition: CallContext.h:103
Parameter fArgs[SMALL_ARGS_N]
Definition: CallContext.h:102
bool IsSorted(uint64_t flags)
Definition: CallContext.h:109
bool AllowImplicit(CallContext *ctxt)
Definition: CallContext.h:125
you should not use this method at all Int_t Int_t Double_t Double_t Double_t e
Definition: TRolke.cxx:630
Cppyy::TCppScope_t fCurScope
Definition: CallContext.h:98
const int SMALL_ARGS_N
Definition: CallContext.h:13
bool UseStrictOwnership(CallContext *ctxt)
Definition: CallContext.h:137
bool ReleasesGIL(CallContext *ctxt)
Definition: CallContext.h:133
unsigned long long fULLong
Definition: callcontext.h:26
static bool SetMemoryPolicy(ECallFlags e)
Definition: CallContext.cxx:41