Skip to content

Commit

Permalink
Change [1] to [] for variable length structure elements (C99 - silenc…
Browse files Browse the repository at this point in the history
…es array out of bounds errors).

Added fields to the end of the class structure for strong / weak ivar bitmaps (not yet generated by any compiler).

Fixed definition of __sync_swap() so that it works on GCC again.
  • Loading branch information
theraven committed Jul 12, 2011
1 parent 219f921 commit 4e7b476
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 12 deletions.
41 changes: 40 additions & 1 deletion class.h
@@ -1,5 +1,22 @@
#ifndef __OBJC_CLASS_H_INCLUDED
#define __OBJC_CLASS_H_INCLUDED

/**
* Overflow bitfield. Used for bitfields that are more than 63 bits.
*/
struct objc_bitfield
{
/**
* The number of elements in the values array.
*/
int32_t length;
/**
* An array of values. Each 32 bits is stored in the native endian for the
* platform.
*/
int32_t values[0];
};

struct objc_class
{
/**
Expand Down Expand Up @@ -83,7 +100,9 @@ struct objc_class
*/

/**
* The version of the ABI used for this class. This is currently always zero.
* The version of the ABI used for this class. Zero indicates the ABI first
* implemented by clang 1.0. One indicates the presence of bitmaps
* indicating the offsets of strong, weak, and unretained ivars.
*/
long abi_version;

Expand All @@ -108,6 +127,26 @@ struct objc_class
* the accessor methods for each property.
*/
struct objc_property_list *properties;

/**
* GC / ARC ABI: Fields below this point only exist if abi_version is >= 1.
*/

/**
* The location of all strong pointer ivars declared by this class.
*
* If the low bit of this field is 0, then this is a pointer to an
* objc_bitfield structure. If the low bit is 1, then the remaining 63
* bits are set, from low to high, for each ivar in the object that is a
* strong pointer.
*/
int64_t strong_pointers;
/**
* The location of all zeroing weak pointer ivars declared by this class.
* The format of this field is the same as the format of the
* strong_pointers field.
*/
int64_t weak_pointers;
};

/**
Expand Down
2 changes: 1 addition & 1 deletion encoding2.c
Expand Up @@ -130,7 +130,7 @@ static void parse_struct(const char **type, type_parser callback, void *context)

inline static void round_up(size_t *v, size_t b)
{
if (0 == b)
if (0 == b)
{
return;
}
Expand Down
2 changes: 1 addition & 1 deletion gc_boehm.c
Expand Up @@ -61,7 +61,7 @@ struct objc_slot* objc_get_slot(Class cls, SEL selector);
#ifndef __has_builtin
# define __has_builtin(x) 0
#endif
#if __has_builtin(__sync_swap)
#if !__has_builtin(__sync_swap)
#define __sync_swap __sync_lock_test_and_set
#endif

Expand Down
4 changes: 2 additions & 2 deletions ivar.h
Expand Up @@ -41,7 +41,7 @@ struct objc_ivar_list
int count;
/**
* An array of instance variable metadata structures. Note that this array
* has count elements, not 1.
* has count elements.
*/
struct objc_ivar ivar_list[1];
struct objc_ivar ivar_list[];
};
4 changes: 2 additions & 2 deletions method_list.h
Expand Up @@ -37,7 +37,7 @@ struct objc_method_list
*/
int count;
/**
* An array of methods. Note that the actual size of this is count, not 1.
* An array of methods. Note that the actual size of this is count.
*/
struct objc_method methods[1];
struct objc_method methods[];
};
4 changes: 2 additions & 2 deletions module.h
Expand Up @@ -37,7 +37,7 @@ struct objc_symbol_table_abi_8
* Current compilers only use this for constant strings. The runtime
* permits other types.
*/
void *definitions[1];
void *definitions[];
};

/**
Expand Down Expand Up @@ -98,5 +98,5 @@ struct objc_static_instance_list
/**
* NULL-terminated array of statically-allocated instances.
*/
id instances[1];
id instances[];
};
2 changes: 1 addition & 1 deletion properties.h
Expand Up @@ -95,6 +95,6 @@ struct objc_property_list
/**
* List of properties.
*/
struct objc_property properties[1];
struct objc_property properties[];
};

4 changes: 2 additions & 2 deletions protocol.h
Expand Up @@ -12,7 +12,7 @@ struct objc_method_description_list
* field points to the name, not to the index of the uniqued version of the
* name. You must not use them for dispatch.
*/
struct objc_selector methods[1];
struct objc_selector methods[];
};


Expand Down Expand Up @@ -116,6 +116,6 @@ struct objc_protocol_list
*
* The instances in this array may be any version of protocols.
*/
Protocol2 *list[1];
Protocol2 *list[];
};

0 comments on commit 4e7b476

Please sign in to comment.