Skip to content

Commit 5caed51

Browse files
anviatmetafacebook-github-bot
authored andcommitted
Fix nullable-to-nonnull conversion errors in ExecuTorchModule.mm for Xcode 26
Summary: In Xcode 26 (xcodestaging), NSString.UTF8String is annotated as returning a nullable pointer (const char * _Nullable). When this value is passed directly to C++ methods that expect const char * _Nonnull, the compiler emits -Wnullable-to-nonnull-conversion warnings which are promoted to errors via -Werror. This causes a build failure in xplat/executorch/extension/apple:ExecuTorch that blocks downstream test targets including BSLInspirationActionsTests owned by edits_workflows_ios. The fix adds ?: "" (nil-coalescing to empty string) at each call site where methodName.UTF8String or similar is passed to a C++ API expecting a non-null pointer. Since the methodName parameters are already typed as nonnull NSString *, the fallback is defensive only — it satisfies the compiler nullability analysis without changing runtime behavior. Differential Revision: D103724159
1 parent c7e8628 commit 5caed51

1 file changed

Lines changed: 10 additions & 10 deletions

File tree

extension/apple/ExecuTorch/Exported/ExecuTorchModule.mm

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -258,11 +258,11 @@ - (instancetype)initWithFilePath:(NSString *)filePath
258258
std::vector<std::string> dataFilePathsVector;
259259
if (dataFilePaths != nil) {
260260
for (NSString *dataFile in dataFilePaths) {
261-
dataFilePathsVector.emplace_back(dataFile.UTF8String);
261+
dataFilePathsVector.emplace_back(dataFile.UTF8String ?: "");
262262
}
263263
}
264264
_module = std::make_unique<Module>(
265-
filePath.UTF8String,
265+
filePath.UTF8String ?: "",
266266
dataFilePathsVector,
267267
static_cast<Module::LoadMode>(loadMode)
268268
);
@@ -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());
@@ -366,7 +366,7 @@ - (nullable ExecuTorchMethodMetadata *)methodMetadata:(NSString *)methodName
366366
- (nullable NSArray<ExecuTorchValue *> *)executeMethod:(NSString *)methodName
367367
withInputs:(NSArray<ExecuTorchValue *> *)values
368368
error:(NSError **)error {
369-
const char *methodNameString = methodName.UTF8String;
369+
const char *methodNameString = methodName.UTF8String ?: "";
370370
__block auto errorCode = Error::Ok;
371371
[values enumerateObjectsUsingBlock:^(ExecuTorchValue *value, NSUInteger index, BOOL *stop) {
372372
errorCode = _module->set_input(methodNameString, toEValue(value), index);
@@ -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)