Skip to content

Commit

Permalink
fix: don't assume Uproot is in global scope in TPython::Eval (#927)
Browse files Browse the repository at this point in the history
* fix: don't assume Uproot is in global scope in TPython::Eval

* Unfortunately, this test does not trigger the bug (in main).

* Use TProfile3D for the test.
  • Loading branch information
jpivarski authored Aug 8, 2023
1 parent a8644df commit 6b3b6f1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/uproot/pyroot.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,15 +101,15 @@ class _Uproot_buffer_sizer : public TObject {
char* _uproot_TMessage_reallocate(char* buffer, size_t newsize, size_t oldsize) {
_Uproot_buffer_sizer* ptr = reinterpret_cast<_Uproot_buffer_sizer*>(
(void*)TPython::Eval("uproot.pyroot.pyroot_to_buffer.sizer")
(void*)TPython::Eval("__import__('uproot').pyroot.pyroot_to_buffer.sizer")
);
ptr->buffer = reinterpret_cast<size_t>(buffer);
ptr->newsize = newsize;
ptr->oldsize = oldsize;
TPython::Exec("uproot.pyroot.pyroot_to_buffer.reallocate()");
TPython::Exec("__import__('uproot').pyroot.pyroot_to_buffer.reallocate()");
TPyReturn out = TPython::Eval("uproot.pyroot.pyroot_to_buffer.buffer.ctypes.data");
TPyReturn out = TPython::Eval("__import__('uproot').pyroot.pyroot_to_buffer.buffer.ctypes.data");
return reinterpret_cast<char*>((size_t)out);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# BSD 3-Clause License; see https://github.com/scikit-hep/uproot5/blob/main/LICENSE

import random
import string

import pytest

ROOT = pytest.importorskip("ROOT")


def test():
name = "".join(random.choices(string.ascii_lowercase, k=10))
h = ROOT.TProfile3D()
assert __import__("uproot").from_pyroot(h).values().shape == (1, 1, 1)

0 comments on commit 6b3b6f1

Please sign in to comment.