Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
Utility.h
Go to the documentation of this file.
1#ifndef CPYCPPYY_UTILITY_H
2#define CPYCPPYY_UTILITY_H
3
4// Standard
5#include <string>
6#include <vector>
7
8
9namespace CPyCppyy {
10
11class PyCallable;
12
14extern bool gDictLookupActive;
15
16// additional converter functions
17unsigned long PyLongOrInt_AsULong(PyObject* pyobject);
19
20namespace Utility {
21
22// convenience functions for adding methods to classes
23bool AddToClass(PyObject* pyclass, const char* label, PyCFunction cfunc,
24 int flags = METH_VARARGS);
25bool AddToClass(PyObject* pyclass, const char* label, const char* func);
26bool AddToClass(PyObject* pyclass, const char* label, PyCallable* pyfunc);
27
28// helpers for dynamically constructing operators
29PyCallable* FindUnaryOperator(PyObject* pyclass, const char* op);
30PyCallable* FindBinaryOperator(PyObject* left, PyObject* right,
31 const char* op, Cppyy::TCppScope_t scope = 0);
32PyCallable* FindBinaryOperator(const std::string& lcname, const std::string& rcname,
33 const char* op, Cppyy::TCppScope_t scope = 0, bool reverse = false);
34
35// helper for template classes and methods
37std::string ConstructTemplateArgs(
38 PyObject* pyname, PyObject* tpArgs, PyObject* args = nullptr, ArgPreference = kNone, int argoff = 0, int* pcnt = nullptr);
39
40// helper for generating callbacks
41void ConstructCallbackPreamble(const std::string& retType,
42 const std::vector<std::string>& argtypes, std::ostringstream& code);
43void ConstructCallbackReturn(const std::string& retType, int nArgs, std::ostringstream& code);
44
45// initialize proxy type objects
46bool InitProxy(PyObject* module, PyTypeObject* pytype, const char* name);
47
48// retrieve the memory buffer from pyobject, return buflength, tc (optional) is python
49// array.array type code, size is type size, buf will point to buffer, and if check is
50// true, some heuristics will be applied to check buffer compatibility with the type
51Py_ssize_t GetBuffer(PyObject* pyobject, char tc, int size, void*& buf, bool check = true);
52
53// data/operator mappings
54std::string MapOperatorName(const std::string& name, bool bTakesParames);
55
57 PyOperators() : fEq(nullptr), fNe(nullptr), fLAdd(nullptr), fRAdd(nullptr),
58 fSub(nullptr), fLMul(nullptr), fRMul(nullptr), fDiv(nullptr), fHash(nullptr) {}
60
68};
69
70// meta information
71const std::string Compound(const std::string& name);
72Py_ssize_t ArraySize(const std::string& name);
73std::string ClassName(PyObject* pyobj);
74
75// for threading: save call to PyErr_Occurred()
77
78// helpers for collecting/maintaining python exception data
79struct PyError_t {
81
82 static void Clear(PyError_t& e)
83 {
84 // Remove exception information.
85 Py_XDECREF(e.fType); Py_XDECREF(e.fValue); Py_XDECREF(e.fTrace);
86 e.fType = e.fValue = e.fTrace = 0;
87 }
88
90};
91
92size_t FetchError(std::vector<PyError_t>&);
94 std::vector<PyError_t>& errors /* clears */, PyObject* topmsg /* steals ref */, PyObject* defexc);
95
96// setup Python API for callbacks
97bool IncludePython();
98
99} // namespace Utility
100
101} // namespace CPyCppyy
102
103#endif // !CPYCPPYY_UTILITY_H
PyDictEntry *(* dict_lookup_func)(PyDictObject *, PyObject *, long)
Definition CPyCppyy.h:69
int Py_ssize_t
Definition CPyCppyy.h:236
_object PyObject
#define e(i)
Definition RSha256.hxx:103
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
unsigned long long ULong64_t
Definition RtypesCore.h:81
char name[80]
Definition TGX11.cxx:110
#define pyname
PyCallable * FindBinaryOperator(PyObject *left, PyObject *right, const char *op, Cppyy::TCppScope_t scope=0)
Definition Utility.cxx:281
size_t FetchError(std::vector< PyError_t > &)
Definition Utility.cxx:881
void ConstructCallbackPreamble(const std::string &retType, const std::vector< std::string > &argtypes, std::ostringstream &code)
Definition Utility.cxx:518
void ConstructCallbackReturn(const std::string &retType, int nArgs, std::ostringstream &code)
Definition Utility.cxx:562
std::string MapOperatorName(const std::string &name, bool bTakesParames)
Definition Utility.cxx:729
Py_ssize_t GetBuffer(PyObject *pyobject, char tc, int size, void *&buf, bool check=true)
Definition Utility.cxx:615
std::string ConstructTemplateArgs(PyObject *pyname, PyObject *tpArgs, PyObject *args=nullptr, ArgPreference=kNone, int argoff=0, int *pcnt=nullptr)
Definition Utility.cxx:474
PyCallable * FindUnaryOperator(PyObject *pyclass, const char *op)
Definition Utility.cxx:267
void SetDetailedException(std::vector< PyError_t > &errors, PyObject *topmsg, PyObject *defexc)
Definition Utility.cxx:893
bool InitProxy(PyObject *module, PyTypeObject *pytype, const char *name)
Definition Utility.cxx:595
bool AddToClass(PyObject *pyclass, const char *label, PyCFunction cfunc, int flags=METH_VARARGS)
Definition Utility.cxx:170
Py_ssize_t ArraySize(const std::string &name)
Definition Utility.cxx:808
const std::string Compound(const std::string &name)
Definition Utility.cxx:784
std::string ClassName(PyObject *pyobj)
Definition Utility.cxx:827
PyObject * PyErr_Occurred_WithGIL()
Definition Utility.cxx:861
Set of helper functions that are invoked from the pythonizors, on the Python side.
unsigned long PyLongOrInt_AsULong(PyObject *pyobject)
Definition Utility.cxx:131
R__EXTERN bool gDictLookupActive
dict_lookup_func gDictLookupOrg
Definition Utility.cxx:27
ULong64_t PyLongOrInt_AsULong64(PyObject *pyobject)
Definition Utility.cxx:151
size_t TCppScope_t
Definition cpp_cppyy.h:18
static void Clear(PyError_t &e)
Definition Utility.h:82