From a74649d285c0868f5046a3ef9b96dfe7699e67b2 Mon Sep 17 00:00:00 2001 From: Ramanpreet Nara Date: Wed, 2 Apr 2025 16:45:18 -0700 Subject: [PATCH] Convert RCTUtils into objc++ Summary: I'll need to use feature flags in this file. And those are only accessible from c++. Changelog: [Internal] Reviewed By: lyahdav Differential Revision: D72326982 fbshipit-source-id: 4c9dfd0e5baa69d979b12914f289d58be6e123a8 --- .../React/Base/{RCTUtils.m => RCTUtils.mm} | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) rename packages/react-native/React/Base/{RCTUtils.m => RCTUtils.mm} (98%) diff --git a/packages/react-native/React/Base/RCTUtils.m b/packages/react-native/React/Base/RCTUtils.mm similarity index 98% rename from packages/react-native/React/Base/RCTUtils.m rename to packages/react-native/React/Base/RCTUtils.mm index 1e496625889..d31a211f935 100644 --- a/packages/react-native/React/Base/RCTUtils.m +++ b/packages/react-native/React/Base/RCTUtils.mm @@ -112,7 +112,7 @@ NSString *__nullable RCTJSONStringify(id __nullable jsonObject, NSError **error) } } -static id __nullable _RCTJSONParse(NSString *__nullable jsonString, BOOL mutable, NSError **error) +static id __nullable _RCTJSONParse(NSString *__nullable jsonString, BOOL isMutable, NSError **error) { static SEL JSONKitSelector = NULL; static SEL JSONKitMutableSelector = NULL; @@ -133,7 +133,7 @@ static id __nullable _RCTJSONParse(NSString *__nullable jsonString, BOOL mutable unichar c = [jsonString characterAtIndex:i]; if (strchr("{[", c)) { static const int options = (1 << 2); // loose unicode - SEL selector = mutable ? JSONKitMutableSelector : JSONKitSelector; + SEL selector = isMutable ? JSONKitMutableSelector : JSONKitSelector; return ((id(*)(id, SEL, int, NSError **))objc_msgSend)(jsonString, selector, options, error); } if (!strchr(" \r\n\t", c)) { @@ -162,7 +162,7 @@ static id __nullable _RCTJSONParse(NSString *__nullable jsonString, BOOL mutable } } NSJSONReadingOptions options = NSJSONReadingAllowFragments; - if (mutable) { + if (isMutable) { options |= NSJSONReadingMutableContainers; } return [NSJSONSerialization JSONObjectWithData:jsonData options:options error:error]; @@ -674,9 +674,15 @@ NSData *__nullable RCTGzipData(NSData *__nullable input, float level) } void *libz = dlopen("/usr/lib/libz.dylib", RTLD_LAZY); - int (*deflateInit2_)(z_streamp, int, int, int, int, int, const char *, int) = dlsym(libz, "deflateInit2_"); - int (*deflate)(z_streamp, int) = dlsym(libz, "deflate"); - int (*deflateEnd)(z_streamp) = dlsym(libz, "deflateEnd"); + + typedef int (*DeflateInit2_)(z_streamp, int, int, int, int, int, const char *, int); + DeflateInit2_ deflateInit2_ = (DeflateInit2_)dlsym(libz, "deflateInit2_"); + + typedef int (*Deflate)(z_streamp, int); + Deflate deflate = (Deflate)dlsym(libz, "deflate"); + + typedef int (*DeflateEnd)(z_streamp); + DeflateEnd deflateEnd = (DeflateEnd)dlsym(libz, "deflateEnd"); z_stream stream; stream.zalloc = Z_NULL;