Skip to content

Commit

Permalink
fix: Remove categories functions that are striped of static library (g…
Browse files Browse the repository at this point in the history
…etsentry#3764)

Remove categories functions that are striped of static library

Co-authored-by: Philipp Hofmann <[email protected]>
  • Loading branch information
2 people authored and Threema committed May 21, 2024
1 parent a8ec641 commit d29d6fb
Show file tree
Hide file tree
Showing 61 changed files with 256 additions and 304 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## Unreleased

- Fix runtime error when including Sentry as a static lib (#3764)

## 8.22.1

### Fixes
Expand Down
56 changes: 24 additions & 32 deletions Sentry.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

29 changes: 14 additions & 15 deletions Sources/Sentry/NSArray+SentrySanitize.m
Original file line number Diff line number Diff line change
@@ -1,30 +1,29 @@
#import "NSArray+SentrySanitize.h"
#import "NSDate+SentryExtras.h"
#import "NSDictionary+SentrySanitize.h"
#import "SentryDateUtils.h"
#import "SentryNSDictionarySanitize.h"

@implementation
NSArray (SentrySanitize)
@implementation SentryArray

- (NSArray *)sentry_sanitize
+ (NSArray *)sanitizeArray:(NSArray *)array;
{
NSMutableArray *array = [NSMutableArray array];
for (id rawValue in self) {

NSMutableArray *result = [NSMutableArray array];
for (id rawValue in array) {
if ([rawValue isKindOfClass:NSString.class]) {
[array addObject:rawValue];
[result addObject:rawValue];
} else if ([rawValue isKindOfClass:NSNumber.class]) {
[array addObject:rawValue];
[result addObject:rawValue];
} else if ([rawValue isKindOfClass:NSDictionary.class]) {
[array addObject:[(NSDictionary *)rawValue sentry_sanitize]];
[result addObject:sentry_sanitize((NSDictionary *)rawValue)];
} else if ([rawValue isKindOfClass:NSArray.class]) {
[array addObject:[(NSArray *)rawValue sentry_sanitize]];
[result addObject:[SentryArray sanitizeArray:rawValue]];
} else if ([rawValue isKindOfClass:NSDate.class]) {
[array addObject:[(NSDate *)rawValue sentry_toIso8601String]];
NSDate *date = (NSDate *)rawValue;
[result addObject:sentry_toIso8601String(date)];
} else {
[array addObject:[rawValue description]];
[result addObject:[rawValue description]];
}
}
return array;
return result;
}

@end
16 changes: 0 additions & 16 deletions Sources/Sentry/NSData+Sentry.m

This file was deleted.

5 changes: 2 additions & 3 deletions Sources/Sentry/NSLocale+Sentry.m
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
#import "NSLocale+Sentry.h"

@implementation
NSLocale (Sentry)
@implementation SentryLocale

- (BOOL)sentry_timeIs24HourFormat
+ (BOOL)timeIs24HourFormat
{
NSDateFormatter *formatter = [NSDateFormatter new];
[formatter setDateStyle:NSDateFormatterNoStyle];
Expand Down
24 changes: 13 additions & 11 deletions Sources/Sentry/NSMutableDictionary+Sentry.m
Original file line number Diff line number Diff line change
@@ -1,27 +1,29 @@
#import "NSMutableDictionary+Sentry.h"

@implementation
NSMutableDictionary (Sentry)
@implementation SentryDictionary

- (void)mergeEntriesFromDictionary:(NSDictionary *)otherDictionary
+ (void)mergeEntriesFromDictionary:(NSDictionary *)dictionary
intoDictionary:(NSMutableDictionary *)destination
{
[otherDictionary enumerateKeysAndObjectsUsingBlock:^(id otherKey, id otherObj, BOOL *stop) {
[dictionary enumerateKeysAndObjectsUsingBlock:^(id otherKey, id otherObj, BOOL *stop) {
if ([otherObj isKindOfClass:NSDictionary.class] &&
[self[otherKey] isKindOfClass:NSDictionary.class]) {
NSMutableDictionary *mergedDict = ((NSDictionary *)self[otherKey]).mutableCopy;
[mergedDict mergeEntriesFromDictionary:(NSDictionary *)otherObj];
self[otherKey] = mergedDict;
[destination[otherKey] isKindOfClass:NSDictionary.class]) {
NSMutableDictionary *mergedDict = ((NSDictionary *)destination[otherKey]).mutableCopy;
[SentryDictionary mergeEntriesFromDictionary:otherObj intoDictionary:mergedDict];
destination[otherKey] = mergedDict;
return;
}

self[otherKey] = otherObj;
destination[otherKey] = otherObj;
}];
}

- (void)setBoolValue:(nullable NSNumber *)value forKey:(NSString *)key
+ (void)setBoolValue:(nullable NSNumber *)value
forKey:(NSString *)key
intoDictionary:(NSMutableDictionary *)destination
{
if (value != nil) {
[self setValue:@([value boolValue]) forKey:key];
[destination setValue:@([value boolValue]) forKey:key];
}
}

Expand Down
2 changes: 1 addition & 1 deletion Sources/Sentry/SentryAppStartMeasurement.m
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#if SENTRY_UIKIT_AVAILABLE

# import "NSDate+SentryExtras.h"
# import "SentryDateUtils.h"
# import "SentryLog.h"
# import <Foundation/Foundation.h>

Expand Down
6 changes: 3 additions & 3 deletions Sources/Sentry/SentryAppState.m
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#import <NSDate+SentryExtras.h>
#import <SentryAppState.h>
#import <SentryDateUtils.h>

NS_ASSUME_NONNULL_BEGIN

Expand Down Expand Up @@ -64,7 +64,7 @@ - (nullable instancetype)initWithJSONObject:(NSDictionary *)jsonObject
id systemBoot = [jsonObject valueForKey:@"system_boot_timestamp"];
if (systemBoot == nil || ![systemBoot isKindOfClass:[NSString class]])
return nil;
NSDate *systemBootTimestamp = [NSDate sentry_fromIso8601String:systemBoot];
NSDate *systemBootTimestamp = sentry_fromIso8601String(systemBoot);
if (nil == systemBootTimestamp) {
return nil;
}
Expand Down Expand Up @@ -111,7 +111,7 @@ - (nullable instancetype)initWithJSONObject:(NSDictionary *)jsonObject
[data setValue:self.osVersion forKey:@"os_version"];
[data setValue:self.vendorId forKey:@"vendor_id"];
[data setValue:@(self.isDebugging) forKey:@"is_debugging"];
[data setValue:[self.systemBootTimestamp sentry_toIso8601String]
[data setValue:sentry_toIso8601String(self.systemBootTimestamp)
forKey:@"system_boot_timestamp"];
[data setValue:@(self.isActive) forKey:@"is_active"];
[data setValue:@(self.wasTerminated) forKey:@"was_terminated"];
Expand Down
10 changes: 5 additions & 5 deletions Sources/Sentry/SentryBreadcrumb.m
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#import "SentryBreadcrumb.h"
#import "NSDate+SentryExtras.h"
#import "NSDictionary+SentrySanitize.h"
#import "SentryDateUtils.h"
#import "SentryLevelMapper.h"
#import "SentryNSDictionarySanitize.h"

@interface
SentryBreadcrumb ()
Expand All @@ -25,7 +25,7 @@ - (instancetype)initWithDictionary:(NSDictionary *)dictionary
if ([key isEqualToString:@"level"] && isString) {
self.level = sentryLevelForString(value);
} else if ([key isEqualToString:@"timestamp"] && isString) {
self.timestamp = [NSDate sentry_fromIso8601String:value];
self.timestamp = sentry_fromIso8601String(value);
} else if ([key isEqualToString:@"category"] && isString) {
self.category = value;
} else if ([key isEqualToString:@"type"] && isString) {
Expand Down Expand Up @@ -66,11 +66,11 @@ - (instancetype)init
NSMutableDictionary *serializedData = [NSMutableDictionary new];

[serializedData setValue:nameForSentryLevel(self.level) forKey:@"level"];
[serializedData setValue:[self.timestamp sentry_toIso8601String] forKey:@"timestamp"];
[serializedData setValue:sentry_toIso8601String(self.timestamp) forKey:@"timestamp"];
[serializedData setValue:self.category forKey:@"category"];
[serializedData setValue:self.type forKey:@"type"];
[serializedData setValue:self.message forKey:@"message"];
[serializedData setValue:[self.data sentry_sanitize] forKey:@"data"];
[serializedData setValue:sentry_sanitize(self.data) forKey:@"data"];
NSDictionary<NSString *, id> *unknown = self.unknown;
if (unknown != nil) {
for (id key in unknown) {
Expand Down
10 changes: 5 additions & 5 deletions Sources/Sentry/SentryClient.m
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#import "SentryClient.h"
#import "NSDictionary+SentrySanitize.h"
#import "NSLocale+Sentry.h"
#import "SentryAppState.h"
#import "SentryAppStateManager.h"
Expand Down Expand Up @@ -28,6 +27,7 @@
#import "SentryMechanismMeta.h"
#import "SentryMessage.h"
#import "SentryMeta.h"
#import "SentryNSDictionarySanitize.h"
#import "SentryNSError.h"
#import "SentryOptions+Private.h"
#import "SentryPropagationContext.h"
Expand Down Expand Up @@ -260,7 +260,7 @@ - (SentryEvent *)buildErrorEvent:(NSError *)error

// Once the UI displays the mechanism data we can the userInfo from the event.context using only
// the root error's userInfo.
[self setUserInfo:[error.userInfo sentry_sanitize] withEvent:event];
[self setUserInfo:sentry_sanitize(error.userInfo) withEvent:event];

return event;
}
Expand Down Expand Up @@ -302,7 +302,7 @@ - (SentryException *)exceptionForError:(NSError *)error
// use a simple enum.
mechanism.desc = error.description;

NSDictionary<NSString *, id> *userInfo = [error.userInfo sentry_sanitize];
NSDictionary<NSString *, id> *userInfo = sentry_sanitize(error.userInfo);
mechanism.data = userInfo;
exception.mechanism = mechanism;

Expand Down Expand Up @@ -743,7 +743,7 @@ - (void)setUserInfo:(NSDictionary *)userInfo withEvent:(SentryEvent *)event
context = [event.context mutableCopy];
}

[context setValue:[userInfo sentry_sanitize] forKey:@"user info"];
[context setValue:sentry_sanitize(userInfo) forKey:@"user info"];
}
}

Expand Down Expand Up @@ -794,7 +794,7 @@ - (void)applyCultureContextToEvent:(SentryEvent *)event
}
#endif
culture[@"locale"] = self.locale.localeIdentifier;
culture[@"is_24_hour_format"] = @(self.locale.sentry_timeIs24HourFormat);
culture[@"is_24_hour_format"] = @([SentryLocale timeIs24HourFormat]);
culture[@"timezone"] = self.timezone.name;
}];
}
Expand Down
7 changes: 3 additions & 4 deletions Sources/Sentry/SentryCrashReportConverter.m
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#import "SentryCrashReportConverter.h"
#import "NSDate+SentryExtras.h"
#import "SentryBreadcrumb.h"
#import "SentryCrashStackCursor.h"
#import "SentryDateUtils.h"
#import "SentryDebugMeta.h"
#import "SentryEvent.h"
#import "SentryException.h"
Expand Down Expand Up @@ -104,8 +104,7 @@ - (SentryEvent *_Nullable)convertReportToEvent
event.timestamp = [NSDate
dateWithTimeIntervalSince1970:[self.report[@"report"][@"timestamp"] integerValue]];
} else {
event.timestamp =
[NSDate sentry_fromIso8601String:self.report[@"report"][@"timestamp"]];
event.timestamp = sentry_fromIso8601String(self.report[@"report"][@"timestamp"]);
}
event.threads = [self convertThreads];
event.debugMeta = [self debugMetaForThreads:event.threads];
Expand Down Expand Up @@ -172,7 +171,7 @@ - (SentryUser *_Nullable)convertUser
category:storedCrumb[@"category"]];
crumb.message = storedCrumb[@"message"];
crumb.type = storedCrumb[@"type"];
crumb.timestamp = [NSDate sentry_fromIso8601String:storedCrumb[@"timestamp"]];
crumb.timestamp = sentry_fromIso8601String(storedCrumb[@"timestamp"]);
crumb.data = storedCrumb[@"data"];
[breadcrumbs addObject:crumb];
}
Expand Down
4 changes: 2 additions & 2 deletions Sources/Sentry/SentryCrashScopeObserver.m
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#import "SentryLevelMapper.h"
#import <Foundation/Foundation.h>
#import <NSData+Sentry.h>
#import <SentryBreadcrumb.h>
#import <SentryCrashJSONCodec.h>
#import <SentryCrashJSONCodecObjC.h>
#import <SentryCrashScopeObserver.h>
#import <SentryLog.h>
#import <SentryNSDataUtils.h>
#import <SentryScopeSyncC.h>
#import <SentryUser.h>

Expand Down Expand Up @@ -156,7 +156,7 @@ - (nullable NSData *)toJSONEncodedCString:(id)toSerialize
}

// C strings need to be null terminated
return [json sentry_nullTerminated];
return sentry_nullTerminated(json);
}

@end
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
#import "NSDate+SentryExtras.h"
#import "SentryDateUtils.h"

NS_ASSUME_NONNULL_BEGIN

@implementation
NSDate (SentryExtras)

+ (NSDateFormatter *)getIso8601Formatter
NSDateFormatter *
sentryGetIso8601Formatter(void)
{
static NSDateFormatter *isoFormatter = nil;
static dispatch_once_t onceToken;
Expand All @@ -29,7 +27,8 @@ + (NSDateFormatter *)getIso8601Formatter
* nanoseconds to the output of NSDateFormatter please use a numeric float instead, which can be
* retrieved with timeIntervalSince1970.
*/
+ (NSDateFormatter *)getIso8601FormatterWithMillisecondPrecision
NSDateFormatter *
sentryGetIso8601FormatterWithMillisecondPrecision(void)
{
static NSDateFormatter *isoFormatter = nil;
static dispatch_once_t onceToken;
Expand All @@ -43,12 +42,13 @@ + (NSDateFormatter *)getIso8601FormatterWithMillisecondPrecision
return isoFormatter;
}

+ (NSDate *)sentry_fromIso8601String:(NSString *)string
NSDate *
sentry_fromIso8601String(NSString *string)
{
NSDate *date = [[self.class getIso8601FormatterWithMillisecondPrecision] dateFromString:string];
NSDate *date = [sentryGetIso8601FormatterWithMillisecondPrecision() dateFromString:string];
if (nil == date) {
// Parse date with low precision formatter for backward compatible
return [[self.class getIso8601Formatter] dateFromString:string];
return [sentryGetIso8601Formatter() dateFromString:string];
} else {
return date;
}
Expand All @@ -58,11 +58,11 @@ + (NSDate *)sentry_fromIso8601String:(NSString *)string
* Only works with milliseconds precision. For more details see
* getIso8601FormatterWithMillisecondPrecision.
*/
- (NSString *)sentry_toIso8601String
NSString *
sentry_toIso8601String(NSDate *date)
{
return [[self.class getIso8601FormatterWithMillisecondPrecision] stringFromDate:self];
NSDateFormatter *formatter = sentryGetIso8601FormatterWithMillisecondPrecision();
return [formatter stringFromDate:date];
}

@end

NS_ASSUME_NONNULL_END
9 changes: 4 additions & 5 deletions Sources/Sentry/SentryEvent.m
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#import "NSDate+SentryExtras.h"
#import "NSDictionary+SentrySanitize.h"
#import "SentryANRTrackingIntegration.h"
#import "SentryBreadcrumb.h"
#import "SentryClient.h"
Expand All @@ -11,6 +9,7 @@
#import "SentryLevelMapper.h"
#import "SentryMessage.h"
#import "SentryMeta.h"
#import "SentryNSDictionarySanitize.h"
#import "SentryRequest.h"
#import "SentryStacktrace.h"
#import "SentrySwift.h"
Expand Down Expand Up @@ -72,7 +71,7 @@ - (instancetype)initWithError:(NSError *)error

// This is important here, since we probably use __sentry internal extras
// before
[serializedData setValue:[self.extra sentry_sanitize] forKey:@"extra"];
[serializedData setValue:sentry_sanitize(self.extra) forKey:@"extra"];
[serializedData setValue:self.tags forKey:@"tags"];

return serializedData;
Expand Down Expand Up @@ -120,7 +119,7 @@ - (void)addThreads:(NSMutableDictionary *)serializedData

- (void)addSimpleProperties:(NSMutableDictionary *)serializedData
{
[serializedData setValue:[self.sdk sentry_sanitize] forKey:@"sdk"];
[serializedData setValue:sentry_sanitize(self.sdk) forKey:@"sdk"];
[serializedData setValue:self.releaseName forKey:@"release"];
[serializedData setValue:self.dist forKey:@"dist"];
[serializedData setValue:self.environment forKey:@"environment"];
Expand All @@ -144,7 +143,7 @@ - (void)addSimpleProperties:(NSMutableDictionary *)serializedData
[serializedData setValue:breadcrumbs forKey:@"breadcrumbs"];
}

[serializedData setValue:[self.context sentry_sanitize] forKey:@"contexts"];
[serializedData setValue:sentry_sanitize(self.context) forKey:@"contexts"];

if (nil != self.message) {
[serializedData setValue:[self.message serialize] forKey:@"message"];
Expand Down
Loading

0 comments on commit d29d6fb

Please sign in to comment.