Skip to content

Commit 8fbfed9

Browse files
authored
Guard NSString.UTF8String against nil in ExecuTorchModule.mm
Differential Revision: D105904682 Pull Request resolved: pytorch#19712
1 parent dbcf6ac commit 8fbfed9

1 file changed

Lines changed: 8 additions & 8 deletions

File tree

extension/apple/ExecuTorch/Exported/ExecuTorchModule.mm

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

320320
- (BOOL)loadMethod:(NSString *)methodName
321321
error:(NSError **)error {
322-
const auto errorCode = _module->load_method(methodName.UTF8String);
322+
const auto errorCode = _module->load_method(methodName.UTF8String ?: "");
323323
if (errorCode != Error::Ok) {
324324
if (error) {
325325
*error = ExecuTorchErrorWithCode((ExecuTorchErrorCode)errorCode);
@@ -363,7 +363,7 @@ - (BOOL)loadMethod:(NSString *)methodName
363363
// passed through to program_->load_method and is not cached on the C++
364364
// Module. ARC keeps `options` alive for the duration of this call via
365365
// the parameter, so no extra retention is needed here.
366-
const auto errorCode = _module->load_method(methodName.UTF8String,
366+
const auto errorCode = _module->load_method(methodName.UTF8String ?: "",
367367
/*planned_memory=*/nullptr,
368368
/*event_tracer=*/nullptr,
369369
[options cppMap]);
@@ -377,11 +377,11 @@ - (BOOL)loadMethod:(NSString *)methodName
377377
}
378378

379379
- (BOOL)isMethodLoaded:(NSString *)methodName {
380-
return _module->is_method_loaded(methodName.UTF8String);
380+
return _module->is_method_loaded(methodName.UTF8String ?: "");
381381
}
382382

383383
- (BOOL)unloadMethod:(NSString *)methodName {
384-
const auto didUnload = _module->unload_method(methodName.UTF8String);
384+
const auto didUnload = _module->unload_method(methodName.UTF8String ?: "");
385385
[_inputs removeObjectForKey:methodName];
386386
[_outputs removeObjectForKey:methodName];
387387
return didUnload;
@@ -404,7 +404,7 @@ - (BOOL)unloadMethod:(NSString *)methodName {
404404

405405
- (nullable ExecuTorchMethodMetadata *)methodMetadata:(NSString *)methodName
406406
error:(NSError **)error {
407-
const auto result = _module->method_meta(methodName.UTF8String);
407+
const auto result = _module->method_meta(methodName.UTF8String ?: "");
408408
if (!result.ok()) {
409409
if (error) {
410410
*error = ExecuTorchErrorWithCode((ExecuTorchErrorCode)result.error());
@@ -549,7 +549,7 @@ - (BOOL)setInput:(ExecuTorchValue *)value
549549
forMethod:(NSString *)methodName
550550
atIndex:(NSInteger)index
551551
error:(NSError **)error {
552-
const auto errorCode = _module->set_input(methodName.UTF8String, toEValue(value), index);
552+
const auto errorCode = _module->set_input(methodName.UTF8String ?: "", toEValue(value), index);
553553
if (errorCode != Error::Ok) {
554554
if (error) {
555555
*error = ExecuTorchErrorWithCode((ExecuTorchErrorCode)errorCode);
@@ -589,7 +589,7 @@ - (BOOL)setInputs:(NSArray<ExecuTorchValue *> *)values
589589
for (ExecuTorchValue *value in values) {
590590
inputs.push_back(toEValue(value));
591591
}
592-
const auto errorCode = _module->set_inputs(methodName.UTF8String, inputs);
592+
const auto errorCode = _module->set_inputs(methodName.UTF8String ?: "", inputs);
593593
if (errorCode != Error::Ok) {
594594
if (error) {
595595
*error = ExecuTorchErrorWithCode((ExecuTorchErrorCode)errorCode);
@@ -632,7 +632,7 @@ - (BOOL)setOutput:(ExecuTorchValue *)value
632632
forMethod:(NSString *)methodName
633633
atIndex:(NSInteger)index
634634
error:(NSError **)error {
635-
const auto errorCode = _module->set_output(methodName.UTF8String, toEValue(value), index);
635+
const auto errorCode = _module->set_output(methodName.UTF8String ?: "", toEValue(value), index);
636636
if (errorCode != Error::Ok) {
637637
if (error) {
638638
*error = ExecuTorchErrorWithCode((ExecuTorchErrorCode)errorCode);

0 commit comments

Comments
 (0)