Skip to content

Commit 5371bed

Browse files
committed
fix: intel simulators
1 parent effd867 commit 5371bed

File tree

1 file changed

+32
-1
lines changed

1 file changed

+32
-1
lines changed

NativeScript/runtime/ClassBuilder.cpp

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,42 @@
11
#include "ClassBuilder.h"
2+
#if TARGET_CPU_X86_64 || TARGET_CPU_X86
3+
#include "SpinLock.h"
4+
#endif
25

36
namespace tns {
47

58
// Moved this method in a separate .cpp file because ARC destroys the class
69
// created with objc_allocateClassPair when the control leaves this method scope
7-
10+
// TODO: revist this as there are x86 simulator issues, so maybe a lock is
11+
// needed regardless
812
Class ClassBuilder::GetExtendedClass(std::string baseClassName,
913
std::string staticClassName) {
14+
#if TARGET_CPU_X86_64 || TARGET_CPU_X86
15+
// X86 simulators have this bugged, so we fallback to old behavior
16+
static SpinMutex m;
17+
SpinLock lock(m);
18+
Class baseClass = objc_getClass(baseClassName.c_str());
19+
std::string name =
20+
!staticClassName.empty()
21+
? staticClassName
22+
: baseClassName + "_" +
23+
std::to_string(++ClassBuilder::classNameCounter_);
24+
Class clazz = objc_getClass(name.c_str());
25+
26+
if (clazz != nil) {
27+
int i = 1;
28+
std::string initialName = name;
29+
while (clazz != nil) {
30+
name = initialName + std::to_string(i++);
31+
clazz = objc_getClass(name.c_str());
32+
}
33+
}
34+
35+
clazz = objc_allocateClassPair(baseClass, name.c_str(), 0);
36+
37+
objc_registerClassPair(clazz);
38+
return clazz;
39+
#else
1040
Class baseClass = objc_getClass(baseClassName.c_str());
1141
std::string name =
1242
!staticClassName.empty()
@@ -30,6 +60,7 @@ Class ClassBuilder::GetExtendedClass(std::string baseClassName,
3060

3161
objc_registerClassPair(clazz);
3262
return clazz;
63+
#endif
3364
}
3465

3566
} // namespace tns

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy