Skip to content

Commit 4e7b476

Browse files
author
theraven
committed
Change [1] to [] for variable length structure elements (C99 - silences 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.
1 parent 219f921 commit 4e7b476

File tree

8 files changed

+51
-12
lines changed

8 files changed

+51
-12
lines changed

class.h

+40-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,22 @@
11
#ifndef __OBJC_CLASS_H_INCLUDED
22
#define __OBJC_CLASS_H_INCLUDED
3+
4+
/**
5+
* Overflow bitfield. Used for bitfields that are more than 63 bits.
6+
*/
7+
struct objc_bitfield
8+
{
9+
/**
10+
* The number of elements in the values array.
11+
*/
12+
int32_t length;
13+
/**
14+
* An array of values. Each 32 bits is stored in the native endian for the
15+
* platform.
16+
*/
17+
int32_t values[0];
18+
};
19+
320
struct objc_class
421
{
522
/**
@@ -83,7 +100,9 @@ struct objc_class
83100
*/
84101

85102
/**
86-
* The version of the ABI used for this class. This is currently always zero.
103+
* The version of the ABI used for this class. Zero indicates the ABI first
104+
* implemented by clang 1.0. One indicates the presence of bitmaps
105+
* indicating the offsets of strong, weak, and unretained ivars.
87106
*/
88107
long abi_version;
89108

@@ -108,6 +127,26 @@ struct objc_class
108127
* the accessor methods for each property.
109128
*/
110129
struct objc_property_list *properties;
130+
131+
/**
132+
* GC / ARC ABI: Fields below this point only exist if abi_version is >= 1.
133+
*/
134+
135+
/**
136+
* The location of all strong pointer ivars declared by this class.
137+
*
138+
* If the low bit of this field is 0, then this is a pointer to an
139+
* objc_bitfield structure. If the low bit is 1, then the remaining 63
140+
* bits are set, from low to high, for each ivar in the object that is a
141+
* strong pointer.
142+
*/
143+
int64_t strong_pointers;
144+
/**
145+
* The location of all zeroing weak pointer ivars declared by this class.
146+
* The format of this field is the same as the format of the
147+
* strong_pointers field.
148+
*/
149+
int64_t weak_pointers;
111150
};
112151

113152
/**

encoding2.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ static void parse_struct(const char **type, type_parser callback, void *context)
130130

131131
inline static void round_up(size_t *v, size_t b)
132132
{
133-
if (0 == b)
133+
if (0 == b)
134134
{
135135
return;
136136
}

gc_boehm.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ struct objc_slot* objc_get_slot(Class cls, SEL selector);
6161
#ifndef __has_builtin
6262
# define __has_builtin(x) 0
6363
#endif
64-
#if __has_builtin(__sync_swap)
64+
#if !__has_builtin(__sync_swap)
6565
#define __sync_swap __sync_lock_test_and_set
6666
#endif
6767

ivar.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ struct objc_ivar_list
4141
int count;
4242
/**
4343
* An array of instance variable metadata structures. Note that this array
44-
* has count elements, not 1.
44+
* has count elements.
4545
*/
46-
struct objc_ivar ivar_list[1];
46+
struct objc_ivar ivar_list[];
4747
};

method_list.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ struct objc_method_list
3737
*/
3838
int count;
3939
/**
40-
* An array of methods. Note that the actual size of this is count, not 1.
40+
* An array of methods. Note that the actual size of this is count.
4141
*/
42-
struct objc_method methods[1];
42+
struct objc_method methods[];
4343
};

module.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ struct objc_symbol_table_abi_8
3737
* Current compilers only use this for constant strings. The runtime
3838
* permits other types.
3939
*/
40-
void *definitions[1];
40+
void *definitions[];
4141
};
4242

4343
/**
@@ -98,5 +98,5 @@ struct objc_static_instance_list
9898
/**
9999
* NULL-terminated array of statically-allocated instances.
100100
*/
101-
id instances[1];
101+
id instances[];
102102
};

properties.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,6 @@ struct objc_property_list
9595
/**
9696
* List of properties.
9797
*/
98-
struct objc_property properties[1];
98+
struct objc_property properties[];
9999
};
100100

protocol.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ struct objc_method_description_list
1212
* field points to the name, not to the index of the uniqued version of the
1313
* name. You must not use them for dispatch.
1414
*/
15-
struct objc_selector methods[1];
15+
struct objc_selector methods[];
1616
};
1717

1818

@@ -116,6 +116,6 @@ struct objc_protocol_list
116116
*
117117
* The instances in this array may be any version of protocols.
118118
*/
119-
Protocol2 *list[1];
119+
Protocol2 *list[];
120120
};
121121

0 commit comments

Comments
 (0)