Skip to content

Commit db579f2

Browse files
facontidavideclaude
andcommitted
feat(sdk): static PJ_DIALOG_PLUGIN variant (no-collision, WASM)
Under PJ_STATIC_PLUGINS many plugins link into one binary; the fixed `extern "C" PJ_get_dialog_vtable` symbol (+ the ABI-version export) PJ_DIALOG_PLUGIN emits would collide across them at link. Emit a uniquely class-keyed pj_static_get_dialog_vtable_<Class>() instead (keeping the dialogVtableFor<Class> specialization), completing the static-export pattern the other three family macros already follow. The static registry resolves dialogs by this getter, not the dlsym entry point. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 2d85541 commit db579f2

1 file changed

Lines changed: 30 additions & 0 deletions

File tree

pj_plugins/dialog_protocol/include/pj_plugins/sdk/dialog_plugin_base.hpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,3 +303,33 @@ PJ_borrowed_dialog_t borrowDialog(DialogT& dialog) noexcept {
303303
return PJ_get_dialog_vtable(); \
304304
} \
305305
}
306+
307+
// --- Static-link variant (WASM / no dlopen) --- see data_source_plugin_base.hpp.
308+
// Many statically-linked plugins each carry a PJ_DIALOG_PLUGIN, so the fixed
309+
// `extern "C" PJ_get_dialog_vtable` symbol (and the ABI-version export) would
310+
// collide at link. The static registry never resolves a dialog via dlsym (the
311+
// host short-circuits the dialog path on WASM), so emit only a uniquely
312+
// class-keyed getter — kept so dialogVtableFor<ClassName>() still resolves for
313+
// any in-binary caller.
314+
#ifdef PJ_STATIC_PLUGINS
315+
#undef PJ_DIALOG_PLUGIN_WITH_MANIFEST
316+
#define PJ_DIALOG_PLUGIN_WITH_MANIFEST(ClassName, ManifestJson) \
317+
inline const PJ_dialog_vtable_t* pj_static_get_dialog_vtable_##ClassName() noexcept { \
318+
static const PJ_dialog_vtable_t* vt = PJ::DialogPluginBase::vtableWithCreate( \
319+
[]() noexcept -> void* { \
320+
try { \
321+
return static_cast<PJ::DialogPluginBase*>(new ClassName()); \
322+
} catch (...) { \
323+
return nullptr; \
324+
} \
325+
}, \
326+
ManifestJson); \
327+
return vt; \
328+
} \
329+
namespace PJ { \
330+
template <> \
331+
[[maybe_unused]] inline const PJ_dialog_vtable_t* dialogVtableFor<ClassName>() noexcept { \
332+
return pj_static_get_dialog_vtable_##ClassName(); \
333+
} \
334+
}
335+
#endif // PJ_STATIC_PLUGINS

0 commit comments

Comments
 (0)