Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions jre_emul/Classes/J2ObjC_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,18 @@ __attribute__((always_inline)) inline id JreRetainedAutoreleasedReturnValue(id v
# define WEAK_ __unsafe_unretained
#endif

#ifndef J2OBJC_EXTERNALLY_RETAINED
#if __has_feature(objc_arc) && __has_attribute(objc_externally_retained)
# define J2OBJC_EXTERNALLY_RETAINED __attribute__((objc_externally_retained))
# define J2OBJC_ASSUME_EXTERNALLY_RETAINED_BEGIN _Pragma("clang attribute J2OBJC_ASSUME_EXTERNALLY_RETAINED.push(__attribute__((objc_externally_retained)), apply_to=any(function, block, objc_method))")
# define J2OBJC_ASSUME_EXTERNALLY_RETAINED_END _Pragma("clang attribute J2OBJC_ASSUME_EXTERNALLY_RETAINED.pop")
#else // __OBJC__ && objc_arc && objc_externally_retained
# define J2OBJC_EXTERNALLY_RETAINED
# define J2OBJC_ASSUME_EXTERNALLY_RETAINED_BEGIN
# define J2OBJC_ASSUME_EXTERNALLY_RETAINED_END
#endif // __OBJC__ && objc_arc && objc_externally_retained
#endif // !J2OBJC_EXTERNALLY_RETAINED

CF_EXTERN_C_BEGIN

id JreThrowNullPointerException(void) __attribute__((noreturn));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,7 @@ void EnumGenerator::GenerateSource(io::Printer* printer) {
"\n"
"@end\n"
"\n"
"J2OBJC_ASSUME_EXTERNALLY_RETAINED_BEGIN\n"
"J2OBJC_CLASS_TYPE_LITERAL_SOURCE($classname$)\n"
"\n"
"IOSObjectArray *$classname$_values(void) {\n"
Expand Down Expand Up @@ -471,6 +472,7 @@ void EnumGenerator::GenerateSource(io::Printer* printer) {
"}\n",
"classname", ClassName(descriptor_), "name", "UNRECOGNIZED");
}
printer->Print("\nJ2OBJC_ASSUME_EXTERNALLY_RETAINED_END\n");
}

} // namespace j2objc
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,7 @@ void MessageGenerator::GenerateSource(io::Printer* printer) {
"\n"
"@end\n"
"\n"
"J2OBJC_ASSUME_EXTERNALLY_RETAINED_BEGIN\n"
"J2OBJC_CLASS_TYPE_LITERAL_SOURCE($classname$)\n"
"\n"
"$classname$ * _Nonnull $classname$_getDefaultInstance(void) {\n"
Expand Down Expand Up @@ -575,6 +576,7 @@ void MessageGenerator::GenerateSource(io::Printer* printer) {
"$classname$_descriptor_, input, registry);\n"
"}\n",
"classname", ClassName(descriptor_));
printer->Print("\nJ2OBJC_ASSUME_EXTERNALLY_RETAINED_END\n");

for (int i = 0; i < descriptor_->real_oneof_decl_count(); i++) {
OneofGenerator(descriptor_->oneof_decl(i)).GenerateSource(printer);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,7 @@ void MessageLiteGenerator::GenerateSource(io::Printer* printer) {
"\n"
"@end\n"
"\n"
"J2OBJC_ASSUME_EXTERNALLY_RETAINED_BEGIN\n"
"J2OBJC_CLASS_TYPE_LITERAL_SOURCE($classname$)\n"
"\n"
"$classname$ * _Nonnull $classname$_getDefaultInstance(void) {\n"
Expand Down Expand Up @@ -455,6 +456,7 @@ void MessageLiteGenerator::GenerateSource(io::Printer* printer) {
"$classname$_descriptor_, input, registry);\n"
"}\n",
"classname", ClassName(descriptor_));
printer->Print("\nJ2OBJC_ASSUME_EXTERNALLY_RETAINED_END\n");

for (int i = 0; i < descriptor_->oneof_decl_count(); i++) {
OneofGenerator(descriptor_->oneof_decl(i)).GenerateSource(printer);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,7 @@ void OneofGenerator::GenerateSource(io::Printer* printer) {
"\n"
"@end\n"
"\n"
"J2OBJC_ASSUME_EXTERNALLY_RETAINED_BEGIN\n"
"J2OBJC_CLASS_TYPE_LITERAL_SOURCE($classname$)\n"
"\n"
"IOSObjectArray *$classname$_values(void) {\n"
Expand Down Expand Up @@ -379,6 +380,7 @@ void OneofGenerator::GenerateSource(io::Printer* printer) {
"classname", CaseClassName(descriptor_),
"name", CaseValueName(descriptor_->field(i)));
}
printer->Print("\nJ2OBJC_ASSUME_EXTERNALLY_RETAINED_END\n");
}

void OneofGenerator::GenerateMessageOrBuilder(io::Printer* printer) {
Expand Down