Skip to content
Snippets Groups Projects
Commit 398d9f84 authored by Wim Lavrijsen's avatar Wim Lavrijsen
Browse files

bool arrays; to solve #90328

git-svn-id: http://root.cern.ch/svn/root/trunk@42602 27541ba8-7e3a-0410-8455-c3a389f83636
parent e30a02fa
No related branches found
No related tags found
No related merge requests found
......@@ -720,6 +720,7 @@ Bool_t PyROOT::T##name##ArrayConverter::ToMemory( PyObject* value, void* address
}
//____________________________________________________________________________
PYROOT_IMPLEMENT_ARRAY_CONVERTER( Bool, Bool_t, 'b' ) // signed char
PYROOT_IMPLEMENT_ARRAY_CONVERTER( Short, Short_t, 'h' )
PYROOT_IMPLEMENT_ARRAY_CONVERTER( UShort, UShort_t, 'H' )
PYROOT_IMPLEMENT_ARRAY_CONVERTER( Int, Int_t, 'i' )
......@@ -1136,6 +1137,7 @@ namespace {
PYROOT_ARRAY_CONVERTER_FACTORY( CString )
PYROOT_ARRAY_CONVERTER_FACTORY( NonConstCString )
PYROOT_ARRAY_CONVERTER_FACTORY( NonConstUCString )
PYROOT_ARRAY_CONVERTER_FACTORY( BoolArray )
PYROOT_ARRAY_CONVERTER_FACTORY( ShortArray )
PYROOT_ARRAY_CONVERTER_FACTORY( UShortArray )
PYROOT_ARRAY_CONVERTER_FACTORY( IntArray )
......@@ -1181,6 +1183,7 @@ namespace {
NFp_t( "#define", &CreateMacroConverter ),
// pointer/array factories
NFp_t( "bool*", &CreateBoolArrayConverter ),
NFp_t( "const unsigned char*", &CreateCStringConverter ),
NFp_t( "unsigned char*", &CreateNonConstUCStringConverter ),
NFp_t( "short*", &CreateShortArrayConverter ),
......
......@@ -160,6 +160,7 @@ namespace PyROOT {
Bool_t fKeepControl;
};
PYROOT_DECLARE_ARRAY_CONVERTER( BoolArray );
PYROOT_DECLARE_ARRAY_CONVERTER( ShortArray );
PYROOT_DECLARE_ARRAY_CONVERTER( UShortArray );
PYROOT_DECLARE_ARRAY_CONVERTER( IntArray );
......
......@@ -179,6 +179,7 @@ PyObject* PyROOT::T##name##ArrayExecutor::Execute( G__CallFunc* func, void* self
return BufFac_t::Instance()->PyBuffer_FromMemory( (type*)func->ExecInt( self ) );\
}
PYROOT_IMPLEMENT_ARRAY_EXECUTOR( Bool, Bool_t )
PYROOT_IMPLEMENT_ARRAY_EXECUTOR( Short, Short_t )
PYROOT_IMPLEMENT_ARRAY_EXECUTOR( UShort, UShort_t )
PYROOT_IMPLEMENT_ARRAY_EXECUTOR( Int, Int_t )
......@@ -377,6 +378,7 @@ namespace {
PYROOT_EXECUTOR_FACTORY( ULongLong )
PYROOT_EXECUTOR_FACTORY( CString )
PYROOT_EXECUTOR_FACTORY( VoidArray )
PYROOT_EXECUTOR_FACTORY( BoolArray )
PYROOT_EXECUTOR_FACTORY( ShortArray )
PYROOT_EXECUTOR_FACTORY( UShortArray )
PYROOT_EXECUTOR_FACTORY( IntArray )
......@@ -424,6 +426,7 @@ namespace {
// pointer/array factories
NFp_t( "void*", &CreateVoidArrayExecutor ),
NFp_t( "bool*", &CreateBoolArrayExecutor ),
NFp_t( "short*", &CreateShortArrayExecutor ),
NFp_t( "unsigned short*", &CreateUShortArrayExecutor ),
NFp_t( "int*", &CreateIntArrayExecutor ),
......
......@@ -52,6 +52,7 @@ namespace PyROOT {
// pointer/array executors
PYROOT_DECLARE_BASIC_EXECUTOR( VoidArray );
PYROOT_DECLARE_BASIC_EXECUTOR( BoolArray );
PYROOT_DECLARE_BASIC_EXECUTOR( ShortArray );
PYROOT_DECLARE_BASIC_EXECUTOR( UShortArray );
PYROOT_DECLARE_BASIC_EXECUTOR( IntArray );
......
......@@ -40,6 +40,7 @@ namespace {
PySequenceMethods Py##name##Buffer_SeqMethods = *(PyBuffer_Type.tp_as_sequence);\
PyMappingMethods Py##name##Buffer_MapMethods;
PYROOT_PREPARE_PYBUFFER_TYPE( Bool )
PYROOT_PREPARE_PYBUFFER_TYPE( Short )
PYROOT_PREPARE_PYBUFFER_TYPE( UShort )
PYROOT_PREPARE_PYBUFFER_TYPE( Int )
......@@ -144,6 +145,7 @@ namespace {
return 0; \
}
PYROOT_IMPLEMENT_PYBUFFER_METHODS( Bool, Bool_t, Long_t, PyBool_FromLong, PyInt_AsLong )
PYROOT_IMPLEMENT_PYBUFFER_METHODS( Short, Short_t, Long_t, PyInt_FromLong, PyInt_AsLong )
PYROOT_IMPLEMENT_PYBUFFER_METHODS( UShort, UShort_t, Long_t, PyInt_FromLong, PyInt_AsLong )
PYROOT_IMPLEMENT_PYBUFFER_METHODS( Int, Int_t, Long_t, PyInt_FromLong, PyInt_AsLong )
......@@ -189,7 +191,9 @@ namespace {
PyObject* buf_typecode( PyObject* pyobject, void* )
{
// return a typecode in the style of module array
if ( PyObject_TypeCheck( pyobject, &PyShortBuffer_Type ) )
if ( PyObject_TypeCheck( pyobject, &PyBoolBuffer_Type ) )
return PyBytes_FromString( (char*)"b" );
else if ( PyObject_TypeCheck( pyobject, &PyShortBuffer_Type ) )
return PyBytes_FromString( (char*)"h" );
else if ( PyObject_TypeCheck( pyobject, &PyUShortBuffer_Type ) )
return PyBytes_FromString( (char*)"H" );
......@@ -257,6 +261,7 @@ PyROOT::TPyBufferFactory* PyROOT::TPyBufferFactory::Instance()
PyROOT::TPyBufferFactory::TPyBufferFactory()
{
// construct python buffer types
PYROOT_INSTALL_PYBUFFER_METHODS( Bool, Bool_t )
PYROOT_INSTALL_PYBUFFER_METHODS( Short, Short_t )
PYROOT_INSTALL_PYBUFFER_METHODS( UShort, UShort_t )
PYROOT_INSTALL_PYBUFFER_METHODS( Int, Int_t )
......@@ -296,6 +301,7 @@ PyObject* PyROOT::TPyBufferFactory::PyBuffer_FromMemory( type* address, PyObject
return buf; \
}
PYROOT_IMPLEMENT_PYBUFFER_FROM_MEMORY( Bool, Bool_t )
PYROOT_IMPLEMENT_PYBUFFER_FROM_MEMORY( Short, Short_t )
PYROOT_IMPLEMENT_PYBUFFER_FROM_MEMORY( UShort, UShort_t )
PYROOT_IMPLEMENT_PYBUFFER_FROM_MEMORY( Int, Int_t )
......
......@@ -17,6 +17,8 @@ class TPyBufferFactory {
public:
static TPyBufferFactory* Instance();
PyObject* PyBuffer_FromMemory( Bool_t* buf, Py_ssize_t size = -1 );
PyObject* PyBuffer_FromMemory( Bool_t* buf, PyObject* sizeCallback );
PyObject* PyBuffer_FromMemory( Short_t* buf, Py_ssize_t size = -1 );
PyObject* PyBuffer_FromMemory( Short_t* buf, PyObject* sizeCallback );
PyObject* PyBuffer_FromMemory( UShort_t* buf, Py_ssize_t size = -1 );
......
......@@ -177,6 +177,10 @@ inline Py_ssize_t PyNumber_AsSsize_t( PyObject* obj, PyObject* ) {
# endif
#endif
#if PY_VERSION_HEX < 0x02020000
#define PyBool_FromLong PyInt_FromLong
#endif
#if PY_VERSION_HEX < 0x03000000
// the following should quiet Solaris
#ifdef Py_False
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment