ObjFW  Check-in [428520105b]

Overview
Comment:objc_exit(): Fix the first class not being free'd

Also cleans up runtime/hashtable.m a little.

Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 428520105b504ee0ef897d7b150398ae61b0f9cb1b923cc17e953119c6bfb646
User & Date: js on 2014-05-15 03:39:47
Other Links: manifest | tags
Context
2014-05-15
04:06
Remove usage of empty initializer extension check-in: f178d11592 user: js tags: trunk
03:39
objc_exit(): Fix the first class not being free'd check-in: 428520105b user: js tags: trunk
01:50
Don't define _*_SOURCE check-in: 17be12b6e5 user: js tags: trunk
Changes

Modified src/runtime/class.m from [0d2c7753b9] to [e257cf48b1].

904
905
906
907
908
909
910




911
912
913
914
915
916
917
918
919
				continue;

			objc_unregister_class(cls);

			/*
			 * The table might have been resized, so go back to the
			 * start again.




			 */
			i = 0;
		}
	}

	assert(classes_cnt == 0);

	if (empty_dtable != NULL) {
		objc_sparsearray_free(empty_dtable);







>
>
>
>

|







904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
				continue;

			objc_unregister_class(cls);

			/*
			 * The table might have been resized, so go back to the
			 * start again.
			 *
			 * Due to the i++ in the for loop, we need to set it to
			 * UINT_FAST32_MAX so that it will get increased at the
			 * end of the loop and thus become 0.
			 */
			i = UINT_FAST32_MAX;
		}
	}

	assert(classes_cnt == 0);

	if (empty_dtable != NULL) {
		objc_sparsearray_free(empty_dtable);

Modified src/runtime/hashtable.m from [f1cf7ae4d1] to [bfc4832e86].

83
84
85
86
87
88
89
90
91
92
93
94
95
96
97



98
99
100
101
102
103
104
105
106
107
	if (count > UINT32_MAX / sizeof(*table->data) || count > UINT32_MAX / 8)
		OBJC_ERROR("Integer overflow!");

	fullness = count * 8 / table->size;

	if (fullness >= 6) {
		if (table->size > UINT32_MAX / 2)
			nsize = table->size;

		nsize = table->size * 2;
	} else if (fullness <= 1)
		nsize = table->size / 2;
	else
		return;




	if ((ndata = calloc(nsize,
	    sizeof(struct objc_hashtable_bucket*))) == NULL)
		OBJC_ERROR("Not enough memory to insert into hash table!");

	for (i = 0; i < table->size; i++) {
		if (table->data[i] != NULL &&
		    table->data[i] != &objc_deleted_bucket) {
			uint32_t j, last;

			last = nsize;







|







>
>
>
|
<
|







83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101

102
103
104
105
106
107
108
109
	if (count > UINT32_MAX / sizeof(*table->data) || count > UINT32_MAX / 8)
		OBJC_ERROR("Integer overflow!");

	fullness = count * 8 / table->size;

	if (fullness >= 6) {
		if (table->size > UINT32_MAX / 2)
			return;

		nsize = table->size * 2;
	} else if (fullness <= 1)
		nsize = table->size / 2;
	else
		return;

	if (count < table->count && nsize < 16)
		return;

	if ((ndata = calloc(nsize, sizeof(sizeof(*ndata)))) == NULL)

		OBJC_ERROR("Not enough memory to resize hash table!");

	for (i = 0; i < table->size; i++) {
		if (table->data[i] != NULL &&
		    table->data[i] != &objc_deleted_bucket) {
			uint32_t j, last;

			last = nsize;
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
		for (i = 0; i < last && table->data[i] != NULL &&
		    table->data[i] != &objc_deleted_bucket; i++);
	}

	if (i >= last)
		OBJC_ERROR("No free bucket!");

	if ((bucket = malloc(sizeof(struct objc_hashtable_bucket))) == NULL)
		OBJC_ERROR("Not enough memory to allocate hash table bucket!");

	bucket->key = key;
	bucket->hash = hash;
	bucket->obj = obj;

	table->data[i] = bucket;







|







188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
		for (i = 0; i < last && table->data[i] != NULL &&
		    table->data[i] != &objc_deleted_bucket; i++);
	}

	if (i >= last)
		OBJC_ERROR("No free bucket!");

	if ((bucket = malloc(sizeof(*bucket))) == NULL)
		OBJC_ERROR("Not enough memory to allocate hash table bucket!");

	bucket->key = key;
	bucket->hash = hash;
	bucket->obj = obj;

	table->data[i] = bucket;