def test08VoidPointerPassing(self): """Test passing of variants of void pointer arguments""" gROOT.LoadMacro("PointerPassing.C+") AddressOf = ROOT.AddressOf MakeNullPointer = ROOT.MakeNullPointer Z = ROOT.Z o = TObject() self.assertEqual(AddressOf(o)[0], Z.GimeAddressPtr(o)) self.assertEqual(AddressOf(o)[0], Z.GimeAddressPtrRef(o)) pZ = Z.getZ(0) self.assertEqual(Z.checkAddressOfZ(pZ), True) self.assertEqual(pZ, Z.getZ(1)) import array if hasattr(array.array, 'buffer_info'): # not supported in p2.2 addressofo = array.array( 'l', [o.IsA()._TClass__DynamicCast(o.IsA(), o)[0]]) self.assertEqual(addressofo.buffer_info()[0], Z.GimeAddressPtrPtr(addressofo)) self.assertEqual(0, Z.GimeAddressPtr(0)) self.assertEqual(0, Z.GimeAddressPtr(None)) self.assertEqual(0, Z.GimeAddressObject(0)) self.assertEqual(0, Z.GimeAddressObject(None)) ptr = MakeNullPointer(TObject) self.assertRaises(ValueError, AddressOf, ptr) Z.SetAddressPtrRef(ptr) self.assertEqual(AddressOf(ptr)[0], 0x1234) Z.SetAddressPtrPtr(ptr) self.assertEqual(AddressOf(ptr)[0], 0x4321)
def test11VoidPointerPassing(self): """Test passing of variants of void pointer arguments""" gROOT.LoadMacro("PointerPassing.C+") AddressOf = self.AddressOf MakeNullPointer = self.MakeNullPointer Z = ROOT.Z o = TObject() if self.exp_pyroot: # In new Cppyy, addressof returns an integer/long oaddr = AddressOf(o) else: oaddr = AddressOf(o)[0] self.assertEqual(oaddr, Z.GimeAddressPtr(o)) self.assertEqual(oaddr, Z.GimeAddressPtrRef(o)) pZ = Z.getZ(0) self.assertEqual(Z.checkAddressOfZ(pZ), True) self.assertEqual(pZ, Z.getZ(1)) import array if hasattr(array.array, 'buffer_info'): # not supported in p2.2 addressofo = array.array( 'l', [o.IsA()._TClass__DynamicCast(o.IsA(), o)[0]]) self.assertEqual(addressofo.buffer_info()[0], Z.GimeAddressPtrPtr(addressofo)) self.assertEqual(0, Z.GimeAddressPtr(0)) self.assertEqual(0, Z.GimeAddressObject(0)) if not self.exp_pyroot: # The conversion None -> ptr is not supported in new Cppyy self.assertEqual(0, Z.GimeAddressPtr(None)) self.assertEqual(0, Z.GimeAddressObject(None)) ptr = MakeNullPointer(TObject) if self.exp_pyroot: # New Cppyy does not raise ValueError, # it just returns zero self.assertEqual(AddressOf(ptr), 0) else: self.assertRaises(ValueError, AddressOf, ptr) Z.SetAddressPtrRef(ptr) if self.exp_pyroot: # In new Cppyy, addressof returns an integer/long self.assertEqual(AddressOf(ptr), 0x1234) Z.SetAddressPtrPtr(ptr) self.assertEqual(AddressOf(ptr), 0x4321) else: self.assertEqual(AddressOf(ptr)[0], 0x1234) Z.SetAddressPtrPtr(ptr) self.assertEqual(AddressOf(ptr)[0], 0x4321)
def test12VoidPointerPassing(self): """Test passing of variants of void pointer arguments""" gROOT.LoadMacro("PointerPassing.C+") Z = ROOT.Z o = TObject() oaddr = addressof(o) self.assertEqual(oaddr, Z.GimeAddressPtr(o)) self.assertEqual(oaddr, Z.GimeAddressPtrRef(o)) pZ = Z.getZ(0) self.assertEqual(Z.checkAddressOfZ(pZ), True) self.assertEqual(pZ, Z.getZ(1)) import array # Not supported in p2.2 # and no 8-byte integer type array on Windows 64b if hasattr(array.array, 'buffer_info') and IS_WINDOWS != 64: if not self.legacy_pyroot: # New cppyy uses unsigned long to represent void* returns, as in DynamicCast. # To prevent an overflow error when converting the Python integer returned by # DynamicCast into a 4-byte signed long in 32 bits, we use unsigned long ('L') # as type of the array.array. array_t = 'L' else: # Old PyROOT returns Long_t buffers for void* array_t = 'l' addressofo = array.array( array_t, [o.IsA()._TClass__DynamicCast(o.IsA(), o)[0]]) self.assertEqual(addressofo.buffer_info()[0], Z.GimeAddressPtrPtr(addressofo)) self.assertEqual(0, Z.GimeAddressPtr(0)) self.assertEqual(0, Z.GimeAddressObject(0)) if self.legacy_pyroot: # The conversion None -> ptr is not supported in new Cppyy self.assertEqual(0, Z.GimeAddressPtr(None)) self.assertEqual(0, Z.GimeAddressObject(None)) ptr = MakeNullPointer(TObject) if not self.legacy_pyroot: # New Cppyy does not raise ValueError, # it just returns zero self.assertEqual(addressof(ptr), 0) else: self.assertRaises(ValueError, AddressOf, ptr) Z.SetAddressPtrRef(ptr) self.assertEqual(addressof(ptr), 0x1234) Z.SetAddressPtrPtr(ptr) self.assertEqual(addressof(ptr), 0x4321)