mirror of
https://github.com/robbert-vdh/yabridge.git
synced 2026-05-09 20:29:10 +02:00
Clean up IPluginFactory::createInstance()
We'll just do all the checks up front, that's much cleaner and also safer.
This commit is contained in:
@@ -28,18 +28,20 @@ tresult PLUGIN_API
|
|||||||
YaPluginFactoryImpl::createInstance(Steinberg::FIDString cid,
|
YaPluginFactoryImpl::createInstance(Steinberg::FIDString cid,
|
||||||
Steinberg::FIDString _iid,
|
Steinberg::FIDString _iid,
|
||||||
void** obj) {
|
void** obj) {
|
||||||
if (!_iid || !cid) {
|
constexpr size_t uid_size = sizeof(Steinberg::TUID);
|
||||||
|
if (!cid || !_iid || strnlen(cid, uid_size) < uid_size ||
|
||||||
|
strnlen(_iid, uid_size) < uid_size) {
|
||||||
return Steinberg::kInvalidArgument;
|
return Steinberg::kInvalidArgument;
|
||||||
}
|
}
|
||||||
|
|
||||||
ArrayUID cid_array;
|
ArrayUID cid_array;
|
||||||
std::copy(cid, cid + sizeof(Steinberg::TUID), cid_array.begin());
|
std::copy(cid, cid + std::extent_v<Steinberg::TUID>, cid_array.begin());
|
||||||
|
|
||||||
// FIXME: `_iid` in Bitwig Studio 3.3.1 is not null terminated, and the
|
// FIXME: `_iid` in Bitwig Studio 3.3.1 is not null terminated, and the
|
||||||
// comparison below will thus fail since the strings have different
|
// comparison below will thus fail since the strings have different
|
||||||
// lengths. We'll temporarily work around this, and if this end sup
|
// lengths. Since it looks like the module implementation that comes
|
||||||
// not being us doing something strange then we should report it.
|
// with the SDK has this same issue I think it might just be a case
|
||||||
constexpr size_t uid_size = sizeof(Steinberg::TUID);
|
// of Steinberg not following its own specifications.
|
||||||
std::string iid_string(_iid, uid_size);
|
std::string iid_string(_iid, uid_size);
|
||||||
|
|
||||||
Vst3PluginProxy::Construct::Interface requested_interface;
|
Vst3PluginProxy::Construct::Interface requested_interface;
|
||||||
@@ -55,12 +57,8 @@ YaPluginFactoryImpl::createInstance(Steinberg::FIDString cid,
|
|||||||
// print a recognizable log message. I don't think they include a safe
|
// print a recognizable log message. I don't think they include a safe
|
||||||
// way to convert a `FIDString/char*` into a `FUID`, so this will have
|
// way to convert a `FIDString/char*` into a `FUID`, so this will have
|
||||||
// to do.
|
// to do.
|
||||||
std::optional<Steinberg::FUID> uid;
|
const Steinberg::FUID uid = Steinberg::FUID::fromTUID(
|
||||||
if (_iid && strnlen(_iid, uid_size) >= uid_size) {
|
*reinterpret_cast<const Steinberg::TUID*>(&*_iid));
|
||||||
uid = Steinberg::FUID::fromTUID(
|
|
||||||
*reinterpret_cast<const Steinberg::TUID*>(&*_iid));
|
|
||||||
}
|
|
||||||
|
|
||||||
bridge.logger.log_unknown_interface(
|
bridge.logger.log_unknown_interface(
|
||||||
"In IPluginFactory::createInstance()", uid);
|
"In IPluginFactory::createInstance()", uid);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user