MCPcopy Index your code
hub / github.com/python/cpython / test

Function test

Lib/ctypes/util.py:496–541  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

494# test code
495
496def test():
497 from ctypes import cdll
498 if os.name == "nt":
499 print(cdll.msvcrt)
500 print(cdll.load("msvcrt"))
501 print(find_library("msvcrt"))
502
503 if os.name == "posix":
504 # find and load_version
505 print(find_library("m"))
506 print(find_library("c"))
507 print(find_library("bz2"))
508
509 # load
510 if sys.platform == "darwin":
511 print(cdll.LoadLibrary("libm.dylib"))
512 print(cdll.LoadLibrary("libcrypto.dylib"))
513 print(cdll.LoadLibrary("libSystem.dylib"))
514 print(cdll.LoadLibrary("System.framework/System"))
515 # issue-26439 - fix broken test call for AIX
516 elif sys.platform.startswith("aix"):
517 from ctypes import CDLL
518 if sys.maxsize < 2**32:
519 print(f"Using CDLL(name, os.RTLD_MEMBER): {CDLL('libc.a(shr.o)', os.RTLD_MEMBER)}")
520 print(f"Using cdll.LoadLibrary(): {cdll.LoadLibrary('libc.a(shr.o)')}")
521 # librpm.so is only available as 32-bit shared library
522 print(find_library("rpm"))
523 print(cdll.LoadLibrary("librpm.so"))
524 else:
525 print(f"Using CDLL(name, os.RTLD_MEMBER): {CDLL('libc.a(shr_64.o)', os.RTLD_MEMBER)}")
526 print(f"Using cdll.LoadLibrary(): {cdll.LoadLibrary('libc.a(shr_64.o)')}")
527 print(f"crypt\t:: {find_library('crypt')}")
528 print(f"crypt\t:: {cdll.LoadLibrary(find_library('crypt'))}")
529 print(f"crypto\t:: {find_library('crypto')}")
530 print(f"crypto\t:: {cdll.LoadLibrary(find_library('crypto'))}")
531 else:
532 print(cdll.LoadLibrary("libm.so"))
533 print(cdll.LoadLibrary("libcrypt.so"))
534 print(find_library("crypt"))
535
536 try:
537 dllist
538 except NameError:
539 print('dllist() not available')
540 else:
541 print(dllist())
542
543if __name__ == "__main__":
544 test()

Callers 1

util.pyFile · 0.70

Calls 6

find_libraryFunction · 0.90
CDLLClass · 0.90
dllistFunction · 0.85
LoadLibraryMethod · 0.80
loadMethod · 0.45
startswithMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…