From 5e543c506f41ff85c1bd540450b5a25e154b7c1f Mon Sep 17 00:00:00 2001 From: MediaPipe Team Date: Mon, 17 Oct 2022 12:13:09 -0700 Subject: [PATCH] Fix unused variable warnings Remove some unused variables and add unused attribute to other variables PiperOrigin-RevId: 481706551 --- mediapipe/objc/MPPCameraInputSource.m | 3 +-- mediapipe/objc/MPPGraph.mm | 6 +++--- mediapipe/objc/MPPGraphTestBase.mm | 16 +++++----------- mediapipe/objc/MPPGraphTests.mm | 4 +--- 4 files changed, 10 insertions(+), 19 deletions(-) diff --git a/mediapipe/objc/MPPCameraInputSource.m b/mediapipe/objc/MPPCameraInputSource.m index b9718680c..73b3549c4 100644 --- a/mediapipe/objc/MPPCameraInputSource.m +++ b/mediapipe/objc/MPPCameraInputSource.m @@ -244,7 +244,7 @@ if ([_session canAddOutput:_depthDataOutput]) { [_session addOutput:_depthDataOutput]; - AVCaptureConnection* connection = + AVCaptureConnection* __unused connection = [_depthDataOutput connectionWithMediaType:AVMediaTypeDepthData]; // Set this when we have a handler. @@ -327,7 +327,6 @@ if (depthData.depthDataType != kCVPixelFormatType_DepthFloat32) { depthData = [depthData depthDataByConvertingToDepthDataType:kCVPixelFormatType_DepthFloat32]; } - CVPixelBufferRef depthBuffer = depthData.depthDataMap; [self.delegate processDepthData:depthData timestamp:timestamp fromSource:self]; } diff --git a/mediapipe/objc/MPPGraph.mm b/mediapipe/objc/MPPGraph.mm index 67d71720e..080cca20f 100644 --- a/mediapipe/objc/MPPGraph.mm +++ b/mediapipe/objc/MPPGraph.mm @@ -134,12 +134,12 @@ void CallFrameDelegate(void* wrapperVoid, const std::string& streamName, if (format == mediapipe::ImageFormat::SRGBA) { // Swap R and B channels. const uint8_t permuteMap[4] = {2, 1, 0, 3}; - vImage_Error vError = vImagePermuteChannels_ARGB8888( - &vSource, &vDestination, permuteMap, kvImageNoFlags); + vImage_Error __unused vError = + vImagePermuteChannels_ARGB8888(&vSource, &vDestination, permuteMap, kvImageNoFlags); _GTMDevAssert(vError == kvImageNoError, @"vImagePermuteChannels failed: %zd", vError); } else { // Convert grayscale back to BGRA - vImage_Error vError = vImageGrayToBGRA(&vSource, &vDestination); + vImage_Error __unused vError = vImageGrayToBGRA(&vSource, &vDestination); _GTMDevAssert(vError == kvImageNoError, @"vImageGrayToBGRA failed: %zd", vError); } diff --git a/mediapipe/objc/MPPGraphTestBase.mm b/mediapipe/objc/MPPGraphTestBase.mm index ddd15f736..eb4ea0535 100644 --- a/mediapipe/objc/MPPGraphTestBase.mm +++ b/mediapipe/objc/MPPGraphTestBase.mm @@ -32,10 +32,11 @@ static UIImage* UIImageWithPixelBuffer(CVPixelBufferRef pixelBuffer) { static void EnsureOutputDirFor(NSString *outputFile) { NSFileManager *fileManager = [NSFileManager defaultManager]; NSError *error = nil; - BOOL result = [fileManager createDirectoryAtPath:[outputFile stringByDeletingLastPathComponent] - withIntermediateDirectories:YES - attributes:nil - error:&error]; + BOOL __unused result = + [fileManager createDirectoryAtPath:[outputFile stringByDeletingLastPathComponent] + withIntermediateDirectories:YES + attributes:nil + error:&error]; // TODO: Log the error for clarity. The file-write will fail later // but it would be nice to see this error. However, 'error' is still testing // false and result is true even on an unwritable path-- not sure what's up. @@ -89,17 +90,10 @@ static void EnsureOutputDirFor(NSString *outputFile) { __block CVPixelBufferRef output; graph.delegate = self; - // The XCTAssert macros contain references to self, which causes a retain cycle, - // since the block retains self and self retains the block. The cycle is broken - // at the end of this method, with _pixelBufferOutputBlock = nil, but Clang does - // not realize that and outputs a warning. WEAKIFY and STRONGIFY, though not - // strictly necessary, are used here to avoid the warning. - WEAKIFY(self); if (!_pixelBufferOutputBlock) { XCTestExpectation* outputReceived = [self expectationWithDescription:@"output received"]; _pixelBufferOutputBlock = ^(MPPGraph* outputGraph, CVPixelBufferRef outputBuffer, const std::string& outputStreamName) { - STRONGIFY(self); XCTAssertEqualObjects(outputGraph, graph); XCTAssertEqual(outputStreamName, outputStream); CFRetain(outputBuffer); diff --git a/mediapipe/objc/MPPGraphTests.mm b/mediapipe/objc/MPPGraphTests.mm index c3cf48047..a68d4528d 100644 --- a/mediapipe/objc/MPPGraphTests.mm +++ b/mediapipe/objc/MPPGraphTests.mm @@ -287,9 +287,7 @@ REGISTER_CALCULATOR(ErrorCalculator); CFHolder inputBuffer; absl::Status status = CreateCVPixelBufferFromCGImage(_sourceImage.CGImage, &inputBuffer); XCTAssert(status.ok()); - CVPixelBufferRef outputBuffer = [self runGraph:_graph - withPixelBuffer:*inputBuffer - packetType:MPPPacketTypePixelBuffer]; + [self runGraph:_graph withPixelBuffer:*inputBuffer packetType:MPPPacketTypePixelBuffer]; __weak MPPGraph* weakGraph = _graph; _graph = nil; XCTAssertNil(weakGraph);