Skip to content

Commit f24fb74

Browse files
fix for new cffi.dlopen behaviour
1 parent 07fe7b5 commit f24fb74

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

PySpice/Spice/NgSpice/Shared.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@
8282
####################################################################################################
8383

8484
from pathlib import Path
85+
import ctypes.util
8586
import logging
8687
import os
8788
import platform
@@ -429,6 +430,16 @@ def setup_platform(cls):
429430

430431
##############################################
431432

433+
@classmethod
434+
def find_library(cls, name: str) -> str:
435+
# name must not be prefixed by lib !
436+
if name.startswith('lib'):
437+
name = name[3:]
438+
cls._logger.debug(f'Search library "{name}"')
439+
return ctypes.util.find_library(name)
440+
441+
##############################################
442+
432443
_instances = {}
433444

434445
@classmethod
@@ -484,17 +495,16 @@ def spinit_not_found(self):
484495
def library_path(self):
485496
if self._library_path is None:
486497
if not self._ngspice_id:
487-
library_prefix = ''
498+
_ = ''
488499
else:
489-
library_prefix = '{}'.format(self._ngspice_id) # id =
490-
library_path = self.LIBRARY_PATH.format(library_prefix)
500+
_ = f'{self._ngspice_id}' # id =
501+
library_path = self.find_library(self.LIBRARY_PATH.format(_))
491502
self._library_path = library_path
492503
return self._library_path
493504

494505
##############################################
495506

496507
def _load_library(self, verbose):
497-
498508
if ConfigInstall.OS.on_windows:
499509
# https://sourceforge.net/p/ngspice/discussion/133842/thread/1cece652/#4e32/5ab8/9027
500510
# When environment variable SPICE_LIB_DIR is empty, ngspice looks in C:\Spice64\share\ngspice\scripts

0 commit comments

Comments
 (0)