51 if (fExecutor && fExecutor->HasState())
delete fExecutor;
53 for (
auto p : fConverters) {
54 if (
p &&
p->HasState())
delete p;
60 fArgIndices =
nullptr;
77 }
catch (std::exception&
e) {
91 pyexc_type = PyObject_GetAttrString(parent,
92 parentname.empty() ? finalname.c_str() : finalname.substr(parentname.size()+2, std::string::npos).c_str());
100 PyObject* pyexc_copy = PyObject_CallFunctionObjArgs(pyclass, source,
nullptr);
111 if (pyexc_type && pyexc_obj) {
112 PyErr_SetObject(pyexc_type, pyexc_obj);
113 Py_DECREF(pyexc_obj);
114 Py_DECREF(pyexc_type);
116 PyErr_Format(PyExc_Exception,
"%s (C++ exception)",
e.what());
117 Py_XDECREF(pyexc_obj);
118 Py_XDECREF(pyexc_type);
123 PyErr_SetString(PyExc_Exception,
"unhandled, unknown C++ exception");
130 if (PyErr_Occurred()) {
153 PyErr_SetString(
gBusException,
"bus error in C++; program state was reset");
154 else if (excode == 1)
155 PyErr_SetString(
gSegvException,
"segfault in C++; program state was reset");
156 else if (excode == 4)
157 PyErr_SetString(
gIllException,
"illegal instruction in C++; program state was reset");
158 else if (excode == 5)
159 PyErr_SetString(
gAbrtException,
"abort from C++; program state was reset");
160 else if (excode == 12)
161 PyErr_SetString(PyExc_FloatingPointError,
"floating point exception in C++; program state was reset");
163 PyErr_SetString(PyExc_SystemError,
"problem in C++; program state was reset");
175 fConverters.resize(nArgs);
178 for (
int iarg = 0; iarg < (
int)nArgs; ++iarg) {
182 PyErr_Format(PyExc_TypeError,
"argument type %s not handled", fullType.c_str());
186 fConverters[iarg] = conv;
210 std::stringstream sig; sig <<
"(";
213 for (
int iarg = 0; iarg < (
int)nArgs; ++iarg) {
214 if (count) sig << (fa ?
", " :
",");
220 if (!parname.empty())
221 sig <<
" " << parname;
224 if (!defvalue.empty())
225 sig <<
" = " << defvalue;
237 std::string details{};
239 PyObject *etype =
nullptr, *evalue =
nullptr;
240 if (PyErr_Occurred()) {
243 PyErr_Fetch(&etype, &evalue, &etrace);
246 PyObject* descr = PyObject_Str(evalue);
259 errtype = PyExc_TypeError;
264 if (details.empty()) {
268 PyErr_Format(errtype,
"%s =>\n %s: %s (%s)",
272 PyErr_Format(errtype,
"%s =>\n %s: %s",
284 PyErr_SetObject(errtype, evalue);
297 fMethod(method), fScope(scope), fExecutor(nullptr), fArgIndices(nullptr),
305 PyCallable(other), fMethod(other.fMethod), fScope(other.fScope)
313 if (
this != &other) {
338 GetSignatureString(fa).c_str());
346 std::string rtn = GetReturnTypeName();
389 for (
int iarg = 0; iarg < (
int)nArgs; ++iarg) {
394 if (strstr(aname.c_str(),
"bool"))
396 else if (strstr(aname.c_str(),
"long long"))
398 else if (strstr(aname.c_str(),
"long"))
401 else if (strstr(aname.c_str(),
"short"))
405 else if (strstr(aname.c_str(),
"float"))
407 else if (strstr(aname.c_str(),
"long double"))
409 else if (strstr(aname.c_str(),
"double"))
413 else if (strstr(aname.c_str(),
"char") && aname[aname.size()-1] !=
'*')
417 else if (strstr(aname.c_str(),
"void*"))
439 if (aname.find(
"initializer_list") != std::string::npos) {
441 }
else if (aname.rfind(
"&&", aname.size()-2) != std::string::npos) {
445 if (aname[aname.size() - 1] ==
'&')
472 if (!nArgs)
return false;
474 for (
int iarg = 0; iarg < (
int)nArgs; ++iarg) {
476 if (aname.find(
"void*") != 0)
493 int co_argcount = (
int)GetMaxArgs() ;
497 PyObject* co_varnames = PyTuple_New(co_argcount+1 );
499 for (
int iarg = 0; iarg < co_argcount; ++iarg) {
502 if (!parname.empty()) {
508 PyTuple_SET_ITEM(co_varnames, iarg+1, pyspec);
517 if (iarg >= (
int)GetMaxArgs())
521 if (!defvalue.empty()) {
526 if (!pyval && PyErr_Occurred()) {
568 for (
int i = 0; i <
n; i++) {
569 PyObject *pItem = PyTuple_GetItem(args_tuple, i);
571 PyErr_SetString(PyExc_TypeError,
"argument types should be in string format");
579 if (arg_score >= 10) {
594 if (fArgsRequired != -1)
597 if (!InitConverters_())
600 if (!InitExecutor_(fExecutor, ctxt))
612 if (!PyDict_CheckExact(kwds)) {
617 if (PyDict_Size(kwds) == 0 && !self) {
623 fArgIndices =
new std::map<std::string, int>{};
629 Py_ssize_t nArgs = PyTuple_GET_SIZE(args) + (self ? 1 : 0);
630 if (nKeys+nArgs < fArgsRequired) {
632 "takes at least %d arguments (%zd given)", fArgsRequired, nKeys+nArgs));
636 PyObject* newArgs = PyTuple_New(nArgs+nKeys);
641 PyTuple_SET_ITEM(newArgs, i,
static_cast<PyObject*
>(
nullptr));
647 while (PyDict_Next(kwds, &pos, &key, &
value)) {
653 auto p = fArgIndices->find(ckey);
654 if (
p == fArgIndices->end()) {
661 PyTuple_SetItem(newArgs, (*fArgIndices)[ckey],
value);
668 PyTuple_SET_ITEM(newArgs, 0, self);
673 if (PyTuple_GET_ITEM(newArgs, i)) {
680 PyObject* item = PyTuple_GET_ITEM(args, i);
682 PyTuple_SET_ITEM(newArgs, i, item);
694 if (kwds)
return ProcessKeywords(
nullptr, args, kwds);
700 if (PyTuple_GET_SIZE(args) != 0) {
714 PyObject* newArgs = PyTuple_GetSlice(args, 1, PyTuple_GET_SIZE(args));
718 args = ProcessKeywords(
nullptr, newArgs, kwds);
729 "unbound method %s::%s must be called with a %s instance as first argument",
741 if (argMax != argc) {
745 "takes at least %d arguments (%zd given)", fArgsRequired, argc));
747 }
else if (argMax < argc) {
749 "takes at most %zd arguments (%zd given)", argMax, argc));
763 for (
int i = 0; i < (
int)argc; ++i) {
764 if (!fConverters[i]->SetArg(PyTuple_GET_ITEM(args, i), cppArgs[i], ctxt)) {
796 if (!
result && PyErr_Occurred())
807 if (fArgsRequired == -1 && !Initialize(ctxt))
811 if (!(args = PreProcessArgs(self, args, kwds)))
815 if (fArgsRequired || PyTuple_GET_SIZE(args)) {
816 if (!ConvertAndSetArgs(args, ctxt)) {
827 PyErr_SetString(PyExc_ReferenceError,
"attempt to access a null-pointer");
837 if (derived && derived != fScope)
845 derived && pyobj->
ObjectIsA() == derived &&
#define CPyCppyy_PyText_AsString
#define CPyCppyy_PyText_FromFormat
#define CPyCppyy_PyText_AsStringChecked
#define CPyCppyy_PyText_FromString
#define CPyCppyy_PyText_Check
winID h TVirtualViewer3D TVirtualGLPainter p
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
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 result
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 cname
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void value
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 req_type
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 Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t format
Cppyy::TCppType_t ObjectIsA(bool check_smart=true) const
std::string GetReturnTypeName()
bool Initialize(CallContext *ctxt=nullptr)
void SetPyError_(PyObject *msg)
virtual PyObject * GetSignature(bool show_formalargs=true)
Cppyy::TCppScope_t fScope
virtual PyObject * Reflex(Cppyy::Reflex::RequestId_t request, Cppyy::Reflex::FormatId_t=Cppyy::Reflex::OPTIMAL)
virtual int GetArgMatchScore(PyObject *args_tuple)
virtual bool InitExecutor_(Executor *&, CallContext *ctxt=nullptr)
virtual PyObject * GetArgDefault(int iarg)
virtual PyObject * GetPrototype(bool show_formalargs=true)
std::string GetSignatureString(bool show_formalargs=true)
PyObject * ExecuteProtected(void *, ptrdiff_t, CallContext *)
std::map< std::string, int > * fArgIndices
virtual PyObject * GetCoVarNames()
virtual PyObject * GetScopeProxy()
PyObject * ExecuteFast(void *, ptrdiff_t, CallContext *)
PyObject * Execute(void *self, ptrdiff_t offset, CallContext *ctxt=nullptr)
void Copy_(const CPPMethod &)
virtual int GetPriority()
PyObject * ProcessKeywords(PyObject *self, PyObject *args, PyObject *kwds)
Cppyy::TCppMethod_t fMethod
virtual PyObject * Call(CPPInstance *&self, PyObject *args, PyObject *kwds, CallContext *ctxt=nullptr)
bool ConvertAndSetArgs(PyObject *args, CallContext *ctxt=nullptr)
CPPMethod & operator=(const CPPMethod &)
virtual PyObject * PreProcessArgs(CPPInstance *&self, PyObject *args, PyObject *kwds)
CPPMethod(Cppyy::TCppScope_t scope, Cppyy::TCppMethod_t method)
virtual Cppyy::TCppFuncAddr_t GetFunctionAddress()
virtual PyObject * Reflex(Cppyy::Reflex::RequestId_t request, Cppyy::Reflex::FormatId_t format=Cppyy::Reflex::OPTIMAL)
R__EXTERN PyObject * gName
std::string clean_type(const std::string &cppname, bool template_strip=true, bool const_strip=true)
std::string extract_namespace(const std::string &name)
Set of helper functions that are invoked from the pythonizors, on the Python side.
PyObject * gAbrtException
PyTypeObject CPPExcInstance_Type
PyObject * GetScopeProxy(Cppyy::TCppScope_t)
PyObject * gSegvException
PyObject * BindCppObjectNoCast(Cppyy::TCppObject_t object, Cppyy::TCppType_t klass, const unsigned flags=0)
CPYCPPYY_EXTERN Executor * CreateExecutor(const std::string &name)
bool CPPInstance_Check(T *object)
PyObject * CreateScopeProxy(Cppyy::TCppScope_t)
R__EXTERN PyObject * gThisModule
CPYCPPYY_EXTERN Converter * CreateConverter(const std::string &name, Py_ssize_t *dims=nullptr)
const RequestId_t RETURN_TYPE
const FormatId_t AS_STRING
RPY_EXPORTED TCppIndex_t CompareMethodArgType(TCppMethod_t, TCppIndex_t iarg, const std::string &req_type)
RPY_EXPORTED ptrdiff_t GetBaseOffset(TCppType_t derived, TCppType_t base, TCppObject_t address, int direction, bool rerror=false)
RPY_EXPORTED TCppIndex_t GetMethodReqArgs(TCppMethod_t)
RPY_EXPORTED bool IsEnum(const std::string &type_name)
RPY_EXPORTED std::string GetMethodName(TCppMethod_t)
RPY_EXPORTED TCppScope_t gGlobalScope
RPY_EXPORTED bool IsSubtype(TCppType_t derived, TCppType_t base)
RPY_EXPORTED std::string GetMethodArgName(TCppMethod_t, TCppIndex_t iarg)
RPY_EXPORTED TCppIndex_t GetMethodNumArgs(TCppMethod_t)
RPY_EXPORTED TCppType_t GetActualClass(TCppType_t klass, TCppObject_t obj)
RPY_EXPORTED std::string GetScopedFinalName(TCppType_t type)
RPY_EXPORTED std::string GetMethodArgType(TCppMethod_t, TCppIndex_t iarg)
RPY_EXPORTED bool IsComplete(const std::string &type_name)
RPY_EXPORTED bool IsBuiltin(const std::string &type_name)
RPY_EXPORTED bool IsStaticMethod(TCppMethod_t method)
RPY_EXPORTED TCppScope_t GetScope(const std::string &scope_name)
RPY_EXPORTED bool IsConstMethod(TCppMethod_t)
RPY_EXPORTED TCppFuncAddr_t GetFunctionAddress(TCppMethod_t method, bool check_enabled=true)
RPY_EXPORTED TCppIndex_t GetNumBasesLongestBranch(TCppType_t type)
Retrieve number of base classes in the longest branch of the inheritance tree.
RPY_EXPORTED std::string GetMethodResultType(TCppMethod_t)
RPY_EXPORTED std::string GetFinalName(TCppType_t type)
RPY_EXPORTED std::string GetMethodArgDefault(TCppMethod_t, TCppIndex_t iarg)
Cppyy::TCppScope_t fCurScope
Parameter * GetArgs(size_t sz)
static ECallFlags sSignalPolicy