@@ -260,7 +260,7 @@ def find_library_darwin(cls):
260260 if f .startswith (dll ):
261261 yield os .path .join (dir_path , f )
262262
263- def __init__ (self , dllpath = None ):
263+ def __init__ (self , dllpath = None , use_tmpcpy = True ):
264264 """Initializes an instance of a ``Library``.
265265
266266 Loads the default J-Link DLL if ``dllpath`` is ``None``, otherwise
@@ -269,6 +269,7 @@ def __init__(self, dllpath=None):
269269 Args:
270270 self (Library): the ``Library`` instance
271271 dllpath (str): the DLL to load into the library
272+ use_tmpcpy (bool): True to load a temporary copy of J-Link DLL
272273
273274 Returns:
274275 ``None``
@@ -278,6 +279,7 @@ def __init__(self, dllpath=None):
278279 self ._path = None
279280 self ._windows = sys .platform .startswith ('win' )
280281 self ._cygwin = sys .platform .startswith ('cygwin' )
282+ self ._use_tmpcpy = use_tmpcpy
281283 self ._temp = None
282284
283285 if self ._windows or self ._cygwin :
@@ -387,28 +389,33 @@ def load(self, path=None):
387389 else :
388390 suffix = '.so'
389391
390- # Copy the J-Link DLL to a temporary file. This will be cleaned up the
391- # next time we load a DLL using this library or if this library is
392- # cleaned up.
393- tf = tempfile .NamedTemporaryFile (delete = False , suffix = suffix )
394- with open (tf .name , 'wb' ) as outputfile :
395- with open (self ._path , 'rb' ) as inputfile :
396- outputfile .write (inputfile .read ())
392+ lib_path = self ._path
397393
398- # This is needed to work around a WindowsError where the file is not
399- # being properly cleaned up after exiting the with statement.
400- tf .close ()
394+ if self ._use_tmpcpy :
395+ # Copy the J-Link DLL to a temporary file. This will be cleaned up the
396+ # next time we load a DLL using this library or if this library is
397+ # cleaned up.
398+ tf = tempfile .NamedTemporaryFile (delete = False , suffix = suffix )
399+ with open (tf .name , 'wb' ) as outputfile :
400+ with open (self ._path , 'rb' ) as inputfile :
401+ outputfile .write (inputfile .read ())
401402
402- self ._temp = tf
403- self ._lib = ctypes .cdll .LoadLibrary (tf .name )
403+ # This is needed to work around a WindowsError where the file is not
404+ # being properly cleaned up after exiting the with statement.
405+ tf .close ()
406+
407+ lib_path = tf .name
408+ self ._temp = tf
409+
410+ self ._lib = ctypes .cdll .LoadLibrary (lib_path )
404411
405412 if self ._windows :
406413 # The J-Link library uses a mix of __cdecl and __stdcall function
407414 # calls. While this is fine on a nix platform or in cygwin, this
408415 # causes issues with Windows, where it expects the __stdcall
409416 # methods to follow the standard calling convention. As a result,
410417 # we have to convert them to windows function calls.
411- self ._winlib = ctypes .windll .LoadLibrary (tf . name )
418+ self ._winlib = ctypes .windll .LoadLibrary (lib_path )
412419 for stdcall in self ._standard_calls_ :
413420 if hasattr (self ._winlib , stdcall ):
414421 # Backwards compatibility. Some methods do not exist on
0 commit comments