Skip to content

Add an optional reason out-parameter to LoadLibrary - #1107

Open
conrade-ctc wants to merge 2 commits into
compiler-research:mainfrom
chicagotrading:loadlib-reason-upstream
Open

Add an optional reason out-parameter to LoadLibrary#1107
conrade-ctc wants to merge 2 commits into
compiler-research:mainfrom
chicagotrading:loadlib-reason-upstream

Conversation

@conrade-ctc

@conrade-ctc conrade-ctc commented Sep 3, 2026

Copy link
Copy Markdown
Collaborator

Follow-up to #1101 from the discussion on compiler-research/cppjit#63; this branch is stacked on #1101.

Cpp::LoadLibrary(lib_stem, lookup, std::string* error = nullptr). When error is set it receives the dlerror() text, or <stem>: library not found when the search-path lookup fails, and the reason is not also printed to stderr. The two-argument form keeps the #1101 behaviour.

  • std::string* cannot cross the C ABI, so the .td entry is NoCWrapper and cppinterop_LoadLibrary(const char*, bool) is kept by hand in CXCppInterOp.cpp, with a test.
  • DynamicLibraryManager_LoadFailureReason now covers a dlopen failure, a failed lookup, and that success clears a stale reason.

Once this lands, cppjit#63 bumps its pin and reads the reason from here instead of the ctypes probe.

Coverage: the wasm branch of Interpreter::loadLibrary is wrapped in LCOV_EXCL_START/STOP, since no coverage lane runs it.

@codecov

codecov Bot commented Sep 3, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 87.98%. Comparing base (7cb23ca) to head (1764cbc).

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1107      +/-   ##
==========================================
+ Coverage   87.78%   87.98%   +0.19%     
==========================================
  Files          23       23              
  Lines        6444     6449       +5     
==========================================
+ Hits         5657     5674      +17     
+ Misses        787      775      -12     
Files with missing lines Coverage Δ
lib/CppInterOp/CXCppInterOp.cpp 100.00% <100.00%> (ø)
lib/CppInterOp/CppInterOp.cpp 90.62% <100.00%> (+<0.01%) ⬆️
lib/CppInterOp/CppInterOpInterpreter.h 88.51% <100.00%> (+3.21%) ⬆️
lib/CppInterOp/DynamicLibraryManager.cpp 75.68% <100.00%> (+1.85%) ⬆️
lib/CppInterOp/DynamicLibraryManager.h 100.00% <ø> (ø)

... and 1 file with indirect coverage changes

Files with missing lines Coverage Δ
lib/CppInterOp/CXCppInterOp.cpp 100.00% <100.00%> (ø)
lib/CppInterOp/CppInterOp.cpp 90.62% <100.00%> (+<0.01%) ⬆️
lib/CppInterOp/CppInterOpInterpreter.h 88.51% <100.00%> (+3.21%) ⬆️
lib/CppInterOp/DynamicLibraryManager.cpp 75.68% <100.00%> (+1.85%) ⬆️
lib/CppInterOp/DynamicLibraryManager.h 100.00% <ø> (ø)

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@github-actions

github-actions Bot commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

clang-tidy review says "All clean, LGTM! 👍"

conrade-ctc pushed a commit to chicagotrading/cppjit that referenced this pull request Sep 3, 2026
Cpp::LoadLibrary now hands back the loader's reason through an optional
out-parameter (compiler-research/CppInterOp#1107), so the ctypes
re-dlopen probe goes away. The pin bump to a CppInterOp commit that
carries #1107 is folded in when it lands.

Co-developed-with-the-help-of: Claude Code (Fable 5.1, human in the loop)
@conrade-ctc
conrade-ctc force-pushed the loadlib-reason-upstream branch from 27bf3f9 to 78629c5 Compare September 3, 2026 18:40
@github-actions

github-actions Bot commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

clang-tidy review says "All clean, LGTM! 👍"

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy made some suggestions

Comment thread lib/CppInterOp/CppInterOp.cpp
Comment thread lib/CppInterOp/CppInterOpInterpreter.h Outdated
Comment thread lib/CppInterOp/CppInterOpInterpreter.h Outdated
Emery Conrad added 2 commits September 4, 2026 11:01
DynamicLibraryManager::loadLibrary got the dlerror() text from
platform::DLOpen but only emitted it under LLVM_DEBUG. cppjit's
load_library builds its Python error from captured stderr, so the
reason was empty. Emit the text to std::cerr; cppjit captures only
std::cerr's rdbuf, not llvm::errs().

Paths.cpp already calls ::dlerror() to build this text.

Co-developed-with-the-help-of: Claude Code (Fable 5, human in the loop)
cppjit builds its Python error from the text a failed LoadLibrary writes
to stderr, which the caller has to capture. Callers can now pass a
std::string* and get the dlerror() text, or a not-found note when the
lookup fails, directly. When the pointer is set the reason is not also
written to stderr.

std::string* cannot cross the C ABI, so the generated C wrapper is
suppressed and cppinterop_LoadLibrary(const char*, bool) is kept by
hand in CXCppInterOp.cpp.

Co-developed-with-the-help-of: Claude Code (Fable 5.1, human in the loop)
@conrade-ctc
conrade-ctc force-pushed the loadlib-reason-upstream branch from c0245ee to 1764cbc Compare September 4, 2026 16:03
@github-actions

github-actions Bot commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

clang-tidy review says "All clean, LGTM! 👍"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant