Skip to content

Commit

Permalink
fix: find_library can be None (tinygrad#7145)
Browse files Browse the repository at this point in the history
  • Loading branch information
jla524 authored Oct 18, 2024
1 parent b0a1389 commit c8b5941
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion autogen_stubs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion tinygrad/runtime/autogen/libc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit c8b5941

Please sign in to comment.