Skip to content
Snippets Groups Projects
Commit 2dc2f13e authored by scott snyder's avatar scott snyder Committed by Attila Krasznahorkay
Browse files

PyUtils: Fix length inconsistency in SetSize call.

The pythonization of TFile::root was calling the SetSize method
on a PyROOT buffer object.  The argument that SetSize takes is the
number of elements in the buffer, where the size of each element
depends on how the buffer was created.  Here, however, we were
passing to SetSize a number of bytes.

The buffer elements we were seeing were void*, which have size 8.
So the buffer size was getting misset by a factor of 8.
This was leading to a crash in the input file peeker.

This crash was however only observed in the muRunData test of TrigUpgradeTest,
and only when it was run with --stdcmalloc and MALLOC_CHECK_=3.
It's a bit a mystery why this apparently long-standing bug hasn't 
caused problems before.



Former-commit-id: 5f553898f3b4118e8ce47eb78932349b750e2054
parent ba75c297
No related branches found
No related tags found
No related merge requests found
......@@ -21,10 +21,18 @@ import os
import sys
import re
from pprint import pprint
from array import array
from .Decorators import memoize
### functions -----------------------------------------------------------------
# Set buffer size, in bytes.
# The argument to SetSize is in elements, not bytes.
def _set_byte_size (buf, sz):
eltsz = array(buf.typecode).itemsize
buf.SetSize (sz / eltsz)
return
def import_root(batch=True):
"""a helper method to wrap the 'import ROOT' statement to prevent ROOT
from screwing up the display or loading graphics libraries when in batch
......@@ -149,7 +157,7 @@ def _pythonize_tfile():
#self.seek(c_buf.sz+self.tell())
#print "-->2",self.tell()
buf = c_buf.buffer()
buf.SetSize(c_buf.sz)
_set_byte_size (buf, c_buf.sz)
return str(buf[:])
return ''
else:
......@@ -160,7 +168,7 @@ def _pythonize_tfile():
c_buf = read_root_file(self, size)
if c_buf and c_buf.sz:
buf = c_buf.buffer()
buf.SetSize(c_buf.sz)
_set_byte_size (buf, c_buf.sz)
out.append(str(buf[:]))
else:
break
......
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