feat(pj_base): add getSharedLibDir() to platform.hpp#64
Merged
Conversation
Adds PJ::sdk::getSharedLibDir(const void* fn_addr) alongside the
existing userDataDir() and getEnv() helpers.
The function returns the directory of the .so / .dll that contains
fn_addr at runtime — useful for plugins that bundle resources (e.g. a
Python stdlib) next to their binary and need to locate them without
knowing the install prefix at build time.
Platform implementation:
- Linux / macOS: dladdr() — callers must link ${CMAKE_DL_LIBS}
- Windows: GetModuleHandleExW() + GetModuleFileNameW()
WIN32_LEAN_AND_MEAN / NOMINMAX guards prevent namespace pollution from
<windows.h>.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
PJ::sdk::getSharedLibDir(const void* fn_addr)topj_base/include/pj_base/sdk/platform.hppalongside the existinguserDataDir()andgetEnv()helpers.so/.dllthat containsfn_addrat runtime, without requiring a known install prefix at build timedladdr()on Linux/macOS andGetModuleHandleExW()+GetModuleFileNameW()on WindowsWIN32_LEAN_AND_MEAN/NOMINMAXguards prevent namespace pollution from<windows.h>Use case
Plugins that bundle resources (e.g. a Python stdlib directory) alongside their binary need to locate those resources at runtime. Without a core helper they must each reimplement
dladdr/GetModuleHandleExWwith their own#ifdefblocks. This PR provides one canonical, tested implementation.The first consumer is the
toolbox_reactive_scripts_editorplugin (pj-official-plugins PR #64), which bundles CPython stdlib and needs to tell the interpreter where to find it.Test plan
getSharedLibDir()called from a plugin.soreturns the correct directory (validated via the plugins PR build)