Skip to content

Commit

Permalink
Enable ARC on Apple (#4)
Browse files Browse the repository at this point in the history
Signed-off-by: Darshan Sen <raisinten@gmail.com>
  • Loading branch information
RaisinTen authored Apr 2, 2024
1 parent 861006a commit 68d79ab
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
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

0 comments on commit 68d79ab

Please sign in to comment.