26#if PY_VERSION_HEX < 0x030b0000
46 struct InitOperatorMapping_t {
48 InitOperatorMapping_t() {
117#if PY_VERSION_HEX < 0x03000000
138 return (
unsigned long)-1;
140 return (
unsigned long)0;
148 ul = (
unsigned long)i;
151 "can\'t convert negative value to unsigned long");
152 return (
unsigned long)-1;
167 return (
unsigned long)0;
178 "can\'t convert negative value to unsigned long long");
196 pdef->ml_name =
const_cast<char*
>(label);
198 pdef->ml_flags = flags;
199 pdef->ml_doc =
nullptr;
269 std::string
opname =
"operator";
304 bool reverse =
false;
362 &&
lcname.find(
"__wrap_iter") == std::string::npos
378 else {
fname <<
"not_implemented<"; }
416#if PY_VERSION_HEX < 0x03000000
439#if PY_VERSION_HEX < 0x03000000
462 tmpl_name.append(arg ?
"double" :
"float");
466#if PY_VERSION_HEX < 0x03000000
477 std::string
subtype{
"std::initializer_list<"};
490 if (CPPScope_Check(
tn)) {
495 if (CPPInstance_Check(
pyobj)) {
496 if (
pyobj->fFlags & CPPInstance::kIsRValue)
528 std::ostringstream
tpn;
562 for (
auto nn : {PyStrings::gCppName, PyStrings::gName}) {
612 "could not construct C++ name from provided template argument.");
635 const std::vector<std::string>&
argtypes, std::ostringstream& code)
643 code <<
" CPYCPPYY_STATIC std::unique_ptr<CPyCppyy::Converter, std::function<void(CPyCppyy::Converter*)>> "
644 "retconv{CPyCppyy::CreateConverter(\""
645 <<
retType <<
"\"), CPyCppyy::DestroyConverter};\n";
649 code <<
" CPYCPPYY_STATIC std::vector<std::unique_ptr<CPyCppyy::Converter, std::function<void(CPyCppyy::Converter*)>>> argcvs;\n"
650 <<
" if (argcvs.empty()) {\n"
651 <<
" argcvs.reserve(" <<
nArgs <<
");\n";
652 for (
int i = 0; i <
nArgs; ++i) {
654 code <<
" argcvs.emplace_back(CPyCppyy::CreateConverter(\"";
655 const std::string& at =
argtypes[i];
657 const std::string&
cpd = TypeManip::compound(
res_at);
670 code <<
"\"), CPyCppyy::DestroyConverter);\n";
677 code <<
" " <<
retType <<
" ret{};\n";
680 code <<
" PyGILState_STATE state = PyGILState_Ensure();\n";
684 code <<
" std::vector<PyObject*> pyargs;\n";
685 code <<
" pyargs.reserve(" <<
nArgs <<
");\n"
687 for (
int i = 0; i <
nArgs; ++i) {
688 code <<
" pyargs.emplace_back(argcvs[" << i <<
"]->FromMemory((void*)";
690 code <<
"arg" << i <<
"));\n"
691 <<
" if (!pyargs.back()) throw " << i <<
";\n";
693 code <<
" } catch(int) {\n"
694 <<
" for (auto pyarg : pyargs) Py_XDECREF(pyarg);\n"
695 <<
" CPyCppyy::PyException pyexc; PyGILState_Release(state); throw pyexc;\n"
707 code <<
" for (auto pyarg : pyargs) Py_DECREF(pyarg);\n";
708 code <<
" bool cOk = (bool)pyresult;\n"
709 " if (pyresult) {\n";
713 code <<
" if (!CPyCppyy::Instance_IsLively(pyresult))\n"
717 code << (
isVoid ?
"" :
" cOk = retconv->ToMemory(pyresult, (void*)&ret);\n")
718 <<
" Py_DECREF(pyresult);\n }\n";
719 if (
isPtr) code <<
" }\n";
720 code <<
" if (!cOk) {"
724 " /* do nothing */ }\n"
726 " CPyCppyy::PyException pyexc; PyGILState_Release(state); throw pyexc; }\n"
728 " PyGILState_Release(state);\n"
730 code << (
isVoid ?
";\n }\n" :
" ret;\n }\n");
753 std::ostringstream
fname;
756 std::ostringstream code;
757 code <<
"namespace __cppyy_internal { std::function<"
759 <<
"(intptr_t faddr) { return (" <<
retType <<
"(*)" <<
signature <<
")faddr;} }";
783 ((
CPPInstance*)func)->fFlags |= CPPInstance::kIsLValue;
839 || (
sizeof(
long int) ==
sizeof(
int) && ((
tc ==
'I' &&
strchr(
bufinfo.format,
'L')) ||
850 "buffer itemsize (%ld) does not match expected size (%d)",
bufinfo.itemsize,
size);
858 else if (buf &&
bufinfo.ndim == 1)
888#if PY_VERSION_HEX < 0x03000000
898 if (buf &&
check ==
true) {
910 }
else if (buflen ==
size) {
920 (
char*)
"%s and given element size (%ld) do not match needed (%d)",
940 if (8 <
name.size() &&
name.substr(0, 8) ==
"operator") {
941 std::string
op =
name.substr(8, std::string::npos);
944 std::string::size_type start = 0, end =
op.size();
945 while (start < end &&
isspace(
op[start])) ++start;
946 while (start < end &&
isspace(
op[end-1])) --end;
947 op =
op.substr(start, end - start);
964 }
else if (
op ==
"*") {
970 }
else if (
op ==
"/") {
974 }
else if (
op ==
"+") {
980 }
else if (
op ==
"-") {
986 }
else if (
op ==
"++") {
990 }
else if (
op ==
"--") {
1005 std::string
clname =
"<unknown>";
1031 std::string
tt =
"<int>::";
1032 for (
auto c : {
"std::vector",
"std::list",
"std::deque"}) {
1033 for (
auto i : {
"iterator",
"const_iterator"}) {
1035 auto pos =
itname.find(
'<');
1036 if (pos != std::string::npos)
1042 auto pos = classname.find(
'<');
1043 if (pos != std::string::npos)
1068#if PY_VERSION_HEX >= 0x02030000
1145 }
else if (
e.fValue) {
1178 "#include \"CPyCppyy/API.h\"\n"
1181 "#include \"CPyCppyy/DispatchPtr.h\"\n"
1182 "#include \"CPyCppyy/PyException.h\"\n"
PyDictEntry *(* dict_lookup_func)(PyDictObject *, PyObject *, long)
#define CPyCppyy_PyText_InternFromString
#define CPyCppyy_PyText_Append
#define CPyCppyy_PyText_AsString
#define CPyCppyy_PyText_AppendAndDel
void CPyCppyy_PyBuffer_Release(PyObject *, Py_buffer *view)
#define CPyCppyy_PyText_FromFormat
#define CPyCppyy_PyText_FromString
#define CPyCppyy_PyText_Check
unsigned long long PY_ULONG_LONG
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
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
static std::set< std::string > sIteratorTypes
static TC2POperatorMapping_t gC2POperatorMapping
static CPyCppyy::PyCallable * BuildOperator(const std::string &lcname, const std::string &rcname, const char *op, Cppyy::TCppScope_t scope, bool reverse=false)
static std::set< std::string > gOpRemove
static std::map< std::string, PyObject * > sStdFuncMakerLookup
static std::set< std::string > gOpSkip
static std::map< void *, PyObject * > sStdFuncLookup
static bool AddTypeName(std::string &tmpl_name, PyObject *tn, PyObject *arg, CPyCppyy::Utility::ArgPreference pref, int *pcnt=nullptr)
static bool check_scope(const std::string &name)
std::map< std::string, std::string > TC2POperatorMapping_t
static std::string AnnotationAsText(PyObject *pyobj)
const_iterator begin() const
const_iterator end() const
std::string clean_type(const std::string &cppname, bool template_strip=true, bool const_strip=true)
PyCallable * FindBinaryOperator(PyObject *left, PyObject *right, const char *op, Cppyy::TCppScope_t scope=0)
void ConstructCallbackPreamble(const std::string &retType, const std::vector< std::string > &argtypes, std::ostringstream &code)
void ConstructCallbackReturn(const std::string &retType, int nArgs, std::ostringstream &code)
Py_ssize_t GetBuffer(PyObject *pyobject, char tc, int size, void *&buf, bool check=true)
std::string ConstructTemplateArgs(PyObject *pyname, PyObject *tpArgs, PyObject *args=nullptr, ArgPreference=kNone, int argoff=0, int *pcnt=nullptr)
PyObject * FuncPtr2StdFunction(const std::string &retType, const std::string &signature, void *address)
PyCallable * FindUnaryOperator(PyObject *pyclass, const char *op)
size_t FetchError(std::vector< PyError_t > &, bool is_cpp=false)
std::string MapOperatorName(const std::string &name, bool bTakesParames, bool *stubbed=nullptr)
void SetDetailedException(std::vector< PyError_t > &errors, PyObject *topmsg, PyObject *defexc)
bool InitProxy(PyObject *module, PyTypeObject *pytype, const char *name)
bool AddToClass(PyObject *pyclass, const char *label, PyCFunction cfunc, int flags=METH_VARARGS)
bool IsSTLIterator(const std::string &classname)
std::string ClassName(PyObject *pyobj)
PyObject * PyErr_Occurred_WithGIL()
CPPOverload * CPPOverload_New(const std::string &name, std::vector< PyCallable * > &methods)
unsigned long PyLongOrInt_AsULong(PyObject *pyobject)
PyObject * gDefaultObject
PyObject * CustomInstanceMethod_New(PyObject *func, PyObject *self, PyObject *pyclass)
dict_lookup_func gDictLookupOrg
PyObject * CreateScopeProxy(Cppyy::TCppScope_t, const unsigned flags=0)
bool CPPOverload_Check(T *object)
bool CPPScope_Check(T *object)
PY_ULONG_LONG PyLongOrInt_AsULong64(PyObject *pyobject)
bool CPPInstance_Check(T *object)
PyObject * gNullPtrObject
RPY_EXPORTED bool Compile(const std::string &code, bool silent=false)
RPY_EXPORTED TCppScope_t gGlobalScope
RPY_EXPORTED TCppMethod_t GetMethodTemplate(TCppScope_t scope, const std::string &name, const std::string &proto)
RPY_EXPORTED std::string ResolveName(const std::string &cppitem_name)
RPY_EXPORTED std::string GetScopedFinalName(TCppType_t type)
RPY_EXPORTED TCppMethod_t GetMethod(TCppScope_t scope, TCppIndex_t imeth)
RPY_EXPORTED TCppScope_t GetScope(const std::string &scope_name)
RPY_EXPORTED TCppIndex_t GetGlobalOperator(TCppType_t scope, const std::string &lc, const std::string &rc, const std::string &op)
static void Clear(PyError_t &e)