ObjFW  Check-in [b52c4a41e4]

Overview
Comment:Make struct size a multiple of the alignment
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: b52c4a41e4c688ced06a5629af8e83396c87273826e06b6dce7277fec65dbfaf
User & Date: js on 2017-10-22 20:58:20
Other Links: manifest | tags
Context
2017-10-23
20:43
runtime: Make Apple GCC with -Wshadow happy check-in: 31155755cc user: js tags: trunk
2017-10-22
20:58
Make struct size a multiple of the alignment check-in: b52c4a41e4 user: js tags: trunk
18:31
OFMethodSignature: Correctly handle Darwin/PPC ABI check-in: f641fc7faa user: js tags: trunk
Changes

Modified src/OFMethodSignature.m from [70534fd085] to [1e877ea8dd].

297
298
299
300
301
302
303
304
305
306
307
308
309
310
311



312


313
314
315
316
317
318
319
297
298
299
300
301
302
303








304
305
306

307
308
309
310
311
312
313
314
315







-
-
-
-
-
-
-
-
+
+
+
-
+
+







	return count * size;
}

size_t
sizeofStruct(const char **type, size_t *length)
{
	size_t size = 0;
#if defined(OF_POWERPC) && defined(OF_MACOS)
	bool first = true;
	size_t alignment;

	{
		const char *typeCopy = *type;
		size_t lengthCopy = *length;
		alignment = alignofStruct(&typeCopy, &lengthCopy);
	const char *typeCopy = *type;
	size_t lengthCopy = *length;
	size_t alignment = alignofStruct(&typeCopy, &lengthCopy);
	}
#if defined(OF_POWERPC) && defined(OF_MACOS)
	bool first = true;
#endif

	assert(*length > 0);

	(*type)++;
	(*length)--;

327
328
329
330
331
332
333


334
335
336
337




338
339
340
341
342
343
344
323
324
325
326
327
328
329
330
331




332
333
334
335
336
337
338
339
340
341
342







+
+
-
-
-
-
+
+
+
+







		@throw [OFInvalidFormatException exception];

	/* Skip '=' */
	(*type)++;
	(*length)--;

	while (*length > 0 && **type != '}') {
		size_t fieldSize, fieldAlign;

		const char *typeCopy = *type;
		size_t lengthCopy = *length;
		size_t fieldSize = sizeofEncoding(type, length);
		size_t fieldAlign = alignofEncoding(&typeCopy, &lengthCopy);
		typeCopy = *type;
		lengthCopy = *length;
		fieldSize = sizeofEncoding(type, length);
		fieldAlign = alignofEncoding(&typeCopy, &lengthCopy);

#if defined(OF_POWERPC) && defined(OF_MACOS)
		if (!first && fieldAlign > 4)
			fieldAlign = 4;

		first = false;
#endif
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
358
359
360
361
362
363
364

365
366
367
368
369
370
371
372

373
374
375
376
377
378
379







-








-








	if (*length == 0 || **type != '}')
		@throw [OFInvalidFormatException exception];

	(*type)++;
	(*length)--;

#if defined(OF_POWERPC) && defined(OF_MACOS)
	if (size % alignment != 0) {
		size_t padding = alignment - (size % alignment);

		if (SIZE_MAX - size < padding)
			@throw [OFOutOfRangeException exception];

		size += padding;
	}
#endif

	return size;
}

size_t
sizeofUnion(const char **type, size_t *length)
{