19 #include "TInterpreter.h"
31 if ( PyBytes_Check( pyobject ) )
35 PyBufferProcs* bufprocs = Py_TYPE(pyobject)->tp_as_buffer;
37 PySequenceMethods* seqmeths = Py_TYPE(pyobject)->tp_as_sequence;
38 if ( seqmeths != 0 && bufprocs != 0
39 && bufprocs->bf_getbuffer != 0
44 (*(bufprocs->bf_getbuffer))( pyobject, &bufinfo, PyBUF_WRITABLE );
45 buf = (
char*)bufinfo.buf;
46 Py_ssize_t buflen = bufinfo.len;
50 PyObject* pytc = PyObject_GetAttrString( pyobject,
"typecode");
52 const char*
s = PyUnicode_AsUTF8AndSize( pytc,
nullptr );
53 if (
s &&
s[0] != tc )
56 }
else if ( seqmeths->sq_length &&
57 (
int)(buflen / (*(seqmeths->sq_length))( pyobject )) ==
size ) {
60 }
else if ( buflen ==
size ) {
67 PyObject* pytype = 0, *pyvalue = 0, *pytrace = 0;
68 PyErr_Fetch( &pytype, &pyvalue, &pytrace );
69 const char*
s = PyUnicode_AsUTF8AndSize( pyvalue,
nullptr );
71 PyObject* pyvalue2 = PyUnicode_FromFormat(
72 (
char*)
"%s and given element size (%ld) do not match needed (%d)",
74 seqmeths->sq_length ? (Long_t)(buflen / (*(seqmeths->sq_length))( pyobject )) : (Long_t)buflen,
77 PyErr_Restore( pytype, pyvalue2, pytrace );
91 return PyImport_ImportModule (
"ROOT");
105 TClass*
cls =
nullptr;
108 PyObject* buf = PyUnicode_AsASCIIString (attr);
110 char*
s = PyBytes_AsString (buf);
112 if (strncmp (
s,
"ROOT.", 5) == 0)
114 if (strncmp (
s,
"cppyy.gbl.", 10) == 0)
116 cls = TClass::GetClass (
s);
129 PyObject* ret = PyObject_GetAttrString (
root,
"SetOwnership");
144 PyObject* ret = PyObject_CallFunction (func,
const_cast<char*
>(
"OI"),
146 static_cast<unsigned int>(
flag));