Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
TCallContext.h
Go to the documentation of this file.
1 #ifndef PYROOT_TCALLCONTEXT_H
2 #define PYROOT_TCALLCONTEXT_H
3 
4 // Standard
5 #include <vector>
6 
7 
8 namespace PyROOT {
9 
10 // general place holder for function parameters
11  struct TParameter {
12  union Value {
13  Bool_t fBool;
14  Short_t fShort;
15  UShort_t fUShort;
16  Int_t fInt;
17  UInt_t fUInt;
18  Long_t fLong;
19  ULong_t fULong;
20  Long64_t fLongLong;
21  ULong64_t fULongLong;
22  Float_t fFloat;
23  Double_t fDouble;
24  LongDouble_t fLongDouble;
25  void* fVoidp;
26  } fValue;
27  void* fRef;
28  char fTypeCode;
29  };
30 
31 // extra call information
32  struct TCallContext {
33  TCallContext( std::vector< TParameter >::size_type sz = 0 ) : fArgs( sz ), fFlags( 0 ) {}
34 
35  enum ECallFlags {
36  kNone = 0,
37  kIsSorted = 1, // if method overload priority determined
38  kIsCreator = 2, // if method creates python-owned objects
39  kIsConstructor = 4, // if method is a C++ constructor
40  kUseHeuristics = 8, // if method applies heuristics memory policy
41  kUseStrict = 16, // if method applies strict memory policy
42  kManageSmartPtr = 32, // if executor should manage smart pointers
43  kReleaseGIL = 64, // if method should release the GIL
44  kFast = 128, // if method should NOT handle signals
45  kSafe = 256 // if method should return on signals
46  };
47 
48  // memory handling
49  static ECallFlags sMemoryPolicy;
50  static Bool_t SetMemoryPolicy( ECallFlags e );
51 
52  // signal safety
53  static ECallFlags sSignalPolicy;
54  static Bool_t SetSignalPolicy( ECallFlags e );
55 
56  // payload
57  std::vector< TParameter > fArgs;
58  UInt_t fFlags;
59  };
60 
61  inline Bool_t IsSorted( UInt_t flags ) {
62  return flags & TCallContext::kIsSorted;
63  }
64 
65  inline Bool_t IsCreator( UInt_t flags ) {
66  return flags & TCallContext::kIsCreator;
67  }
68 
69  inline Bool_t IsConstructor( UInt_t flags ) {
70  return flags & TCallContext::kIsConstructor;
71  }
72 
73  inline Bool_t ManagesSmartPtr( TCallContext* ctxt ) {
74  return ctxt->fFlags & TCallContext::kManageSmartPtr;
75  }
76 
77  inline Bool_t ReleasesGIL( UInt_t flags ) {
78  return flags & TCallContext::kReleaseGIL;
79  }
80 
81  inline Bool_t ReleasesGIL( TCallContext* ctxt ) {
82  return ctxt ? (ctxt->fFlags & TCallContext::kReleaseGIL) : kFALSE;
83  }
84 
85  inline Bool_t UseStrictOwnership( TCallContext* ctxt ) {
86  if ( ctxt && (ctxt->fFlags & TCallContext::kUseStrict) )
87  return kTRUE;
88  if ( ctxt && (ctxt->fFlags & TCallContext::kUseHeuristics) )
89  return kFALSE;
90 
91  return TCallContext::sMemoryPolicy == TCallContext::kUseStrict;
92  }
93 
94 } // namespace PyROOT
95 
96 #endif // !PYROOT_TCALLCONTEXT_H