Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
CPPMethod.h
Go to the documentation of this file.
1#ifndef CPYRT_CPPMETHOD_H
2#define CPYRT_CPPMETHOD_H
3
4// Bindings
5#include "PyCallable.h"
6
7// Standard
8#include <string>
9#include <unordered_map>
10#include <vector>
11
12namespace cppjit::cpyrt {
13
14class Executor;
15class Converter;
16
18public:
19 PyCallArgs(CPPInstance*& self, cpyrt_PyArgs_t args, size_t nargsf,
20 PyObject* kwds)
21 : fSelf(self), fArgs(args), fNArgsf(nargsf), fKwds(kwds), fFlags(kNone) {}
23
25 kNone = 0x0000,
26 kIsOffset = 0x0001, // args were offset by 1 to drop self
27 kSelfSwap = 0x0002, // args[-1] and self need swapping
28 kArgsSwap = 0x0004, // args[0] and args[1] need swapping
29 kDoFree = 0x0008, // args need to be free'd (vector call only)
30 kDoItemDecref = 0x0010 // items in args need a decref (vector call only)
31 };
32
33public:
36 size_t fNArgsf;
38 int fFlags;
39};
40
41class CPPMethod : public PyCallable {
42public:
44 CPPMethod(const CPPMethod&);
46 virtual ~CPPMethod();
47
48public:
49 PyObject* GetSignature(bool show_formalargs = true) override;
50 PyObject* GetSignatureNames() override;
51 PyObject* GetSignatureTypes() override;
52 PyObject* GetPrototype(bool show_formalargs = true) override;
53 PyObject* GetTypeName() override;
57
58 int GetPriority() override;
59 bool IsGreedy() override;
60
61 int GetMaxArgs() override;
62 PyObject* GetCoVarNames() override;
63 PyObject* GetArgDefault(int iarg, bool silent = true) override;
64 bool IsConst() override;
65
66 PyObject* GetScopeProxy() override;
68
69 PyCallable* Clone() override { return new CPPMethod(*this); }
70
71 int GetArgMatchScore(PyObject* args_tuple) override;
72
78
79public:
80 PyObject* Call(CPPInstance*& self, cpyrt_PyArgs_t args, size_t nargsf,
81 PyObject* kwds, CallContext* ctxt = nullptr) override;
82
83protected:
84 virtual bool ProcessArgs(PyCallArgs& args);
85
86 bool Initialize(CallContext* ctxt = nullptr);
87 bool ProcessKwds(PyObject* self_in, PyCallArgs& args);
88 bool ConvertAndSetArgs(cpyrt_PyArgs_t, size_t nargsf,
89 CallContext* ctxt = nullptr);
90 PyObject* Execute(void* self, ptrdiff_t offset, CallContext* ctxt = nullptr);
91
95 std::string GetSignatureString(bool show_formalargs = true);
96 std::string GetReturnTypeName();
97
98 virtual bool InitExecutor_(Executor*&, CallContext* ctxt = nullptr);
99
100 // whether fExecutor's result is a real PyObject* (ConstructorExecutor
101 // returns the new object's address instead)
102 virtual bool ResultIsPyObject() const { return true; }
103
104private:
105 void Copy_(const CPPMethod&);
106 void Destroy_();
107 bool VerifyArgCount_(Py_ssize_t);
108
109 PyObject* ExecuteFast(void*, ptrdiff_t, CallContext*);
110
111 bool InitConverters_();
112
113 void SetPyError_(PyObject* msg);
114
115private:
116 // representation
119 // class that declares fMethod, which may be a base of fScope (set by Call)
122
123 // call dispatch buffers
124 std::vector<Converter*> fConverters;
125 std::unordered_map<std::string, int>* fArgIndices;
126
127protected:
128 // cached value that doubles as initialized flag (uninitialized if -1)
130};
131
132} // namespace cppjit::cpyrt
133
134#endif // !CPYRT_CPPMETHOD_H
_object PyObject
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h offset
PyObject * GetTypeName() override
virtual bool InitExecutor_(Executor *&, CallContext *ctxt=nullptr)
int GetArgMatchScore(PyObject *args_tuple) override
bool Initialize(CallContext *ctxt=nullptr)
std::string GetReturnTypeName()
void SetPyError_(PyObject *msg)
PyObject * GetScopeProxy() override
PyObject * GetPrototype(bool show_formalargs=true) override
Construct a Python string from the method's prototype.
bool IsConst() override
PyObject * GetSignatureTypes() override
Returns a dictionary with the types of the signature of this method.
PyObject * Call(CPPInstance *&self, cpyrt_PyArgs_t args, size_t nargsf, PyObject *kwds, CallContext *ctxt=nullptr) override
virtual bool ProcessArgs(PyCallArgs &args)
CPPMethod(interop::TCppScope_t scope, interop::TCppMethod_t method)
Executor * GetExecutor()
Definition CPPMethod.h:94
bool IsSimilarFnType(cppjit::interop::TCppType_t fn_type) override
Definition CPPMethod.h:73
PyObject * Execute(void *self, ptrdiff_t offset, CallContext *ctxt=nullptr)
PyObject * Reflex(interop::Reflex::RequestId_t request, interop::Reflex::FormatId_t=interop::Reflex::OPTIMAL) override
std::unordered_map< std::string, int > * fArgIndices
Definition CPPMethod.h:125
int GetMaxArgs() override
std::string GetSignatureString(bool show_formalargs=true)
interop::TCppMethod_t GetMethod()
Definition CPPMethod.h:92
PyObject * GetCoVarNames() override
interop::TCppFuncAddr_t GetFunctionAddress() override
interop::TCppMethod_t fMethod
Definition CPPMethod.h:117
PyObject * GetSignature(bool show_formalargs=true) override
PyObject * ExecuteFast(void *, ptrdiff_t, CallContext *)
std::vector< Converter * > fConverters
Definition CPPMethod.h:124
bool IsGreedy() override
PyCallable * Clone() override
Definition CPPMethod.h:69
CPPMethod & operator=(const CPPMethod &)
bool VerifyArgCount_(Py_ssize_t)
Definition CPPMethod.cxx:61
interop::TCppScope_t fScope
Definition CPPMethod.h:118
PyObject * GetArgDefault(int iarg, bool silent=true) override
int GetPriority() override
bool ProcessKwds(PyObject *self_in, PyCallArgs &args)
virtual bool ResultIsPyObject() const
Definition CPPMethod.h:102
bool ConvertAndSetArgs(cpyrt_PyArgs_t, size_t nargsf, CallContext *ctxt=nullptr)
interop::TCppScope_t GetScope()
Definition CPPMethod.h:93
PyObject * GetSignatureNames() override
Returns a tuple with the names of the input parameters of this method.
interop::TCppScope_t fDeclaringScope
Definition CPPMethod.h:120
void Copy_(const CPPMethod &)
Definition CPPMethod.cxx:80
PyCallArgs(CPPInstance *&self, cpyrt_PyArgs_t args, size_t nargsf, PyObject *kwds)
Definition CPPMethod.h:19
cpyrt_PyArgs_t fArgs
Definition CPPMethod.h:35
CPPInstance *& fSelf
Definition CPPMethod.h:34
PyObject *const * cpyrt_PyArgs_t
Definition cpyrt.h:81
const FormatId_t OPTIMAL
Definition Reflex.h:22
Cpp::TypeRef TCppType_t
Definition API.h:42
TCppType_t GetTypeFromScope(TCppScope_t klass)
Cpp::FuncRef TCppMethod_t
Definition API.h:44
bool IsSimilarFnTypes(TCppType_t typ1, TCppType_t typ2)
void * TCppFuncAddr_t
Definition API.h:46
Cpp::DeclRef TCppScope_t
Definition API.h:41