43#if PY_VERSION_HEX >= 0x03080000
46 if (
fFlags & kDoItemDecref) {
52 PyMem_Free((
void*)
fArgs);
62 std::swap(PyTuple_GET_ITEM(
fArgs, 0), PyTuple_GET_ITEM(
fArgs, 1));
73 if (maxargs != actual) {
76 "takes at least %d arguments (%zd given)", fArgsRequired, actual));
78 }
else if (maxargs < actual) {
80 "takes at most %zd arguments (%zd given)", maxargs, actual));
94 fArgIndices =
nullptr;
102 if (fExecutor && fExecutor->HasState())
delete fExecutor;
106 if (
p &&
p->HasState())
delete p;
110 delete fArgIndices; fArgIndices =
nullptr;
127 }
catch (std::exception&
e) {
143 pyexc_type = PyObject_GetAttrString(parent,
144 parentname.empty() ? finalname.c_str() : finalname.substr(parentname.size()+2, std::string::npos).c_str());
152 PyObject* pyexc_copy = PyObject_CallFunctionObjArgs(pyclass, source,
nullptr);
163 if (pyexc_type && pyexc_obj) {
164 PyErr_SetObject(pyexc_type, pyexc_obj);
165 Py_DECREF(pyexc_obj);
166 Py_DECREF(pyexc_type);
168 PyErr_Format(PyExc_Exception,
"%s (C++ exception)",
e.what());
169 Py_XDECREF(pyexc_obj);
170 Py_XDECREF(pyexc_type);
177 PyErr_SetString(PyExc_Exception,
"unhandled, unknown C++ exception");
184 if (PyErr_Occurred()) {
206 if (PyErr_Occurred()) {
207 std::cerr <<
"Python exception outstanding during C++ longjmp:" << std::endl;
209 std::cerr << std::endl;
214 PyErr_SetString(
gBusException,
"bus error in C++; program state was reset");
215 else if (excode == 1)
216 PyErr_SetString(
gSegvException,
"segfault in C++; program state was reset");
217 else if (excode == 4)
218 PyErr_SetString(
gIllException,
"illegal instruction in C++; program state was reset");
219 else if (excode == 5)
220 PyErr_SetString(
gAbrtException,
"abort from C++; program state was reset");
221 else if (excode == 12)
222 PyErr_SetString(PyExc_FloatingPointError,
"floating point exception in C++; program state was reset");
224 PyErr_SetString(PyExc_SystemError,
"problem in C++; program state was reset");
239 for (
int iarg = 0; iarg < (
int)nArgs; ++iarg) {
243 PyErr_Format(PyExc_TypeError,
"argument type %s not handled", fullType.c_str());
278 std::string details{};
280 PyObject *etype =
nullptr, *evalue =
nullptr;
281 if (PyErr_Occurred()) {
284 PyErr_Fetch(&etype, &evalue, &etrace);
287 PyObject* descr = PyObject_Str(evalue);
300 errtype = PyExc_TypeError;
305 if (details.empty()) {
309 PyErr_Format(errtype,
"%s =>\n %s: %s (%s)",
313 PyErr_Format(errtype,
"%s =>\n %s: %s",
325 PyErr_SetObject(errtype, evalue);
338 fMethod(method), fScope(scope), fExecutor(nullptr), fArgIndices(nullptr),
346 PyCallable(other), fMethod(other.fMethod), fScope(other.fScope)
354 if (
this != &other) {
405 (finalscope.empty() ?
"" :
"::"),
407 GetSignatureString(fa).c_str());
424 std::string rtn = GetReturnTypeName();
467 for (
int iarg = 0; iarg < (
int)nArgs; ++iarg) {
472 if (strstr(aname.c_str(),
"std::complex"))
476 if (strstr(aname.c_str(),
"bool"))
478 else if (strstr(aname.c_str(),
"long long"))
480 else if (strstr(aname.c_str(),
"long"))
483 else if (strstr(aname.c_str(),
"short"))
487 else if (strstr(aname.c_str(),
"float"))
489 else if (strstr(aname.c_str(),
"long double"))
491 else if (strstr(aname.c_str(),
"double"))
495 else if (strstr(aname.c_str(),
"char") && aname[aname.size()-1] !=
'*')
499 else if (strstr(aname.c_str(),
"void*"))
521 if (aname.find(
"initializer_list") != std::string::npos) {
523 }
else if (aname.rfind(
"&&", aname.size()-2) != std::string::npos) {
527 if (aname[aname.size() - 1] ==
'&')
554 if (!nArgs)
return false;
556 for (
int iarg = 0; iarg < (
int)nArgs; ++iarg) {
558 if (aname.find(
"void*") != 0)
575 int co_argcount = (
int)GetMaxArgs() ;
579 PyObject* co_varnames = PyTuple_New(co_argcount+1 );
581 for (
int iarg = 0; iarg < co_argcount; ++iarg) {
584 if (!parname.empty()) {
590 PyTuple_SET_ITEM(co_varnames, iarg+1, pyspec);
599 if (iarg >= (
int)GetMaxArgs())
603 static PyObject* gbl = PyDict_GetItemString(PySys_GetObject((
char*)
"modules"),
"cppyy.gbl");
606 if (!defvalue.empty()) {
607 PyObject** dctptr = _PyObject_GetDictPtr(gbl);
608 if (!(dctptr && *dctptr))
614 if (defvalue.find(
"::") != std::string::npos) {
617 if (!scope) PyErr_Clear();
626 char c = defvalue.back();
627 if (
c ==
'F' ||
c ==
'D' ||
c ==
'L') {
629 if (2 < defvalue.size() && defvalue[defvalue.size()-2] ==
'U')
631 defvalue = defvalue.substr(0, defvalue.size()-
offset);
639 PyObject* pycode = Py_CompileString((
char*)defvalue.c_str(),
"cppyy_default_compiler", Py_eval_input);
641 pyval = PyEval_EvalCode(
642#
if PY_VERSION_HEX < 0x03000000
649 if (!pyval && PyErr_Occurred() && silent) {
658 PyErr_Format(PyExc_TypeError,
"Could not construct default value for: %s",
Cppyy::GetMethodArgName(fMethod, iarg).c_str());
695 for (
int i = 0; i <
n; i++) {
696 PyObject *pItem = PyTuple_GetItem(args_tuple, i);
698 PyErr_SetString(PyExc_TypeError,
"argument types should be in string format");
706 if (arg_score >= 10) {
721 if (fArgsRequired != -1)
724 if (!InitConverters_())
727 if (!InitExecutor_(fExecutor, ctxt))
739#if PY_VERSION_HEX >= 0x03080000
740 if (!PyTuple_CheckExact(cargs.
fKwds)) {
746 if (!PyDict_CheckExact(cargs.
fKwds)) {
753 if (nKeys == 0 && !self_in)
757 fArgIndices =
new std::map<std::string, int>{};
763 if (!VerifyArgCount_(nArgs+nKeys))
772#if PY_VERSION_HEX >= 0x03080000
774 for (
Py_ssize_t ikey = 0; ikey < nKeys; ++ikey) {
775 key = PyTuple_GET_ITEM(cargs.
fKwds, ikey);
779 while (PyDict_Next(cargs.
fKwds, &pos, &key, &
value)) {
785 auto p = fArgIndices->find(ckey);
786 if (
p == fArgIndices->end()) {
792 maxpos =
p->second > maxpos ?
p->second : maxpos;
827 for (
Py_ssize_t i = nArgs; i < maxargs; ++i) {
834 item = GetArgDefault((
int)i,
false );
843#if PY_VERSION_HEX >= 0x03080000
844 if (cargs.
fFlags & PyCallArgs::kDoFree) {
853 cargs.
fArgs = newArgs;
855#if PY_VERSION_HEX >= 0x03080000
856 cargs.
fFlags = PyCallArgs::kDoFree | PyCallArgs::kDoItemDecref;
869 if (cargs.
fKwds) {
return ProcessKwds(
nullptr, cargs); }
890#if PY_VERSION_HEX >= 0x03080000
896 cargs.
fArgs = PyTuple_GetSlice(cargs.
fArgs, 1, PyTuple_GET_SIZE(cargs.
fArgs));
903 return ProcessKwds(
nullptr, cargs);
911 "unbound method %s::%s must be called with a %s instance as first argument",
921 if (!VerifyArgCount_(argc))
933 for (
int i = 0; i < (
int)argc; ++i) {
966 if (!
result && PyErr_Occurred())
977 if (fArgsRequired == -1 && !Initialize(ctxt))
982 if (!ProcessArgs(cargs))
991 if (!ConvertAndSetArgs(cargs.
fArgs, cargs.
fNArgsf, ctxt))
1000 PyErr_SetString(PyExc_ReferenceError,
"attempt to access a null-pointer");
1009 if (derived && derived != fScope)
1015 derived && pyobj->
ObjectIsA() == derived &&
static void CPyCppyy_PyArgs_DEL(CPyCppyy_PyArgs_t args)
static PyObject * CPyCppyy_PyArgs_SET_ITEM(CPyCppyy_PyArgs_t args, Py_ssize_t i, PyObject *item)
#define CPyCppyy_PyText_AsString
static Py_ssize_t CPyCppyy_PyArgs_GET_SIZE(CPyCppyy_PyArgs_t args, size_t)
PyObject * CPyCppyy_PyArgs_t
#define CPyCppyy_PyText_AppendAndDel
#define CPyCppyy_PyText_FromFormat
#define CPyCppyy_PyText_AsStringChecked
static CPyCppyy_PyArgs_t CPyCppyy_PyArgs_New(Py_ssize_t N)
#define CPyCppyy_PyText_FromString
static PyObject * CPyCppyy_PyArgs_GET_ITEM(CPyCppyy_PyArgs_t args, Py_ssize_t i)
#define CPyCppyy_PyText_Check
std::vector< Converter * > fConverters
#define CLING_EXCEPTION_ENDTRY
#define CLING_EXCEPTION_CATCH(n)
#define CLING_EXCEPTION_TRY
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)
bool ProcessKwds(PyObject *self_in, PyCallArgs &args)
void SetPyError_(PyObject *msg)
virtual PyObject * GetSignature(bool show_formalargs=true)
Cppyy::TCppScope_t fScope
virtual bool ProcessArgs(PyCallArgs &args)
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 * GetPrototype(bool show_formalargs=true)
Construct a Python string from the method's prototype.
std::string GetSignatureString(bool show_formalargs=true)
PyObject * ExecuteProtected(void *, ptrdiff_t, CallContext *)
bool ConvertAndSetArgs(CPyCppyy_PyArgs_t, size_t nargsf, CallContext *ctxt=nullptr)
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()
Cppyy::TCppMethod_t fMethod
virtual PyObject * Call(CPPInstance *&self, CPyCppyy_PyArgs_t args, size_t nargsf, PyObject *kwds, CallContext *ctxt=nullptr)
virtual PyObject * GetArgDefault(int iarg, bool silent=true)
bool VerifyArgCount_(Py_ssize_t)
CPPMethod & operator=(const CPPMethod &)
CPPMethod(Cppyy::TCppScope_t scope, Cppyy::TCppMethod_t method)
virtual PyObject * GetTypeName()
virtual Cppyy::TCppFuncAddr_t GetFunctionAddress()
virtual PyObject * Reflex(Cppyy::Reflex::RequestId_t request, Cppyy::Reflex::FormatId_t format=Cppyy::Reflex::OPTIMAL)
void cppscope_to_pyscope(std::string &cppscope)
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 * CreateScopeProxy(Cppyy::TCppScope_t, const unsigned flags=0)
PyObject * gSegvException
PyObject * BindCppObjectNoCast(Cppyy::TCppObject_t object, Cppyy::TCppType_t klass, const unsigned flags=0)
CPYCPPYY_EXTERN Executor * CreateExecutor(const std::string &name, cdims_t=0)
bool CPPInstance_Check(T *object)
CPYCPPYY_EXTERN Converter * CreateConverter(const std::string &name, cdims_t=0)
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 std::string GetMethodSignature(TCppMethod_t, bool show_formalargs, TCppIndex_t maxargs=(TCppIndex_t) -1)
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