// tests/plugin/fixtures/legacy_plugin.cpp // 模拟 ABI 1.3 旧插件(注册结构 48B):用于验证宿主 ABI 1.4 的二进制向后兼容。 // - 默认:kind=format,只填 format/generic/cae/cam/gcs 字段,struct_size=48; // - VDE_LEGACY_KIND_MESHER:kind=mesher,同样只报到 48B(旧插件不认识 mesher 字段), // 宿主必须因 struct_size 不足而明确拒绝。 #include #include #include "vde/plugin/vde_plugin_api.h" namespace { int probe(const void* head, std::size_t head_size) { (void)head; (void)head_size; return 0; } int read_file(const VdePluginHost* host, const char* path, VdeBody** bodies, size_t* count) { (void)host; (void)path; if (bodies) *bodies = nullptr; if (count) *count = 0; return VDE_PLUGIN_ERR_UNSUPPORTED; } int read_memory(const VdePluginHost* host, const void* data, size_t size, VdeBody** bodies, size_t* count) { (void)host; (void)data; (void)size; if (bodies) *bodies = nullptr; if (count) *count = 0; return VDE_PLUGIN_ERR_UNSUPPORTED; } int write_file(const VdePluginHost* host, const char* path, const VdeBody* bodies, size_t count) { (void)host; (void)path; (void)bodies; (void)count; return VDE_PLUGIN_ERR_UNSUPPORTED; } const char* format_describe() { return "legacy ABI 1.3 format plugin"; } const VdeFormatPlugin kFormat = {sizeof(VdeFormatPlugin), "legacy.format", ".legacy", probe, read_file, read_memory, write_file, nullptr, format_describe}; #if defined(VDE_LEGACY_KIND_MESHER) int legacy_mesh(const VdePluginHost* host, const void* model_data, size_t model_size, const VdeMesherOptions* options, VdeMesherResult* result) { (void)host; (void)model_data; (void)model_size; (void)options; (void)result; return VDE_PLUGIN_ERR_UNSUPPORTED; } const VdeMesherPlugin kMesher = {sizeof(VdeMesherPlugin), "legacy.mesher", nullptr, legacy_mesh, nullptr}; #endif constexpr const char* kPluginId = "com.vde.test.legacy.format"; #if defined(VDE_LEGACY_KIND_MESHER) constexpr const char* kMesherPluginId = "com.vde.test.legacy.mesher48"; #endif } // namespace extern "C" { VDE_PLUGIN_EXPORT int vde_plugin_query(std::uint32_t host_abi_major, VdePluginInfo* info) { if (!info || info->struct_size < sizeof(VdePluginInfo)) return VDE_PLUGIN_ERR_INVALID_ARG; if (host_abi_major != VDE_PLUGIN_ABI_MAJOR) return VDE_PLUGIN_ERR_ABI; #if defined(VDE_LEGACY_KIND_MESHER) info->id = kMesherPluginId; info->name = "Legacy ABI 1.4 mesher declaration (48B registration)"; info->kind = VDE_PLUGIN_KIND_MESHER; info->capabilities = "mesher:legacy"; info->abi_minor = 4; #else info->id = kPluginId; info->name = "Legacy ABI 1.3 format plugin"; info->kind = VDE_PLUGIN_KIND_FORMAT; info->capabilities = "format:legacy"; info->abi_minor = 3; #endif info->version = "0.1.0"; info->abi_major = VDE_PLUGIN_ABI_MAJOR; info->license = "Apache-2.0"; return VDE_PLUGIN_OK; } VDE_PLUGIN_EXPORT int vde_plugin_init(const VdePluginHost* host, VdePluginRegistration* reg) { (void)host; if (!reg) return VDE_PLUGIN_ERR_INVALID_ARG; // 真实 ABI 1.3 插件编译时 sizeof(VdePluginRegistration)==48;这里显式写 48, // 宿主(ABI 1.4,sizeof==56)必须按 struct_size 判断字段存在性。 reg->struct_size = static_cast(offsetof(VdePluginRegistration, mesher)); reg->format = nullptr; reg->generic = nullptr; reg->cae_solver = nullptr; reg->cam_strategy = nullptr; reg->gcs_solver = nullptr; #if defined(VDE_LEGACY_KIND_MESHER) reg->kind = VDE_PLUGIN_KIND_MESHER; #else reg->kind = VDE_PLUGIN_KIND_FORMAT; reg->format = &kFormat; #endif return VDE_PLUGIN_OK; } VDE_PLUGIN_EXPORT void vde_plugin_shutdown() {} } // extern "C"