Skip to content
This repository was archived by the owner on Aug 31, 2021. It is now read-only.

Commit 6acc827

Browse files
committed
[[ Bug 20886 ]] Fix crash when class omitted in objc binding
1 parent bcfd2ca commit 6acc827

File tree

3 files changed

+22
-6
lines changed

3 files changed

+22
-6
lines changed

docs/lcb/notes/20886.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# [20886] Fix crash when class is omitted in obj-c binding string

libscript/src/script-instance.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -978,12 +978,6 @@ __MCScriptResolveForeignFunctionBindingForObjC(MCScriptInstanceRef p_instance,
978978
{
979979
return false;
980980
}
981-
982-
MCAutoStringRefAsUTF8String t_class_cstring;
983-
if (!t_class_cstring.Lock(*t_class))
984-
{
985-
return false;
986-
}
987981

988982
bool t_valid = true;
989983
bool t_is_dynamic = MCStringIsEmpty(*t_class);
@@ -1002,6 +996,12 @@ __MCScriptResolveForeignFunctionBindingForObjC(MCScriptInstanceRef p_instance,
1002996
}
1003997
else
1004998
{
999+
MCAutoStringRefAsUTF8String t_class_cstring;
1000+
if (!t_class_cstring.Lock(*t_class))
1001+
{
1002+
return false;
1003+
}
1004+
10051005
t_objc_class = objc_getClass(*t_class_cstring);
10061006
if (t_objc_class == nullptr)
10071007
{

tests/lcb/vm/interop-objc.lcb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,21 @@ public handler TestDynamicInstanceMethodBinding()
221221
end unsafe
222222
end handler
223223

224+
foreign handler DynamicGetIntNoClass(in pObject as ObjcId) returns CInt \
225+
binds to "objc:-intValue"
226+
227+
public handler TestDynamicInstanceMethodNoClassCrash()
228+
if not the operating system is in ["mac", "ios"] then
229+
skip test "obj-c dynamic instance method binding no class crash" \
230+
because "not implemented on" && the operating system
231+
return
232+
end if
233+
234+
unsafe
235+
test "dynamic method binds" when DynamicGetIntNoClass is not nothing
236+
end unsafe
237+
end handler
238+
224239
foreign handler DynamicAlloc() returns ObjcRetainedId \
225240
binds to "objc:.+alloc"
226241

0 commit comments

Comments
 (0)