From c8b59416d0d71c35e96e2d04b09bd8841b239e57 Mon Sep 17 00:00:00 2001 From: Jacky Lee <39754370+jla524@users.noreply.github.com> Date: Fri, 18 Oct 2024 10:50:52 -0700 Subject: [PATCH] fix: find_library can be None (#7145) --- autogen_stubs.sh | 2 +- tinygrad/runtime/autogen/libc.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/autogen_stubs.sh b/autogen_stubs.sh index ab267c6ba0e4..ee9324e43643 100755 --- a/autogen_stubs.sh +++ b/autogen_stubs.sh @@ -211,7 +211,7 @@ generate_libc() { sed -i "s\import ctypes\import ctypes, ctypes.util, os\g" $BASE/libc.py sed -i "s\FIXME_STUB\libc\g" $BASE/libc.py - sed -i "s\FunctionFactoryStub()\ctypes.CDLL(ctypes.util.find_library('c'))\g" $BASE/libc.py + sed -i "s\FunctionFactoryStub()\None if (libc_path := ctypes.util.find_library('c')) is None else ctypes.CDLL(libc_path)\g" $BASE/libc.py fixup $BASE/libc.py } diff --git a/tinygrad/runtime/autogen/libc.py b/tinygrad/runtime/autogen/libc.py index d0f8ac121d80..53e1841ed63a 100644 --- a/tinygrad/runtime/autogen/libc.py +++ b/tinygrad/runtime/autogen/libc.py @@ -27,7 +27,7 @@ def __getattr__(self, _): # You can either re-run clan2py with -l /path/to/library.so # Or manually fix this by comment the ctypes.CDLL loading _libraries = {} -_libraries['libc'] = ctypes.CDLL(ctypes.util.find_library('c')) # ctypes.CDLL('libc') +_libraries['libc'] = None if (libc_path := ctypes.util.find_library('c')) is None else ctypes.CDLL(libc_path) # ctypes.CDLL('libc') def string_cast(char_pointer, encoding='utf-8', errors='strict'): value = ctypes.cast(char_pointer, ctypes.c_char_p).value if value is not None and encoding is not None: