| 382 | } |
| 383 | |
| 384 | std::shared_ptr<PluginLibrary> LoadByPath(const std::string& path, |
| 385 | const std::string& type) { |
| 386 | if (IsTruthy(std::getenv("OPENCC_DISABLE_PLUGINS"))) { |
| 387 | throw Exception("Segmentation plugin loading is disabled."); |
| 388 | } |
| 389 | |
| 390 | std::lock_guard<std::mutex> lock(mutex_); |
| 391 | // Use the explicit path as cache key (not type) to avoid collisions |
| 392 | // when the same plugin type is loaded from different library paths. |
| 393 | auto it = cache_.find(path); |
| 394 | if (it != cache_.end()) { |
| 395 | return it->second; |
| 396 | } |
| 397 | std::shared_ptr<PluginLibrary> plugin = LoadFromPath(path, type); |
| 398 | cache_[path] = plugin; |
| 399 | return plugin; |
| 400 | } |
| 401 | |
| 402 | private: |
| 403 | static std::vector<std::string> GetPluginFileNames(const std::string& type) { |
no test coverage detected