ObjFW  Check-in [973574d1bd]

Overview
Comment:OFAllocObject: Fix calculation of extra alignment

While at it, also migrate to using OFRoundUpToPowerOf2, which is much
more readable.

Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | 1.0
Files: files | file ages | folders
SHA3-256: 973574d1bdea2568fb3cbf6fc91c84012adbe571ef9ea4661af2ed2c3fffe984
User & Date: js on 2023-11-04 14:44:44
Other Links: branch diff | manifest | tags
Context
2023-11-05
11:09
Update ChangeLog for 1.0.5 check-in: ce07cdc1b1 user: js tags: 1.0
2023-11-04
14:44
OFAllocObject: Fix calculation of extra alignment check-in: 973574d1bd user: js tags: 1.0
14:43
OFAllocObject: Fix calculation of extra alignment check-in: 648d29a33e user: js tags: trunk
2023-10-28
20:38
README.md: Fix typo check-in: 5bf1d19ec2 user: js tags: 1.0
Changes

Modified src/OFObject.m from [663f9433ab] to [399d8957d0].

332
333
334
335
336
337
338
339
340

341
342
343
344
345
346
347
{
	OFObject *instance;
	size_t instanceSize;

	instanceSize = class_getInstanceSize(class);

	if OF_UNLIKELY (extraAlignment > 1)
		extraAlignment = ((instanceSize + extraAlignment - 1) &
		    ~(extraAlignment - 1)) - extraAlignment;


	instance = calloc(1, PRE_IVARS_ALIGN + instanceSize +
	    extraAlignment + extraSize);

	if OF_UNLIKELY (instance == nil) {
		object_setClass((id)&allocFailedException,
		    [OFAllocFailedException class]);







|
|
>







332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
{
	OFObject *instance;
	size_t instanceSize;

	instanceSize = class_getInstanceSize(class);

	if OF_UNLIKELY (extraAlignment > 1)
		extraAlignment = OFRoundUpToPowerOf2(extraAlignment,
		    PRE_IVARS_ALIGN + instanceSize) -
		    PRE_IVARS_ALIGN - instanceSize;

	instance = calloc(1, PRE_IVARS_ALIGN + instanceSize +
	    extraAlignment + extraSize);

	if OF_UNLIKELY (instance == nil) {
		object_setClass((id)&allocFailedException,
		    [OFAllocFailedException class]);