[Bug 220596] [NEW PORT] shells/xonsh: Python-ish BASH-wards shell
bugzilla-noreply at freebsd.org
bugzilla-noreply at freebsd.org
Mon Sep 18 10:39:30 UTC 2017
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=220596
Shane <FreeBSD at ShaneWare.Biz> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |FreeBSD at ShaneWare.Biz
--- Comment #29 from Shane <FreeBSD at ShaneWare.Biz> ---
(In reply to Roberto Fernandez Cueto from comment #27)
Your example use of find_library is wrong.
>From pydocs -
> name is the library name without any prefix like lib, suffix like .so, .dylib or version number (this is the form used for the posix linker option -l)
sysctlbyname takes a char* as the first arg - in ctypes get that from
create_string_buffer(), also prefixing it as bytes works - b'kern.boottime'
While it doesn't actually make a difference, using ctypes.c_size_t for sz would
be more correct.
So for the proper results in 2.7 and 3.x use
import ctypes
import ctypes.util
libc = ctypes.CDLL(ctypes.util.find_library('c'), use_errno=True)
sz = ctypes.c_size_t(0)
Then either
sysctl_name = ctypes.create_string_buffer(b'kern.boottime')
libc.sysctlbyname(sysctl_name, None, ctypes.byref(sz), None, 0)
or
libc.sysctlbyname(b'kern.boottime', None, ctypes.byref(sz), None, 0)
So to get rid of the exception on starting xonsh -
You will find in _uptime_bsd() xp.LIBC is None so that points to the first fix
being back in __amalgam__.py:LIBC()
Adjust the ON_BSD test to use find_library() - the same as ON_DARWIN
elif ON_BSD:
try:
libc = ctypes.CDLL(ctypes.util.find_library("c"))
Then in _uptime_bsd() either prefix the sysctlname with b or use
create_string_buffer()
xp.LIBC.sysctlbyname(b'kern.boottime', None, ctypes.byref(sz), None, 0)
--
You are receiving this mail because:
You are on the CC list for the bug.
More information about the freebsd-python
mailing list