Skip to content

Commit a0ba4ec

Browse files
Keion Anvaripourfacebook-github-bot
authored andcommitted
Fix nullable pointer errors in ExecuTorchModule.mm
Summary: NSString.UTF8String returns a nullable pointer (const char * _Nullable), but the ExecuTorch C++ Module methods expect non-nullable const char *. This causes 14 compilation errors (7 call sites × 2 architectures) that block downstream iOS test targets from building, including TWAppCoordinatorTests for Oculus Twilight. The fix adds the idiomatic Objective-C null-coalescing operator (`?: ""`) at each call site. Since the methodName parameters are already non-null NSString *, UTF8String will never actually return null in practice - this just satisfies the compiler's nullability checker. Differential Revision: D103190695
1 parent 94d2881 commit a0ba4ec

1 file changed

Lines changed: 7 additions & 7 deletions

File tree

extension/apple/ExecuTorch/Exported/ExecuTorchModule.mm

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ - (BOOL)isLoaded {
314314

315315
- (BOOL)loadMethod:(NSString *)methodName
316316
error:(NSError **)error {
317-
const auto errorCode = _module->load_method(methodName.UTF8String);
317+
const auto errorCode = _module->load_method(methodName.UTF8String ?: "");
318318
if (errorCode != Error::Ok) {
319319
if (error) {
320320
*error = ExecuTorchErrorWithCode((ExecuTorchErrorCode)errorCode);
@@ -325,11 +325,11 @@ - (BOOL)loadMethod:(NSString *)methodName
325325
}
326326

327327
- (BOOL)isMethodLoaded:(NSString *)methodName {
328-
return _module->is_method_loaded(methodName.UTF8String);
328+
return _module->is_method_loaded(methodName.UTF8String ?: "");
329329
}
330330

331331
- (BOOL)unloadMethod:(NSString *)methodName {
332-
const auto didUnload = _module->unload_method(methodName.UTF8String);
332+
const auto didUnload = _module->unload_method(methodName.UTF8String ?: "");
333333
[_inputs removeObjectForKey:methodName];
334334
[_outputs removeObjectForKey:methodName];
335335
return didUnload;
@@ -352,7 +352,7 @@ - (BOOL)unloadMethod:(NSString *)methodName {
352352

353353
- (nullable ExecuTorchMethodMetadata *)methodMetadata:(NSString *)methodName
354354
error:(NSError **)error {
355-
const auto result = _module->method_meta(methodName.UTF8String);
355+
const auto result = _module->method_meta(methodName.UTF8String ?: "");
356356
if (!result.ok()) {
357357
if (error) {
358358
*error = ExecuTorchErrorWithCode((ExecuTorchErrorCode)result.error());
@@ -497,7 +497,7 @@ - (BOOL)setInput:(ExecuTorchValue *)value
497497
forMethod:(NSString *)methodName
498498
atIndex:(NSInteger)index
499499
error:(NSError **)error {
500-
const auto errorCode = _module->set_input(methodName.UTF8String, toEValue(value), index);
500+
const auto errorCode = _module->set_input(methodName.UTF8String ?: "", toEValue(value), index);
501501
if (errorCode != Error::Ok) {
502502
if (error) {
503503
*error = ExecuTorchErrorWithCode((ExecuTorchErrorCode)errorCode);
@@ -537,7 +537,7 @@ - (BOOL)setInputs:(NSArray<ExecuTorchValue *> *)values
537537
for (ExecuTorchValue *value in values) {
538538
inputs.push_back(toEValue(value));
539539
}
540-
const auto errorCode = _module->set_inputs(methodName.UTF8String, inputs);
540+
const auto errorCode = _module->set_inputs(methodName.UTF8String ?: "", inputs);
541541
if (errorCode != Error::Ok) {
542542
if (error) {
543543
*error = ExecuTorchErrorWithCode((ExecuTorchErrorCode)errorCode);
@@ -580,7 +580,7 @@ - (BOOL)setOutput:(ExecuTorchValue *)value
580580
forMethod:(NSString *)methodName
581581
atIndex:(NSInteger)index
582582
error:(NSError **)error {
583-
const auto errorCode = _module->set_output(methodName.UTF8String, toEValue(value), index);
583+
const auto errorCode = _module->set_output(methodName.UTF8String ?: "", toEValue(value), index);
584584
if (errorCode != Error::Ok) {
585585
if (error) {
586586
*error = ExecuTorchErrorWithCode((ExecuTorchErrorCode)errorCode);

0 commit comments

Comments
 (0)