From 9cf19319c552abd96710e748944dd1cfc446c38d Mon Sep 17 00:00:00 2001 From: Dhinak G <17605561+dhinakg@users.noreply.github.com> Date: Sat, 10 Jul 2021 01:38:41 -0400 Subject: [PATCH] Attempt to fix pickle issues --- Resources/device_probe.py | 6 +++--- Resources/ioreg.py | 2 ++ 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Resources/device_probe.py b/Resources/device_probe.py index 738f74a0d..e37bc0d00 100644 --- a/Resources/device_probe.py +++ b/Resources/device_probe.py @@ -81,7 +81,7 @@ class PCIDevice: location = [hex(int(i, 16)) for i in ioreg.io_name_t_to_str(ioreg.IORegistryEntryGetLocationInPlane(entry, "IOService".encode(), None)[1]).split(",") + ["0"]] paths.append(f"Pci({location[0]},{location[1]})") elif ioreg.IOObjectConformsTo(entry, "IOACPIPlatformDevice".encode()): - paths.append(f"PciRoot({hex(int(ioreg.IORegistryEntryCreateCFProperty(entry, '_UID', ioreg.kCFAllocatorDefault, ioreg.kNilOptions) or 0))})") # type: ignore + paths.append(f"PciRoot({hex(int(ioreg.corefoundation_to_native(ioreg.IORegistryEntryCreateCFProperty(entry, '_UID', ioreg.kCFAllocatorDefault, ioreg.kNilOptions)) or 0))})") # type: ignore break elif ioreg.IOObjectConformsTo(entry, "IOPCIBridge".encode()): pass @@ -127,7 +127,7 @@ class WirelessCard(PCIDevice): interface = next(ioreg.ioiterator_to_list(ioreg.IOServiceGetMatchingServices(ioreg.kIOMasterPortDefault, matching_dict, None)[1]), None) if interface: - device.country_code = ioreg.IORegistryEntryCreateCFProperty(interface, "IO80211CountryCode", ioreg.kCFAllocatorDefault, ioreg.kNilOptions) # type: ignore # If not present, will be None anyways + device.country_code = ioreg.corefoundation_to_native(ioreg.IORegistryEntryCreateCFProperty(interface, "IO80211CountryCode", ioreg.kCFAllocatorDefault, ioreg.kNilOptions)) # type: ignore # If not present, will be None anyways else: device.country_code = None # type: ignore @@ -378,7 +378,7 @@ class Computer: parent = ioreg.IORegistryEntryGetParentEntry(device, "IOService".encode(), None)[1] ioreg.IOObjectRelease(device) - aspm: Union[int, bytes] = ioreg.IORegistryEntryCreateCFProperty(parent, "pci-aspm-default", ioreg.kCFAllocatorDefault, ioreg.kNilOptions) or 0 # type: ignore + aspm: Union[int, bytes] = ioreg.corefoundation_to_native(ioreg.IORegistryEntryCreateCFProperty(parent, "pci-aspm-default", ioreg.kCFAllocatorDefault, ioreg.kNilOptions)) or 0 # type: ignore if isinstance(aspm, bytes): aspm = int.from_bytes(aspm, byteorder="little") diff --git a/Resources/ioreg.py b/Resources/ioreg.py index e1b2b3378..ad435cc8f 100644 --- a/Resources/ioreg.py +++ b/Resources/ioreg.py @@ -218,6 +218,8 @@ def ioiterator_to_list(iterator: io_iterator_t): def corefoundation_to_native(collection): + if collection is None: # nullptr + return None native = Conversion.pythonCollectionFromPropertyList(collection) CFRelease(collection) return native