Skip to content

Commit

Permalink
Fix upgrading legacy properties with qualifiers.
Browse files Browse the repository at this point in the history
This fixes PropertyIntrospectionTest2_arc with the 1.x ABI and enables
the test that was disabled in this mode.
  • Loading branch information
davidchisnall committed May 20, 2019
1 parent 5aa82d0 commit 375018a
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 21 deletions.
10 changes: 3 additions & 7 deletions Test/PropertyIntrospectionTest2_arc.m
Expand Up @@ -510,9 +510,7 @@ void structDefault2Setter(id self, SEL _cmd, struct YorkshireTeaStruct value) {

int main(void)
{
#ifdef NEW_ABI
testProperty("atomicBoolDefault", "TAB,VatomicBoolDefault", ATTRS(ATTR("T", "AB"), ATTR("V", "atomicBoolDefault")));
#endif
testProperty("charDefault", "Tc,VcharDefault", ATTRS(ATTR("T", "c"), ATTR("V", "charDefault")));
testProperty("doubleDefault", "Td,VdoubleDefault", ATTRS(ATTR("T", "d"), ATTR("V", "doubleDefault")));
testProperty("enumDefault", "Ti,VenumDefault", ATTRS(ATTR("T", "i"), ATTR("V", "enumDefault")));
Expand Down Expand Up @@ -602,11 +600,9 @@ int main(void)
ATTR("G", "dynamicGetterSetter"),
ATTR("S", "setDynamicGetterSetter:")));

Protocol *testProto = objc_getProtocol("ProtocolTest");
#ifdef NEW_ABI
testPropertyForProtocol(testProto, "atomicBoolDefault", "TAB", ATTRS(ATTR("T", "AB")));
#endif
testPropertyForProtocol(testProto, "charDefault", "Tc", ATTRS(ATTR("T", "c")));
Protocol *testProto = objc_getProtocol("ProtocolTest");
testPropertyForProtocol(testProto, "atomicBoolDefault", "TAB", ATTRS(ATTR("T", "AB")));
testPropertyForProtocol(testProto, "charDefault", "Tc", ATTRS(ATTR("T", "c")));
testPropertyForProtocol(testProto, "doubleDefault", "Td", ATTRS(ATTR("T", "d")));
testPropertyForProtocol(testProto, "enumDefault", "Ti", ATTRS(ATTR("T", "i")));
testPropertyForProtocol(testProto, "floatDefault", "Tf", ATTRS(ATTR("T", "f")));
Expand Down
47 changes: 33 additions & 14 deletions legacy.c
Expand Up @@ -168,12 +168,36 @@ static inline BOOL checkAttribute(char field, int attr)

static void upgradeProperty(struct objc_property *n, struct objc_property_gsv1 *o)
{
size_t typeSize = lengthOfTypeEncoding(o->getter_types);
char *typeEncoding = malloc(typeSize + 1);
memcpy(typeEncoding, o->getter_types, typeSize);
typeEncoding[typeSize] = 0;

char *typeEncoding;
ptrdiff_t typeSize;
if (o->name[0] == '\0')
{
n->name = o->name + o->name[1];
n->attributes = o->name + 2;
// If we have an attribute string, then it will contain a more accurate
// version of the types than we'll find in the getter (qualifiers such
// as _Atomic and volatile may be dropped)
assert(n->attributes[0] == 'T');
const char *type_start = &n->attributes[1];
const char *type_end = strchr(type_start, ',');
if (type_end == NULL)
{
type_end = type_start + strlen(type_start);
}
typeSize = type_end - type_start;
typeEncoding = malloc(typeSize + 1);
memcpy(typeEncoding, type_start, typeSize);
typeEncoding[typeSize] = 0;
}
else
{
typeSize = (ptrdiff_t)lengthOfTypeEncoding(o->getter_types);
typeEncoding = malloc(typeSize + 1);
memcpy(typeEncoding, o->getter_types, typeSize);
typeEncoding[typeSize] = 0;
}
n->type = typeEncoding;

if (o->getter_name)
{
n->getter = sel_registerTypedName_np(o->getter_name, o->getter_types);
Expand All @@ -185,8 +209,6 @@ static void upgradeProperty(struct objc_property *n, struct objc_property_gsv1 *

if (o->name[0] == '\0')
{
n->name = o->name + o->name[1];
n->attributes = o->name + 2;
return;
}

Expand Down Expand Up @@ -251,13 +273,10 @@ static void upgradeProperty(struct objc_property *n, struct objc_property_gsv1 *
*(insert++) = 0;
*(insert++) = 0;
// Set the type encoding
if (NULL != typeEncoding)
{
*(insert++) = 'T';
memcpy(insert, typeEncoding, typeSize);
insert += typeSize;
needsComma = YES;
}
*(insert++) = 'T';
memcpy(insert, typeEncoding, typeSize);
insert += typeSize;
needsComma = YES;
// Set the flags
memcpy(insert, flags, i);
insert += i;
Expand Down

0 comments on commit 375018a

Please sign in to comment.