| 238 | } |
| 239 | |
| 240 | bool Plugin::load(color_ostream &con) |
| 241 | { |
| 242 | { |
| 243 | RefAutolock lock(access); |
| 244 | if(state == PS_LOADED) |
| 245 | { |
| 246 | return true; |
| 247 | } |
| 248 | else if(state != PS_UNLOADED && state != PS_DELETED) |
| 249 | { |
| 250 | if (state == PS_BROKEN) |
| 251 | con.printerr("Plugin {} is broken - cannot be loaded\n", name); |
| 252 | return false; |
| 253 | } |
| 254 | state = PS_LOADING; |
| 255 | } |
| 256 | // enter suspend |
| 257 | CoreSuspender suspend; |
| 258 | // open the library, etc |
| 259 | fmt::print(stderr, "loading plugin {}\n", name); |
| 260 | DFLibrary * plug = OpenPlugin(path); |
| 261 | if(!plug) |
| 262 | { |
| 263 | RefAutolock lock(access); |
| 264 | if (!Filesystem::isfile(path)) |
| 265 | { |
| 266 | con.printerr("Plugin {} does not exist on disk\n", name); |
| 267 | state = PS_DELETED; |
| 268 | return false; |
| 269 | } |
| 270 | else { |
| 271 | con.printerr("Can't load plugin {}\n", name); |
| 272 | state = PS_UNLOADED; |
| 273 | return false; |
| 274 | } |
| 275 | } |
| 276 | #define plugin_abort_load ClosePlugin(plug); RefAutolock lock(access); state = PS_UNLOADED |
| 277 | #define plugin_check_symbol(sym) \ |
| 278 | if (!LookupPlugin(plug, sym)) \ |
| 279 | { \ |
| 280 | con.printerr("Plugin {}: missing symbol: {}\n", name, sym); \ |
| 281 | plugin_abort_load; \ |
| 282 | return false; \ |
| 283 | } |
| 284 | |
| 285 | plugin_check_symbol("plugin_name") |
| 286 | plugin_check_symbol("plugin_version") |
| 287 | plugin_check_symbol("plugin_abi_version") |
| 288 | plugin_check_symbol("plugin_self") |
| 289 | plugin_check_symbol("plugin_init") |
| 290 | plugin_check_symbol("plugin_globals") |
| 291 | const char ** plug_name =(const char ** ) LookupPlugin(plug, "plugin_name"); |
| 292 | if (name != *plug_name) |
| 293 | { |
| 294 | con.printerr("Plugin {}: name mismatch, claims to be {}\n", name, *plug_name); |
| 295 | plugin_abort_load; |
| 296 | return false; |
| 297 | } |
nothing calls this directly
no test coverage detected