51 if (fExecutor && fExecutor->HasState())
delete fExecutor;
53 for (
auto p : fConverters) {
54 if (p && p->HasState())
delete p;
72 }
catch (std::exception&
e) {
86 pyexc_type = PyObject_GetAttrString(parent,
87 parentname.empty() ? finalname.c_str() : finalname.substr(parentname.size()+2, std::string::npos).c_str());
95 PyObject* pyexc_copy = PyObject_CallFunctionObjArgs(pyclass, source,
nullptr);
106 if (pyexc_type && pyexc_obj) {
107 PyErr_SetObject(pyexc_type, pyexc_obj);
108 Py_DECREF(pyexc_obj);
109 Py_DECREF(pyexc_type);
111 PyErr_Format(PyExc_Exception,
"%s (C++ exception)",
e.what());
112 Py_XDECREF(pyexc_obj);
113 Py_XDECREF(pyexc_type);
118 PyErr_SetString(PyExc_Exception,
"unhandled, unknown C++ exception");
125 if (PyErr_Occurred()) {
144 result = ExecuteFast(self, offset, ctxt);
148 PyErr_SetString(
gBusException,
"bus error in C++; program state was reset");
149 else if (excode == 1)
150 PyErr_SetString(
gSegvException,
"segfault in C++; program state was reset");
151 else if (excode == 4)
152 PyErr_SetString(
gIllException,
"illegal instruction in C++; program state was reset");
153 else if (excode == 5)
154 PyErr_SetString(
gAbrtException,
"abort from C++; program state was reset");
155 else if (excode == 12)
156 PyErr_SetString(PyExc_FloatingPointError,
"floating point exception in C++; program state was reset");
158 PyErr_SetString(PyExc_SystemError,
"problem in C++; program state was reset");
170 fConverters.resize(nArgs);
173 for (
int iarg = 0; iarg < (
int)nArgs; ++iarg) {
177 PyErr_Format(PyExc_TypeError,
"argument type %s not handled", fullType.c_str());
181 fConverters[iarg] = conv;
205 std::stringstream sig; sig <<
"(";
208 for (
int iarg = 0; iarg < (
int)nArgs; ++iarg) {
209 if (count) sig << (fa ?
", " :
",");
215 if (!parname.empty())
216 sig <<
" " << parname;
219 if (!defvalue.empty())
220 sig <<
" = " << defvalue;
232 std::string details{};
234 PyObject *etype =
nullptr, *evalue =
nullptr;
235 if (PyErr_Occurred()) {
238 PyErr_Fetch(&etype, &evalue, &etrace);
241 PyObject* descr = PyObject_Str(evalue);
254 errtype = PyExc_TypeError;
259 if (details.empty()) {
263 PyErr_Format(errtype,
"%s =>\n %s: %s (%s)",
267 PyErr_Format(errtype,
"%s =>\n %s: %s",
279 PyErr_SetObject(errtype, evalue);
292 fMethod(method), fScope(scope), fExecutor(nullptr), fArgIndices(nullptr),
300 PyCallable(other), fMethod(other.fMethod), fScope(other.fScope)
308 if (
this != &other) {
333 GetSignatureString(fa).c_str());
363 for (
int iarg = 0; iarg < (
int)nArgs; ++iarg) {
368 if (strstr(aname.c_str(),
"bool"))
370 else if (strstr(aname.c_str(),
"long long"))
372 else if (strstr(aname.c_str(),
"long"))
375 else if (strstr(aname.c_str(),
"short"))
379 else if (strstr(aname.c_str(),
"float"))
381 else if (strstr(aname.c_str(),
"long double"))
383 else if (strstr(aname.c_str(),
"double"))
387 else if (strstr(aname.c_str(),
"char") && aname[aname.size()-1] !=
'*')
391 else if (strstr(aname.c_str(),
"void*"))
413 if (aname.find(
"initializer_list") != std::string::npos) {
415 }
else if (aname.rfind(
"&&", aname.size()-2) != std::string::npos) {
419 if (aname[aname.size() - 1] ==
'&')
446 if (!nArgs)
return false;
448 for (
int iarg = 0; iarg < (
int)nArgs; ++iarg) {
450 if (aname.find(
"void*") != 0)
467 int co_argcount = (
int)GetMaxArgs() ;
471 PyObject* co_varnames = PyTuple_New(co_argcount+1 );
473 for (
int iarg = 0; iarg < co_argcount; ++iarg) {
476 if (!parname.empty()) {
482 PyTuple_SET_ITEM(co_varnames, iarg+1, pyspec);
491 if (iarg >= (
int)GetMaxArgs())
495 if (!defvalue.empty()) {
500 if (!pyval && PyErr_Occurred()) {
531 if (fArgsRequired != -1)
534 if (!InitConverters_())
537 if (!InitExecutor_(fExecutor, ctxt))
549 if (!PyDict_CheckExact(kwds)) {
554 if (PyDict_Size(kwds) == 0 && !self) {
560 fArgIndices =
new std::map<std::string, int>{};
566 Py_ssize_t nArgs = PyTuple_GET_SIZE(args) + (self ? 1 : 0);
567 if (nKeys+nArgs < fArgsRequired) {
569 "takes at least %d arguments (%zd given)", fArgsRequired, nKeys+nArgs));
573 PyObject* newArgs = PyTuple_New(nArgs+nKeys);
578 PyTuple_SET_ITEM(newArgs, i,
nullptr);
584 while (PyDict_Next(kwds, &pos, &key, &value)) {
590 auto p = fArgIndices->find(ckey);
591 if (p == fArgIndices->end()) {
598 PyTuple_SetItem(newArgs, (*fArgIndices)[ckey], value);
605 PyTuple_SET_ITEM(newArgs, 0, self);
610 if (PyTuple_GET_ITEM(newArgs, i)) {
617 PyObject* item = PyTuple_GET_ITEM(args, i);
619 PyTuple_SET_ITEM(newArgs, i, item);
631 if (kwds)
return ProcessKeywords(
nullptr, args, kwds);
637 if (PyTuple_GET_SIZE(args) != 0) {
651 PyObject* newArgs = PyTuple_GetSlice(args, 1, PyTuple_GET_SIZE(args));
655 args = ProcessKeywords(
nullptr, newArgs, kwds);
666 "unbound method %s::%s must be called with a %s instance as first argument",
678 if (argMax != argc) {
682 "takes at least %d arguments (%zd given)", fArgsRequired, argc));
684 }
else if (argMax < argc) {
686 "takes at most %zd arguments (%zd given)", argMax, argc));
700 for (
int i = 0; i < (
int)argc; ++i) {
701 if (!fConverters[i]->SetArg(PyTuple_GET_ITEM(args, i), cppArgs[i], ctxt)) {
720 result = ExecuteFast(self, offset, ctxt);
723 result = ExecuteProtected(self, offset, ctxt);
733 if (!result && PyErr_Occurred())
748 if (!(args = PreProcessArgs(self, args, kwds)))
752 if (fArgsRequired || PyTuple_GET_SIZE(args)) {
753 if (!ConvertAndSetArgs(args, ctxt)) {
764 PyErr_SetString(PyExc_ReferenceError,
"attempt to access a null-pointer");
773 ptrdiff_t offset = 0;
774 if (derived && derived != fScope)
782 derived && pyobj->
ObjectIsA() == derived &&
#define CPyCppyy_PyText_AsString
#define CPyCppyy_PyText_FromFormat
#define CPyCppyy_PyText_AsStringChecked
#define CPyCppyy_PyText_FromString
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 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()
std::string clean_type(const std::string &cppname, bool template_strip=true, bool const_strip=true)
std::string extract_namespace(const std::string &name)
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)
CPYCPPYY_EXTERN Converter * CreateConverter(const std::string &name, Py_ssize_t *dims=nullptr)
RPY_EXPORTED TCppType_t GetActualClass(TCppType_t klass, TCppObject_t obj)
RPY_EXPORTED ptrdiff_t GetBaseOffset(TCppType_t derived, TCppType_t base, TCppObject_t address, int direction, bool rerror=false)
RPY_EXPORTED std::string GetMethodArgDefault(TCppMethod_t, TCppIndex_t iarg)
RPY_EXPORTED bool IsBuiltin(const std::string &type_name)
RPY_EXPORTED bool IsComplete(const std::string &type_name)
RPY_EXPORTED bool IsEnum(const std::string &type_name)
RPY_EXPORTED std::string GetFinalName(TCppType_t type)
RPY_EXPORTED TCppIndex_t GetMethodReqArgs(TCppMethod_t)
RPY_EXPORTED bool IsStaticMethod(TCppMethod_t method)
RPY_EXPORTED std::string GetMethodName(TCppMethod_t)
RPY_EXPORTED TCppIndex_t GetNumBases(TCppType_t type)
RPY_EXPORTED std::string GetMethodArgName(TCppMethod_t, TCppIndex_t iarg)
RPY_EXPORTED bool IsSubtype(TCppType_t derived, TCppType_t base)
RPY_EXPORTED bool IsConstMethod(TCppMethod_t)
RPY_EXPORTED TCppFuncAddr_t GetFunctionAddress(TCppMethod_t method, bool check_enabled=true)
RPY_EXPORTED TCppIndex_t GetMethodNumArgs(TCppMethod_t)
RPY_EXPORTED std::string GetScopedFinalName(TCppType_t type)
RPY_EXPORTED TCppScope_t GetScope(const std::string &scope_name)
RPY_EXPORTED std::string GetMethodResultType(TCppMethod_t)
RPY_EXPORTED TCppScope_t gGlobalScope
RPY_EXPORTED std::string GetMethodArgType(TCppMethod_t, TCppIndex_t iarg)
void Initialize(Bool_t useTMVAStyle=kTRUE)
Cppyy::TCppScope_t fCurScope
Parameter * GetArgs(size_t sz)
static ECallFlags sSignalPolicy