# Buggy code
def LIBC():
    """The platform dependent libc implementation."""
    if ON_DARWIN:
        libc = ctypes.CDLL(ctypes.util.find_library("c"))
    elif ON_CYGWIN:
        libc = ctypes.CDLL("cygwin1.dll")
    elif ON_MSYS:
        libc = ctypes.CDLL("msys-2.0.dll")
    elif ON_BSD:
        try:
            libc = ctypes.CDLL("libc.so")
        except AttributeError:
            libc = None
        except OSError:
            # OS X; can't use ctypes.util.find_library because that creates
            # a new process on Linux, which is undesirable.
            try:
                libc = ctypes.CDLL("libc.dylib")
            except OSError:
                libc = None
    elif ON_POSIX:
        try:
            libc = ctypes.CDLL("libc.so")
        except AttributeError:
            libc = None
        except OSError:
            # Debian and derivatives do the wrong thing because /usr/lib/libc.so
            # is a GNU ld script rather than an ELF object. To get around this, we
            # have to be more specific.
            # We don't want to use ctypes.util.find_library because that creates a
            # new process on Linux. We also don't want to try too hard because at
            # this point we're already pretty sure this isn't Linux.
            try:
                libc = ctypes.CDLL("libc.so.6")
            except OSError:
                libc = None
        if not hasattr(libc, "sysinfo"):
            # Not Linux.
            libc = None
    elif ON_WINDOWS:
        if hasattr(ctypes, "windll") and hasattr(ctypes.windll, "kernel32"):
            libc = ctypes.windll.kernel32
        else:
            try:
                # Windows CE uses the cdecl calling convention.
                libc = ctypes.CDLL("coredll.lib")
            except (AttributeError, OSError):
                libc = None
    elif ON_BEOS:
        libc = ctypes.CDLL("libroot.so")
    else:
        libc = None
    return libc


# Traceback (AttributeError)
Exception in thread Thread-2:
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/threading.py", line 917, in _bootstrap_inner
self.run()
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/xonsh/history/json.py", line 111, in run
files = self.files(only_unlocked=True)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/xonsh/history/json.py", line 133, in files
boot = uptime.boottime()
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/xonsh/xoreutils/uptime.py", line 270, in boottime
up = uptime()
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/xonsh/xoreutils/uptime.py", line 258, in uptime
up = _UPTIME_FUNCS.get(sys.platform, _uptime_bsd)()
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/xonsh/xoreutils/uptime.py", line 30, in _uptime_osx
bt = xlimps.macutils.sysctlbyname(b"kern.boottime", return_str=False)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/xonsh/macutils.py", line 14, in sysctlbyname
LIBC.sysctlbyname(name, None, byref(size), None, 0)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/xonsh/lazyasd.py", line 60, in __getattribute__
obj = self._lazy_obj()
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/xonsh/lazyasd.py", line 52, in _lazy_obj
obj = d['load']()
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/xonsh/platform.py", line 491, in LIBC
libc = ctypes.CDLL(ctypes.util.find_library("c"))
AttributeError: module 'ctypes' has no attribute 'util'

# Fixed code
def LIBC():
    """The platform dependent libc implementation."""
    global ctypes
    if ON_DARWIN:
        import ctypes.util

        libc = ctypes.CDLL(ctypes.util.find_library("c"))
    elif ON_CYGWIN:
        libc = ctypes.CDLL("cygwin1.dll")
    elif ON_MSYS:
        libc = ctypes.CDLL("msys-2.0.dll")
    elif ON_BSD:
        try:
            libc = ctypes.CDLL("libc.so")
        except AttributeError:
            libc = None
        except OSError:
            # OS X; can't use ctypes.util.find_library because that creates
            # a new process on Linux, which is undesirable.
            try:
                libc = ctypes.CDLL("libc.dylib")
            except OSError:
                libc = None
    elif ON_POSIX:
        try:
            libc = ctypes.CDLL("libc.so")
        except AttributeError:
            libc = None
        except OSError:
            # Debian and derivatives do the wrong thing because /usr/lib/libc.so
            # is a GNU ld script rather than an ELF object. To get around this, we
            # have to be more specific.
            # We don't want to use ctypes.util.find_library because that creates a
            # new process on Linux. We also don't want to try too hard because at
            # this point we're already pretty sure this isn't Linux.
            try:
                libc = ctypes.CDLL("libc.so.6")
            except OSError:
                libc = None
        if not hasattr(libc, "sysinfo"):
            # Not Linux.
            libc = None
    elif ON_WINDOWS:
        if hasattr(ctypes, "windll") and hasattr(ctypes.windll, "kernel32"):
            libc = ctypes.windll.kernel32
        else:
            try:
                # Windows CE uses the cdecl calling convention.
                libc = ctypes.CDLL("coredll.lib")
            except (AttributeError, OSError):
                libc = None
    elif ON_BEOS:
        libc = ctypes.CDLL("libroot.so")
    else:
        libc = None
    return libc