我使用 python ctypes 获取 system.hardware.uuid。在 i386 机器上执行的 python 程序不会失败。但是在 x64 机器上执行的相同程序会产生错误。
这是我的python类:
self._hal = ctypes.cdll.LoadLibrary(find_library('hal'))
self._ctx = self._hal.libhal_ctx_new()
self._dbus_error = dbus_error()
self._hal.dbus_error_init(ctypes.byref(self._dbus_error))
self._conn = self._hal.dbus_bus_get(ctypes.c_int(1),ctypes.byref(self._dbus_error))
self._hal.libhal_ctx_set_dbus_connection(self._ctx, self._conn)
udi = ctypes.c_char_p("/org/freedesktop/Hal/devices/computer")
key = ctypes.c_char_p("system.hardware.uuid")
self._hal.libhal_device_get_property_string.restype = ctypes.c_char_p
self._uuid_ = self._hal.libhal_device_get_property_string(self._ctx, udi, key, self._dbus_error)
return self._uuid_
这是错误消息:
[tmp]$ ./test-uid.py
*** glibc detected *** /usr/bin/python: free(): invalid pointer: 0x00000000007546c0 ***
======= Backtrace: =========
/lib64/libc.so.6[0x2af62a5741df]
/lib64/libc.so.6(cfree+0x4b)[0x2af62a57463b]
/lib64/libdbus-1.so.3(dbus_error_free+0x29)[0x379fa10219]
/lib64/libdbus-1.so.3(dbus_move_error+0x31)[0x379fa10281]
/usr/lib64/libhal.so.1(libhal_device_get_property_string+0xaf)[0x379da05e5f]