From 719703fd2912876a4b48a093c1ec200d397ae8b6 Mon Sep 17 00:00:00 2001
From: Sergey Fedorov <barracuda@macos-powerpc.org>
Date: Fri, 7 Aug 2026 03:17:46 +0000
Subject: [PATCH 31/38] physicalmemory (Apple): use legacy
 NSPropertyListSerialization API

propertyListWithData:options:format:error: requires a newer Foundation;
use propertyListFromData:mutabilityOption:format:errorDescription:
instead, replace subscripting with valueForKey:/objectForKey:, restrict
the Apple Silicon branch to __arm64__, and wrap in an NSAutoreleasePool
on pre-10.9 targets.

Ported from https://github.com/macos-powerpc/powerpc-ports/blob/main/sysutils/fastfetch/files/0012-Misc-fixes-for-legacy-systems.patch
---
 .../physicalmemory/physicalmemory_apple.m     | 57 ++++++++++++-------
 1 file changed, 37 insertions(+), 20 deletions(-)

diff --git a/src/detection/physicalmemory/physicalmemory_apple.m b/src/detection/physicalmemory/physicalmemory_apple.m
index c58c2f14b..faaa83a63 100644
--- a/src/detection/physicalmemory/physicalmemory_apple.m
+++ b/src/detection/physicalmemory/physicalmemory_apple.m
@@ -4,7 +4,16 @@
 #include "common/strutil.h"
 #include "common/apple/cf_helpers.h"
 
-#import <Foundation/Foundation.h>
+#include <Foundation/Foundation.h>
+#include <AvailabilityMacros.h>
+
+#if MAC_OS_X_VERSION_MIN_REQUIRED < 1090
+#define POOLSTART NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+#define POOLEND   [pool release];
+#else
+#define POOLSTART
+#define POOLEND
+#endif
 
 static void appendDevice(
     FFlist* result,
@@ -12,7 +21,7 @@ static void appendDevice(
     NSString* vendor,
     NSString* size,
 
-    // Intel only
+    // Intel and PowerPC
     NSString* locator,
     NSString* serial,
     NSString* partNumber,
@@ -67,6 +76,7 @@ static void appendDevice(
 
 static const char* detectFromSystemProfiler(FFlist* result)
 {
+    POOLSTART
     FF_STRBUF_AUTO_DESTROY buffer = ffStrbufCreate();
     if (ffProcessAppendStdOut(&buffer, (char* const[]) {
         "system_profiler",
@@ -78,31 +88,37 @@ static const char* detectFromSystemProfiler(FFlist* result)
     }) != nullptr)
         return "Starting `system_profiler SPMemoryDataType -xml -detailLevel full` failed";
 
-    NSArray* arr = [NSPropertyListSerialization propertyListWithData:[NSData dataWithBytes:buffer.chars length:buffer.length]
-                    options:NSPropertyListImmutable
-                    format:nil
-                    error:nil];
-    if (!arr || !arr.count)
+    NSString* error;
+    NSData* plistData = [NSData dataWithBytes:buffer.chars length:buffer.length];
+    NSPropertyListFormat format;
+    NSArray* arr = [NSPropertyListSerialization propertyListFromData:plistData
+                    mutabilityOption:NSPropertyListImmutable
+                    format:&format
+                    errorDescription:&error];
+    if (!arr) {
+        [error release];
         return "system_profiler SPMemoryDataType returned an empty array";
+    }
 
-    for (NSDictionary* data in arr[0][@"_items"])
+    for (NSDictionary* data in [[arr objectAtIndex:0] objectForKey:@"_items"])
     {
-        if (data[@"_items"])
+        if ([data objectForKey:@"_items"])
         {
-            // for Intel
-            for (NSDictionary* item in data[@"_items"])
+            // for Intel and PowerPC
+            for (NSDictionary* item in [data objectForKey:@"_items"])
             {
                 appendDevice(result,
-                    item[@"dimm_type"],
-                    item[@"dimm_manufacturer"],
-                    item[@"dimm_size"],
-                    item[@"_name"],
-                    item[@"dimm_serial_number"],
-                    item[@"dimm_part_number"],
-                    item[@"dimm_speed"],
-                    !![data[@"global_ecc_state"] isEqualToString:@"ecc_enabled"]);
+                    [item valueForKey:@"dimm_type"],
+                    [item valueForKey:@"dimm_manufacturer"],
+                    [item valueForKey:@"dimm_size"],
+                    [item valueForKey:@"_name"],
+                    [item valueForKey:@"dimm_serial_number"],
+                    [item valueForKey:@"dimm_part_number"],
+                    [item valueForKey:@"dimm_speed"],
+                    !![[data objectForKey:@"global_ecc_state"] isEqualToString:@"ecc_enabled"]);
             }
         }
+#ifdef __arm64__
         else
         {
             // for Apple Silicon
@@ -116,8 +132,9 @@ static const char* detectFromSystemProfiler(FFlist* result)
                 nil,
                 false);
         }
+#endif
     }
-
+    POOLEND
     return nullptr;
 }
 
-- 
2.43.0

