Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions python/cppjit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,8 +241,10 @@ def _interpreter_lock():
def cppdef(src, verbose=True):
"""Declare C++ source <src> to Cling."""
with _stderr_capture() as err, _interpreter_lock():
errcode = gbl.Cpp.Declare(src, not verbose)
if not errcode == 0 or err.err:
ok = gbl.gInterpreter.Declare(src)
if not verbose:
err.err = ""
if not ok or err.err:
if "warning" in err.err.lower() and "error" not in err.err.lower():
warnings.warn(err.err, SyntaxWarning)
return True
Expand Down Expand Up @@ -326,23 +328,22 @@ def load_library(name):
def include(header):
"""Load (and JIT) header file <header> into Cling."""
with _stderr_capture() as err, _interpreter_lock():
errcode = gbl.Cpp.Declare('#include "%s"' % header, False)
if not errcode == 0:
ok = gbl.gInterpreter.Declare('#include "%s"' % header)
if not ok:
raise ImportError('Failed to load header file "%s"%s' % (header, err.err))
return True


def c_include(header):
"""Load (and JIT) header file <header> into Cling."""
with _stderr_capture() as err, _interpreter_lock():
errcode = gbl.Cpp.Declare(
ok = gbl.gInterpreter.Declare(
"""extern "C" {
#include "%s"
}"""
% header,
False,
% header
)
if not errcode == 0:
if not ok:
raise ImportError('Failed to load header file "%s"%s' % (header, err.err))
return True

Expand Down
1 change: 1 addition & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -124,4 +124,5 @@ CPPJIT_ADD_PYTEST(test_eigen)
CPPJIT_ADD_PYTEST(test_leakcheck)
CPPJIT_ADD_PYTEST(test_numba)
CPPJIT_ADD_PYTEST(test_regression)
CPPJIT_ADD_PYTEST(test_root_declare)
CPPJIT_ADD_PYTEST(test_root_interpreter_lock)
52 changes: 52 additions & 0 deletions test/test_root_declare.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import os
import subprocess

from pytest import mark
from support import IS_WINDOWS


class TestROOTDECLARE:
@mark.skipif(IS_WINDOWS, reason="builds a dictionary with rootcling")
def test01_include_header_of_autoloaded_dictionary(self, tmp_path):
"""include a #pragma once header whose dictionary its rootmap autoloads"""

import cppjit

name = "pragma_once_dict"
header, linkdef = name + ".h", name + "LinkDef.h"
rootmap, lib = name + ".rootmap", "lib%s.so" % name
(tmp_path / header).write_text(
"#pragma once\n"
"namespace %s { struct Thing { int value() const { return 42; } }; }\n"
% name
)
(tmp_path / linkdef).write_text(
"#ifdef __CLING__\n#pragma link C++ class %s::Thing+;\n#endif\n" % name
)

bindir = cppjit.gbl.TROOT.GetBinDir().Data()
rootcling = os.path.join(bindir, "rootcling")
root_config = os.path.join(bindir, "root-config")
subprocess.check_call(
[rootcling, "-f", "dict.cxx", "-rmf", rootmap, "-rml", lib]
+ ["-I" + str(tmp_path), header, linkdef],
cwd=tmp_path,
)
cxx = subprocess.check_output([root_config, "--cxx"], text=True).split()
flags = subprocess.check_output(
[root_config, "--cflags", "--libs"], text=True
).split()
subprocess.check_call(
cxx
+ ["-shared", "-fPIC", "-o", lib, "dict.cxx", "-I" + str(tmp_path)]
+ flags,
cwd=tmp_path,
)

cppjit.add_include_path(str(tmp_path))
cppjit.add_library_path(str(tmp_path))
cppjit.gbl.gInterpreter.LoadLibraryMap(str(tmp_path / rootmap))

cppjit.include(header)

assert cppjit.gbl.pragma_once_dict.Thing().value() == 42
Loading