diff --git a/Source/cifframe.m b/Source/cifframe.m index 5aac4bb26..11c3a48aa 100644 --- a/Source/cifframe.m +++ b/Source/cifframe.m @@ -259,12 +259,8 @@ cifframe_arg_addr(cifframe_t *cframe, int index) ffi_type * cifframe_type(const char *typePtr, const char **advance) { - static ffi_type stypeNSPoint = { 0 }; - static ffi_type stypeNSRange = { 0 }; - static ffi_type stypeNSRect = { 0 }; - static ffi_type stypeNSSize = { 0 }; const char *type; - ffi_type *ftype = 0; + ffi_type *ftype; typePtr = objc_skip_type_qualifiers (typePtr); type = typePtr; @@ -357,9 +353,9 @@ cifframe_type(const char *typePtr, const char **advance) if (GSSelectorTypesMatch(typePtr - 1, @encode(NSRange))) { static ffi_type *elems[3]; - static ffi_type *ftype = &stypeNSRange; + static ffi_type stype = { 0 }; - if (ftype->type == 0) + if (stype.type == 0) { const char *t = @encode(NSUInteger); @@ -379,41 +375,19 @@ cifframe_type(const char *typePtr, const char **advance) } elems[1] = elems[0]; elems[2] = 0; - ftype->elements = elems; - ftype->type = FFI_TYPE_STRUCT; - } - typePtr = objc_skip_typespec (typePtr - 1); - break; - } - else if (GSSelectorTypesMatch(typePtr - 1, @encode(NSPoint))) - { - static ffi_type *elems[3]; - static ffi_type *ftype = &stypeNSPoint; - - if (ftype->type == 0) - { - if (*@encode(CGFloat) == _C_DBL) - { - elems[0] = &ffi_type_double; - } - else - { - elems[0] = &ffi_type_float; - } - elems[1] = elems[0]; - elems[2] = 0; - ftype->elements = elems; - ftype->type = FFI_TYPE_STRUCT; + stype.elements = elems; + stype.type = FFI_TYPE_STRUCT; } + ftype = &stype; typePtr = objc_skip_typespec (typePtr - 1); break; } else if (GSSelectorTypesMatch(typePtr - 1, @encode(NSSize))) { static ffi_type *elems[3]; - static ffi_type *ftype = &stypeNSSize; + static ffi_type stype = { 0 }; - if (ftype->type == 0) + if (stype.type == 0) { if (*@encode(CGFloat) == _C_DBL) { @@ -425,28 +399,30 @@ cifframe_type(const char *typePtr, const char **advance) } elems[1] = elems[0]; elems[2] = 0; - ftype->elements = elems; - ftype->type = FFI_TYPE_STRUCT; + stype.elements = elems; + stype.type = FFI_TYPE_STRUCT; } + ftype = &stype; typePtr = objc_skip_typespec (typePtr - 1); break; } else if (GSSelectorTypesMatch(typePtr - 1, @encode(NSRect))) { static ffi_type *elems[3]; - static ffi_type *ftype = &stypeNSRect; + static ffi_type stype = { 0 }; - if (ftype->type == 0) + if (stype.type == 0) { /* An NSRect is an NSPoint and an NSSize, but those * two structures are actually identical. */ elems[0] = cifframe_type(@encode(NSSize), NULL); - elems[1] = cifframe_type(@encode(NSPoint), NULL); + elems[1] = elems[0]; elems[2] = 0; - ftype->elements = elems; - ftype->type = FFI_TYPE_STRUCT; + stype.elements = elems; + stype.type = FFI_TYPE_STRUCT; } + ftype = &stype; typePtr = objc_skip_typespec (typePtr - 1); break; } @@ -521,14 +497,8 @@ cifframe_type(const char *typePtr, const char **advance) NSCAssert(typePtr, @"End of signature while parsing"); if (align > max_align) { - if (ftype && ftype->type == FFI_TYPE_STRUCT - && ftype != &stypeNSPoint - && ftype != &stypeNSRange - && ftype != &stypeNSRect - && ftype != &stypeNSSize) - { - free(ftype); - } + if (ftype && ftype->type == FFI_TYPE_STRUCT) + free(ftype); ftype = local; max_align = align; }