Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable ARC on Apple #4

Merged
merged 1 commit into from
Apr 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/apple/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
add_library(benoni STATIC http.mm)

target_compile_options(benoni PUBLIC "-fobjc-arc")

target_include_directories(benoni PUBLIC "${PROJECT_SOURCE_DIR}/include")

target_link_libraries(benoni PUBLIC "-framework Foundation")
11 changes: 5 additions & 6 deletions src/apple/http.mm
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ - (BenoniHTTPTaskContextWrap *)initWithContext:

- (void)dealloc {
delete context;
[super dealloc];
}
@end

Expand Down Expand Up @@ -123,7 +122,7 @@ - (void)URLSession:(NSURLSession *)session
HTTPTaskContext *context = [contextWrap context];

if (context->data == nil) {
context->data = [[NSMutableData data] retain];
context->data = [NSMutableData data];
}

[context->data appendData:data];
Expand All @@ -140,7 +139,7 @@ - (void)URLSession:(NSURLSession *)session

if (error) {
std::string error_string([[error localizedDescription] UTF8String]);
[contextWrap dealloc];
contextMap_[key] = nil;
callback(std::move(error_string));
return;
}
Expand All @@ -159,11 +158,11 @@ - (void)URLSession:(NSURLSession *)session
}
[responseString appendString:chunk];
}];
[context->data release];
context->data = nil;

if (success == NO) {
std::string error_string("response body has invalid encoding");
[contextWrap dealloc];
contextMap_[key] = nil;
callback(std::move(error_string));
return;
}
Expand All @@ -175,7 +174,7 @@ - (void)URLSession:(NSURLSession *)session
.status = context->status,
.headers = std::move(context->headers),
};
[contextWrap dealloc];
contextMap_[key] = nil;
callback(response);
}
@end
Expand Down