Repository navigation
fix: update moduleMap in UnloadPluginLibrary - #1002
Conversation
|
Good fix, but.... I actually consider that function to be a bit of a mistake for actual ( I think The bug fixed here looks like the result of "fixes" a less experienced version of I made in 2013. Given that unloading of real adapters is broken, which means hopefully nobody is depending on it currently, I can think of a few ways forward:
In all 3 cases, mock adapters (which of course we'll rename for Python) can still be unloaded (using a new function in case 3). I think I favor 2. What do you think? Of course, in the future we could support unloading of real adapters that explicitly declare their support for doing so, which could be useful for adapters that don't have third-party dependencies (static or dynamic). We kind of need good terms for |
|
makes sense! yeah, I'm good with option 2 (assuming you mean it would be an error when closing this, since either way this isn't the right approach |
Unloading a DLL-based device adapter is not safe in general, so make LoadedDeviceAdapterImplRegular::Unload() throw instead of unloading the library. Mock adapters can still be unloaded (and re-loaded under the same name). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
actually, reopening with one possible way to implement option 2. let me know if this is what you meant One caveat: |
|
Yes, that is what I had in mind! Your caveat raises a good point, but I think it's okay -- it's more common that we cannot predict errors before taking action, so no need to overachieve here. We're going from "experimental, don't use" + unpredictable behavior to explicit error for classic adapters, so I don't think we really need to worry about breaking anybody's code that wasn't already broken. But I will increment the MMCore patch version before merging. |
|
Would it be useful to have a method to query the type (classic vs registered) of an adapter? (So the app can determine if it is unloadable.) |
I don't have an immediate need for it, but also don't have any objections |
|
Well, let's not bother until it's needed then! |
Only bumping the patch version because the unloadLibrary() changes can be considered a bug fix: - Previously, we labeled the function "experimental, don't use" and it did not work in practice. It is unlikely that any existing code calling this function was correct to begin with. - Now we throw an explicit error for library adapters (an improvement) or correctly unregister a mock device adapter (bugfix). Also added to the doc comment of unloadLibrary().
0ff4e60 to
c339894
Compare
unloadLibrary()unloaded the adapter module but left its entry inCPluginManager::moduleMap_, so a later load under the same name failed ("already loaded") for mock adapters, or reused the stale entry (with function pointers into the unloaded library) for regular adapters; this erases the entry after a successful unload and adds a regression test.edit: discovered while working on pymmcore-plus/pymmcore-nano#86, where creating and discards adapters at runtime becomes something that is actually more likely/useful.