I have a script where I'm trying to get the system attributes; eventually this will gather memory information. I have isolated the crash to this line of code:
from ctypes import POINTER
from objc_util import ObjCClass, ObjCInstance, c, c_void_p
NSHomeDirectory = c.NSHomeDirectory
NSHomeDirectory.restype = c_void_p
NSHomeDirectory.argtype = []
NSFileManager = ObjCClass('NSFileManager')
LP_c_void_p = POINTER(c_void_p)
def get_system_attributes():
file_manager = NSFileManager.defaultManager()
error = LP_c_void_p()
attributes = file_manager.attributesOfFileSystemForPath_error_(
ObjCInstance(
NSHomeDirectory()
).cString(),
error
)
return attributes
get_system_attributes()
attributesOfFileSystemForPath_error_ takes a string and an error pointer. It crashes when it gets to the error inside that function. I think it crashes due to an NSError object being created. Any ideas on how to stop the crash?