ObjFW  Check-in [1dcfbcb479]

Overview
Comment:Work around some annoying compiler bugs.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 1dcfbcb4792a8a2385f7b0c85a7916895bb75f4dd69123bc69f8868afb409baa
User & Date: js on 2011-02-02 17:38:29
Other Links: manifest | tags
Context
2011-02-02
22:26
Increase blocks compatibility by replacing NSAutoreleasePool. check-in: 3d0a1604ae user: js tags: trunk
17:38
Work around some annoying compiler bugs. check-in: 1dcfbcb479 user: js tags: trunk
2011-02-01
22:54
Fix missing default value for variable in objfw-compile. check-in: 9485e90f58 user: js tags: trunk
Changes

Modified src/OFArray.m from [c2a9160a23] to [7a4da4f986].

406
407
408
409
410
411
412

413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428


429
430
431
432

433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449


450
451
452
453
454
455
456

	for (i = 0; i < count && !stop; i++)
		block(objs[i], i, &stop);
}

- (OFArray*)mappedArrayUsingBlock: (of_array_map_block_t)block
{

	size_t count = [array count];
	id *tmp = [self allocMemoryForNItems: count
				    withSize: sizeof(id)];

	@try {
		id *objs = [array cArray];
		size_t i;

		for (i = 0; i < count; i++)
			tmp[i] = block(objs[i], i);

		return [OFArray arrayWithCArray: tmp
					 length: count];
	} @finally {
		[self freeMemory: tmp];
	}


}

- (OFArray*)filteredArrayUsingBlock: (of_array_filter_block_t)block
{

	size_t count = [array count];
	id *tmp = [self allocMemoryForNItems: count
				    withSize: sizeof(id)];

	@try {
		id *objs = [array cArray];
		size_t i, j = 0;

		for (i = 0; i < count; i++)
			if (block(objs[i], i))
				tmp[j++] = objs[i];

		return [OFArray arrayWithCArray: tmp
					 length: j];
	} @finally {
		[self freeMemory: tmp];
	}


}
#endif

- (void)dealloc
{
	id *objs = [array cArray];
	size_t i, count = [array count];







>











|
|



>
>




>












|
|



>
>







406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462

	for (i = 0; i < count && !stop; i++)
		block(objs[i], i, &stop);
}

- (OFArray*)mappedArrayUsingBlock: (of_array_map_block_t)block
{
	OFArray *ret;
	size_t count = [array count];
	id *tmp = [self allocMemoryForNItems: count
				    withSize: sizeof(id)];

	@try {
		id *objs = [array cArray];
		size_t i;

		for (i = 0; i < count; i++)
			tmp[i] = block(objs[i], i);

		ret = [OFArray arrayWithCArray: tmp
					length: count];
	} @finally {
		[self freeMemory: tmp];
	}

	return ret;
}

- (OFArray*)filteredArrayUsingBlock: (of_array_filter_block_t)block
{
	OFArray *ret;
	size_t count = [array count];
	id *tmp = [self allocMemoryForNItems: count
				    withSize: sizeof(id)];

	@try {
		id *objs = [array cArray];
		size_t i, j = 0;

		for (i = 0; i < count; i++)
			if (block(objs[i], i))
				tmp[j++] = objs[i];

		ret = [OFArray arrayWithCArray: tmp
					length: j];
	} @finally {
		[self freeMemory: tmp];
	}

	return ret;
}
#endif

- (void)dealloc
{
	id *objs = [array cArray];
	size_t i, count = [array count];

Modified src/OFDate.m from [d1491b40fa] to [08b8759c25].

341
342
343
344
345
346
347

348
349
350
351
352
353
354
- (uint16_t)localDayOfYear
{
	LOCALTIME_RET(tm_yday + 1)
}

- (OFString*)dateStringWithFormat: (OFString*)fmt
{

	time_t sec_ = sec;
	struct tm tm;
	char *buf;

	if (sec != sec_)
		@throw [OFOutOfRangeException newWithClass: isa];








>







341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
- (uint16_t)localDayOfYear
{
	LOCALTIME_RET(tm_yday + 1)
}

- (OFString*)dateStringWithFormat: (OFString*)fmt
{
	OFString *ret;
	time_t sec_ = sec;
	struct tm tm;
	char *buf;

	if (sec != sec_)
		@throw [OFOutOfRangeException newWithClass: isa];

376
377
378
379
380
381
382
383
384
385
386


387
388
389
390

391
392
393
394
395
396
397

	buf = [self allocMemoryWithSize: of_pagesize];

	@try {
		if (!strftime(buf, of_pagesize, [fmt cString], &tm))
			@throw [OFOutOfRangeException newWithClass: isa];

		return [OFString stringWithCString: buf];
	} @finally {
		[self freeMemory: buf];
	}


}

- (OFString*)localDateStringWithFormat: (OFString*)fmt
{

	time_t sec_ = sec;
	struct tm tm;
	char *buf;

	if (sec != sec_)
		@throw [OFOutOfRangeException newWithClass: isa];








|



>
>




>







377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401

	buf = [self allocMemoryWithSize: of_pagesize];

	@try {
		if (!strftime(buf, of_pagesize, [fmt cString], &tm))
			@throw [OFOutOfRangeException newWithClass: isa];

		ret = [OFString stringWithCString: buf];
	} @finally {
		[self freeMemory: buf];
	}

	return ret;
}

- (OFString*)localDateStringWithFormat: (OFString*)fmt
{
	OFString *ret;
	time_t sec_ = sec;
	struct tm tm;
	char *buf;

	if (sec != sec_)
		@throw [OFOutOfRangeException newWithClass: isa];

419
420
421
422
423
424
425
426
427
428
429


430
431
432
433
434
435
436

	buf = [self allocMemoryWithSize: of_pagesize];

	@try {
		if (!strftime(buf, of_pagesize, [fmt cString], &tm))
			@throw [OFOutOfRangeException newWithClass: isa];

		return [OFString stringWithCString: buf];
	} @finally {
		[self freeMemory: buf];
	}


}

- (OFDate*)earlierDate: (OFDate*)date
{
	if ([self compare: date] == OF_ORDERED_DESCENDING)
		return [[date retain] autorelease];








|



>
>







423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442

	buf = [self allocMemoryWithSize: of_pagesize];

	@try {
		if (!strftime(buf, of_pagesize, [fmt cString], &tm))
			@throw [OFOutOfRangeException newWithClass: isa];

		ret = [OFString stringWithCString: buf];
	} @finally {
		[self freeMemory: buf];
	}

	return ret;
}

- (OFDate*)earlierDate: (OFDate*)date
{
	if ([self compare: date] == OF_ORDERED_DESCENDING)
		return [[date retain] autorelease];

Modified src/OFStream.m from [77f3cb0a9b] to [5a1ab363d9].

640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660


661
662
663
664
665
666
667
{
	return [self writeNBytes: [str cStringLength]
		      fromBuffer: [str cString]];
}

- (size_t)writeLine: (OFString*)str
{
	size_t len = [str cStringLength];
	char *buf;

	buf = [self allocMemoryWithSize: len + 1];

	@try {
		memcpy(buf, [str cString], len);
		buf[len] = '\n';

		return [self writeNBytes: len + 1
			      fromBuffer: buf];
	} @finally {
		[self freeMemory: buf];
	}


}

- (size_t)writeFormat: (OFString*)fmt, ...
{
	va_list args;
	size_t ret;








|








|
|



>
>







640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
{
	return [self writeNBytes: [str cStringLength]
		      fromBuffer: [str cString]];
}

- (size_t)writeLine: (OFString*)str
{
	size_t ret, len = [str cStringLength];
	char *buf;

	buf = [self allocMemoryWithSize: len + 1];

	@try {
		memcpy(buf, [str cString], len);
		buf[len] = '\n';

		ret = [self writeNBytes: len + 1
			     fromBuffer: buf];
	} @finally {
		[self freeMemory: buf];
	}

	return ret;
}

- (size_t)writeFormat: (OFString*)fmt, ...
{
	va_list args;
	size_t ret;

Modified src/of_asprintf.m from [6358474411] to [75df7de9af].

299
300
301
302
303
304
305
306



307
308
309
310
311
312
313
			    va_arg(ctx->args, ptrdiff_t));
			break;
		default:
			return false;
		}

		break;
	case 'o': case 'u': case 'x': case 'X':



		switch (ctx->len_mod) {
		case LENGTH_MODIFIER_NONE:
		case LENGTH_MODIFIER_HH:
		case LENGTH_MODIFIER_H:
			tmp_len = asprintf(&tmp, ctx->subfmt,
			    va_arg(ctx->args, unsigned int));
			break;







|
>
>
>







299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
			    va_arg(ctx->args, ptrdiff_t));
			break;
		default:
			return false;
		}

		break;
	case 'o':
	case 'u':
	case 'x':
	case 'X':
		switch (ctx->len_mod) {
		case LENGTH_MODIFIER_NONE:
		case LENGTH_MODIFIER_HH:
		case LENGTH_MODIFIER_H:
			tmp_len = asprintf(&tmp, ctx->subfmt,
			    va_arg(ctx->args, unsigned int));
			break;