ObjFW  Diff

Differences From Artifact [79c2ad057e]:

To Artifact [a84cb06e69]:


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
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480

481
482
483
484
485
486
487
	return [self readDataArrayWithItemSize: 1
				     andNItems: nItems];
}

- (OFDataArray*)readDataArrayWithItemSize: (size_t)itemSize
				andNItems: (size_t)nItems
{
	OFDataArray *da;
	char *tmp;

	da = [OFDataArray dataArrayWithItemSize: itemSize];
	tmp = [self allocMemoryForNItems: nItems
				  ofSize: itemSize];

	@try {
		[self readExactlyNBytes: nItems * itemSize
			     intoBuffer: tmp];

		[da addNItems: nItems
		   fromCArray: tmp];

	} @finally {
		[self freeMemory: tmp];
	}

	return da;
}

- (OFDataArray*)readDataArrayTillEndOfStream
{
	OFDataArray *dataArray;
	char *buffer;

	dataArray = [OFDataArray dataArray];
	buffer = [self allocMemoryWithSize: of_pagesize];

	@try {
		while (![self isAtEndOfStream]) {
			size_t length;

			length = [self readNBytes: of_pagesize
				       intoBuffer: buffer];
			[dataArray addNItems: length
				  fromCArray: buffer];

		}
	} @finally {
		[self freeMemory: buffer];
	}

	return dataArray;
}







|


|
|
|





<
|
>




|
















<
|
>







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
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478

479
480
481
482
483
484
485
486
487
	return [self readDataArrayWithItemSize: 1
				     andNItems: nItems];
}

- (OFDataArray*)readDataArrayWithItemSize: (size_t)itemSize
				andNItems: (size_t)nItems
{
	OFDataArray *dataArray;
	char *tmp;

	dataArray = [OFDataArray dataArrayWithItemSize: itemSize];
	tmp = [self allocMemoryWithItemSize: itemSize
				      count: nItems];

	@try {
		[self readExactlyNBytes: nItems * itemSize
			     intoBuffer: tmp];


		[dataArray addItemsFromCArray: tmp
					count: nItems];
	} @finally {
		[self freeMemory: tmp];
	}

	return dataArray;
}

- (OFDataArray*)readDataArrayTillEndOfStream
{
	OFDataArray *dataArray;
	char *buffer;

	dataArray = [OFDataArray dataArray];
	buffer = [self allocMemoryWithSize: of_pagesize];

	@try {
		while (![self isAtEndOfStream]) {
			size_t length;

			length = [self readNBytes: of_pagesize
				       intoBuffer: buffer];

			[dataArray addItemsFromCArray: buffer
						count: length];
		}
	} @finally {
		[self freeMemory: buffer];
	}

	return dataArray;
}
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954

#ifdef OF_BIG_ENDIAN
	[self writeNBytes: size
	       fromBuffer: buffer];
#else
	uint16_t *tmp;

	tmp = [self allocMemoryForNItems: nInt16s
				  ofSize: sizeof(uint16_t)];

	@try {
		size_t i;

		for (i = 0; i < nInt16s; i++)
			tmp[i] = of_bswap16(buffer[i]);








|
|







939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954

#ifdef OF_BIG_ENDIAN
	[self writeNBytes: size
	       fromBuffer: buffer];
#else
	uint16_t *tmp;

	tmp = [self allocMemoryWithItemSize: sizeof(uint16_t)
				      count: nInt16s];

	@try {
		size_t i;

		for (i = 0; i < nInt16s; i++)
			tmp[i] = of_bswap16(buffer[i]);

969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984

#ifdef OF_BIG_ENDIAN
	[self writeNBytes: size
	       fromBuffer: buffer];
#else
	uint32_t *tmp;

	tmp = [self allocMemoryForNItems: nInt32s
				  ofSize: sizeof(uint32_t)];

	@try {
		size_t i;

		for (i = 0; i < nInt32s; i++)
			tmp[i] = of_bswap32(buffer[i]);








|
|







969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984

#ifdef OF_BIG_ENDIAN
	[self writeNBytes: size
	       fromBuffer: buffer];
#else
	uint32_t *tmp;

	tmp = [self allocMemoryWithItemSize: sizeof(uint32_t)
				      count: nInt32s];

	@try {
		size_t i;

		for (i = 0; i < nInt32s; i++)
			tmp[i] = of_bswap32(buffer[i]);

999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014

#ifdef OF_BIG_ENDIAN
	[self writeNBytes: size
	       fromBuffer: buffer];
#else
	uint64_t *tmp;

	tmp = [self allocMemoryForNItems: nInt64s
				  ofSize: sizeof(uint64_t)];

	@try {
		size_t i;

		for (i = 0; i < nInt64s; i++)
			tmp[i] = of_bswap64(buffer[i]);








|
|







999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014

#ifdef OF_BIG_ENDIAN
	[self writeNBytes: size
	       fromBuffer: buffer];
#else
	uint64_t *tmp;

	tmp = [self allocMemoryWithItemSize: sizeof(uint64_t)
				      count: nInt64s];

	@try {
		size_t i;

		for (i = 0; i < nInt64s; i++)
			tmp[i] = of_bswap64(buffer[i]);

1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044

#ifdef OF_FLOAT_BIG_ENDIAN
	[self writeNBytes: size
	       fromBuffer: buffer];
#else
	float *tmp;

	tmp = [self allocMemoryForNItems: nFloats
				  ofSize: sizeof(float)];

	@try {
		size_t i;

		for (i = 0; i < nFloats; i++)
			tmp[i] = of_bswap_float(buffer[i]);








|
|







1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044

#ifdef OF_FLOAT_BIG_ENDIAN
	[self writeNBytes: size
	       fromBuffer: buffer];
#else
	float *tmp;

	tmp = [self allocMemoryWithItemSize: sizeof(float)
				      count: nFloats];

	@try {
		size_t i;

		for (i = 0; i < nFloats; i++)
			tmp[i] = of_bswap_float(buffer[i]);

1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074

#ifdef OF_FLOAT_BIG_ENDIAN
	[self writeNBytes: size
	       fromBuffer: buffer];
#else
	double *tmp;

	tmp = [self allocMemoryForNItems: nDoubles
				  ofSize: sizeof(double)];

	@try {
		size_t i;

		for (i = 0; i < nDoubles; i++)
			tmp[i] = of_bswap_double(buffer[i]);








|
|







1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074

#ifdef OF_FLOAT_BIG_ENDIAN
	[self writeNBytes: size
	       fromBuffer: buffer];
#else
	double *tmp;

	tmp = [self allocMemoryWithItemSize: sizeof(double)
				      count: nDoubles];

	@try {
		size_t i;

		for (i = 0; i < nDoubles; i++)
			tmp[i] = of_bswap_double(buffer[i]);

1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144

#ifndef OF_BIG_ENDIAN
	[self writeNBytes: size
	       fromBuffer: buffer];
#else
	uint16_t *tmp;

	tmp = [self allocMemoryForNItems: nInt16s
				  ofSize: sizeof(uint16_t)];

	@try {
		size_t i;

		for (i = 0; i < nInt16s; i++)
			tmp[i] = of_bswap16(buffer[i]);








|
|







1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144

#ifndef OF_BIG_ENDIAN
	[self writeNBytes: size
	       fromBuffer: buffer];
#else
	uint16_t *tmp;

	tmp = [self allocMemoryWithItemSize: sizeof(uint16_t)
				      count: nInt16s];

	@try {
		size_t i;

		for (i = 0; i < nInt16s; i++)
			tmp[i] = of_bswap16(buffer[i]);

1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174

#ifndef OF_BIG_ENDIAN
	[self writeNBytes: size
	       fromBuffer: buffer];
#else
	uint32_t *tmp;

	tmp = [self allocMemoryForNItems: nInt32s
				  ofSize: sizeof(uint32_t)];

	@try {
		size_t i;

		for (i = 0; i < nInt32s; i++)
			tmp[i] = of_bswap32(buffer[i]);








|
|







1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174

#ifndef OF_BIG_ENDIAN
	[self writeNBytes: size
	       fromBuffer: buffer];
#else
	uint32_t *tmp;

	tmp = [self allocMemoryWithItemSize: sizeof(uint32_t)
				      count: nInt32s];

	@try {
		size_t i;

		for (i = 0; i < nInt32s; i++)
			tmp[i] = of_bswap32(buffer[i]);

1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204

#ifndef OF_BIG_ENDIAN
	[self writeNBytes: size
	       fromBuffer: buffer];
#else
	uint64_t *tmp;

	tmp = [self allocMemoryForNItems: nInt64s
				  ofSize: sizeof(uint64_t)];

	@try {
		size_t i;

		for (i = 0; i < nInt64s; i++)
			tmp[i] = of_bswap64(buffer[i]);








|
|







1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204

#ifndef OF_BIG_ENDIAN
	[self writeNBytes: size
	       fromBuffer: buffer];
#else
	uint64_t *tmp;

	tmp = [self allocMemoryWithItemSize: sizeof(uint64_t)
				      count: nInt64s];

	@try {
		size_t i;

		for (i = 0; i < nInt64s; i++)
			tmp[i] = of_bswap64(buffer[i]);

1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234

#ifndef OF_FLOAT_BIG_ENDIAN
	[self writeNBytes: size
	       fromBuffer: buffer];
#else
	float *tmp;

	tmp = [self allocMemoryForNItems: nFloats
				  ofSize: sizeof(float)];

	@try {
		size_t i;

		for (i = 0; i < nFloats; i++)
			tmp[i] = of_bswap_float(buffer[i]);








|
|







1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234

#ifndef OF_FLOAT_BIG_ENDIAN
	[self writeNBytes: size
	       fromBuffer: buffer];
#else
	float *tmp;

	tmp = [self allocMemoryWithItemSize: sizeof(float)
				      count: nFloats];

	@try {
		size_t i;

		for (i = 0; i < nFloats; i++)
			tmp[i] = of_bswap_float(buffer[i]);

1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264

#ifndef OF_FLOAT_BIG_ENDIAN
	[self writeNBytes: size
	       fromBuffer: buffer];
#else
	double *tmp;

	tmp = [self allocMemoryForNItems: nDoubles
				  ofSize: sizeof(double)];

	@try {
		size_t i;

		for (i = 0; i < nDoubles; i++)
			tmp[i] = of_bswap_double(buffer[i]);








|
|







1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264

#ifndef OF_FLOAT_BIG_ENDIAN
	[self writeNBytes: size
	       fromBuffer: buffer];
#else
	double *tmp;

	tmp = [self allocMemoryWithItemSize: sizeof(double)
				      count: nDoubles];

	@try {
		size_t i;

		for (i = 0; i < nDoubles; i++)
			tmp[i] = of_bswap_double(buffer[i]);