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));
106 if (p && p->HasState())
delete p;
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());
290#if PY_VERSION_HEX >= 0x030c0000
291 PyObject *evalue = PyErr_Occurred() ? PyErr_GetRaisedException() :
nullptr;
298 if (PyErr_Occurred()) {
299 PyErr_Fetch(&etype, &evalue, &etrace);
303 const bool isCppExc = evalue && PyType_IsSubtype((PyTypeObject*)etype, &
CPPExcInstance_Type);
310 if (evalue && !isCppExc) {
311#if PY_VERSION_HEX >= 0x030c0000
312 PyObject* tb = PyException_GetTraceback(evalue);
315 PyErr_SetRaisedException(evalue);
320 PyErr_Restore(etype, evalue, etrace);
325 PyObject* descr = PyObject_Str(evalue);
335 PyObject* errtype = etype ? etype : PyExc_TypeError;
342 if (details.empty()) {
343 PyErr_Format(errtype,
"%s =>\n %s: %s", cdoc, cname, cmsg ? cmsg :
"");
345 PyErr_Format(errtype,
"%s =>\n %s: %s (%s)", cdoc, cname, cmsg, details.c_str());
347 PyErr_Format(errtype,
"%s =>\n %s: %s", cdoc, cname, details.c_str());
352 Py_XDECREF(topMessage);
359#if PY_VERSION_HEX >= 0x030c0000
360 PyErr_SetRaisedException(evalue);
362 PyErr_Restore(etype, evalue, etrace);
390 if (
this != &other) {
441 (finalscope.empty() ?
"" :
"::"),
505 for (
int iarg = 0; iarg < (
int)nArgs; ++iarg) {
510 if (strstr(aname.c_str(),
"std::complex"))
514 if (strstr(aname.c_str(),
"bool"))
516 else if (strstr(aname.c_str(),
"long long"))
518 else if (strstr(aname.c_str(),
"long"))
521 else if (strstr(aname.c_str(),
"short"))
525 else if (strstr(aname.c_str(),
"float"))
527 else if (strstr(aname.c_str(),
"long double"))
529 else if (strstr(aname.c_str(),
"double"))
533 else if (strstr(aname.c_str(),
"char") && aname[aname.size()-1] !=
'*')
537 else if (strstr(aname.c_str(),
"void*"))
559 if (aname.find(
"initializer_list") != std::string::npos) {
561 }
else if (aname.rfind(
"&&", aname.size()-2) != std::string::npos) {
565 if (aname[aname.size() - 1] ==
'&')
592 if (!nArgs)
return false;
594 for (
int iarg = 0; iarg < (
int)nArgs; ++iarg) {
596 if (aname.find(
"void*") != 0)
617 PyObject* co_varnames = PyTuple_New(co_argcount+1 );
619 for (
int iarg = 0; iarg < co_argcount; ++iarg) {
622 if (!parname.empty()) {
628 PyTuple_SET_ITEM(co_varnames, iarg+1, pyspec);
641 static PyObject* gbl = PyDict_GetItemString(PySys_GetObject((
char*)
"modules"),
"cppyy.gbl");
644 if (!defvalue.empty()) {
645 PyObject** dctptr = _PyObject_GetDictPtr(gbl);
646 if (!(dctptr && *dctptr))
652 if (defvalue.rfind(
'(') != std::string::npos) {
655 std::string possible_scope = defvalue.substr(0, defvalue.rfind(
'('));
663 if (!scope) PyErr_Clear();
668 defvalue = cand_scope + defvalue.substr(defvalue.rfind(
'('), std::string::npos);
679 char c = defvalue.back();
680 if (
c ==
'F' ||
c ==
'D' ||
c ==
'L') {
682 if (2 < defvalue.size() && defvalue[defvalue.size()-2] ==
'U')
684 defvalue = defvalue.substr(0, defvalue.size()-offset);
685 }
else if (defvalue ==
"true") {
687 }
else if (defvalue ==
"false") {
696 PyObject* pycode = Py_CompileString((
char*)defvalue.c_str(),
"cppyy_default_compiler", Py_eval_input);
698 pyval = PyEval_EvalCode(
699#
if PY_VERSION_HEX < 0x03000000
706 if (!pyval && PyErr_Occurred() && silent) {
752 for (
int i = 0; i <
n; i++) {
753 PyObject *pItem = PyTuple_GetItem(args_tuple, i);
755 PyErr_SetString(PyExc_TypeError,
"argument types should be in string format");
763 if (arg_score >= 10) {
796#if PY_VERSION_HEX >= 0x03080000
797 if (!PyTuple_CheckExact(cargs.
fKwds)) {
803 if (!PyDict_CheckExact(cargs.
fKwds)) {
810 if (nKeys == 0 && !self_in)
829#if PY_VERSION_HEX >= 0x03080000
831 for (
Py_ssize_t ikey = 0; ikey < nKeys; ++ikey) {
832 key = PyTuple_GET_ITEM(cargs.
fKwds, ikey);
833 value = cargs.
fArgs[npos_args+ikey];
836 while (PyDict_Next(cargs.
fKwds, &pos, &key, &value)) {
849 maxpos = p->second > maxpos ? p->second : maxpos;
850 vArgs[p->second] = value;
884 for (
Py_ssize_t i = nArgs; i < maxargs; ++i) {
900#if PY_VERSION_HEX >= 0x03080000
901 if (cargs.
fFlags & PyCallArgs::kDoFree) {
910 cargs.
fArgs = newArgs;
912#if PY_VERSION_HEX >= 0x03080000
913 cargs.
fFlags = PyCallArgs::kDoFree | PyCallArgs::kDoItemDecref;
947#if PY_VERSION_HEX >= 0x03080000
953 cargs.
fArgs = PyTuple_GetSlice(cargs.
fArgs, 1, PyTuple_GET_SIZE(cargs.
fArgs));
968 "unbound method %s::%s must be called with a %s instance as first argument",
990 for (
int i = 0; i < (
int)argc; ++i) {
1015 if (!result && PyErr_Occurred())
1049 PyErr_SetString(PyExc_ReferenceError,
"attempt to access a null-pointer");
1057 ptrdiff_t offset = 0;
1058 if (derived && derived !=
fScope)
1064 derived && pyobj->
ObjectIsA() == derived &&
1096 PyObject *signature_names = PyTuple_New(argcount);
1098 for (
int iarg = 0; iarg < argcount; ++iarg) {
1101 PyTuple_SET_ITEM(signature_names, iarg, argname_py);
1104 return signature_names;
1123 PyObject *signature_types_dict = PyDict_New();
1132 PyObject *parameter_types = PyTuple_New(argcount);
1134 for (
int iarg = 0; iarg < argcount; ++iarg) {
1137 PyTuple_SET_ITEM(parameter_types, iarg, argtype_py);
1142 return signature_types_dict;
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
#define CLING_EXCEPTION_ENDTRY
#define CLING_EXCEPTION_CATCH(n)
#define CLING_EXCEPTION_TRY
Cppyy::TCppType_t ObjectIsA(bool check_smart=true) const
std::string GetReturnTypeName()
PyObject * GetSignature(bool show_formalargs=true) override
bool Initialize(CallContext *ctxt=nullptr)
bool ProcessKwds(PyObject *self_in, PyCallArgs &args)
void SetPyError_(PyObject *msg)
PyObject * GetSignatureNames() override
Returns a tuple with the names of the input parameters of this method.
Cppyy::TCppScope_t fScope
virtual bool ProcessArgs(PyCallArgs &args)
int GetPriority() override
virtual bool InitExecutor_(Executor *&, CallContext *ctxt=nullptr)
int GetArgMatchScore(PyObject *args_tuple) override
std::string GetSignatureString(bool show_formalargs=true)
PyObject * ExecuteProtected(void *, ptrdiff_t, CallContext *)
bool ConvertAndSetArgs(CPyCppyy_PyArgs_t, size_t nargsf, CallContext *ctxt=nullptr)
std::map< std::string, int > * fArgIndices
std::vector< Converter * > fConverters
PyObject * GetTypeName() override
PyObject * GetSignatureTypes() override
Returns a dictionary with the types of the signature of this method.
PyObject * ExecuteFast(void *, ptrdiff_t, CallContext *)
PyObject * Execute(void *self, ptrdiff_t offset, CallContext *ctxt=nullptr)
Cppyy::TCppFuncAddr_t GetFunctionAddress() override
void Copy_(const CPPMethod &)
PyObject * GetCoVarNames() override
PyObject * GetPrototype(bool show_formalargs=true) override
Construct a Python string from the method's prototype.
Cppyy::TCppMethod_t fMethod
PyObject * GetArgDefault(int iarg, bool silent=true) override
int GetMaxArgs() override
bool VerifyArgCount_(Py_ssize_t)
CPPMethod & operator=(const CPPMethod &)
Cppyy::TCppMethod_t GetMethod()
CPPMethod(Cppyy::TCppScope_t scope, Cppyy::TCppMethod_t method)
PyObject * Reflex(Cppyy::Reflex::RequestId_t request, Cppyy::Reflex::FormatId_t=Cppyy::Reflex::OPTIMAL) override
PyObject * Call(CPPInstance *&self, CPyCppyy_PyArgs_t args, size_t nargsf, PyObject *kwds, CallContext *ctxt=nullptr) override
PyObject * GetScopeProxy() override
virtual PyObject * Reflex(Cppyy::Reflex::RequestId_t request, Cppyy::Reflex::FormatId_t format=Cppyy::Reflex::OPTIMAL)
virtual PyObject * GetDocString()
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)
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 uint32_t & GlobalPolicyFlags()