ObjFW  Diff

Differences From Artifact [335de526be]:

To Artifact [6e083ee3de]:


442
443
444
445
446
447
448
449
450


451
452
453
454
455
456
457
442
443
444
445
446
447
448


449
450
451
452
453
454
455
456
457







-
-
+
+







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

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

	@try {
		[self readIntoBuffer: tmp
			 exactLength: nItems * itemSize];

		[dataArray addItemsFromCArray: tmp
					count: nItems];
605
606
607
608
609
610
611
612

613
614
615
616
617
618
619
605
606
607
608
609
610
611

612
613
614
615
616
617
618
619







-
+







				} @catch (id e) {
					/*
					 * Append data to cache to prevent loss
					 * of data due to wrong encoding.
					 */
					cache = [self
					    resizeMemory: cache
						  toSize: cacheLength +
						    size: cacheLength +
							  bufferLength];

					if (cache != NULL)
						memcpy(cache + cacheLength,
						    buffer, bufferLength);

					cacheLength += bufferLength;
636
637
638
639
640
641
642
643

644
645
646
647

648
649
650
651
652
653
654
636
637
638
639
640
641
642

643
644
645
646

647
648
649
650
651
652
653
654







-
+



-
+







				waitingForDelimiter = NO;
				return ret;
			}
		}

		/* There was no newline or \0 */
		cache = [self resizeMemory: cache
				    toSize: cacheLength + bufferLength];
				      size: cacheLength + bufferLength];

		/*
		 * It's possible that cacheLen + len is 0 and thus cache was
		 * set to NULL by resizeMemory:toSize:.
		 * set to NULL by resizeMemory:size:.
		 */
		if (cache != NULL)
			memcpy(cache + cacheLength, buffer, bufferLength);

		cacheLength += bufferLength;
	} @finally {
		[self freeMemory: buffer];
799
800
801
802
803
804
805
806

807
808
809
810

811
812
813
814
815
816
817
799
800
801
802
803
804
805

806
807
808
809

810
811
812
813
814
815
816
817







-
+



-
+







				waitingForDelimiter = NO;
				return ret;
			}
		}

		/* Neither the delimiter nor \0 was found */
		cache = [self resizeMemory: cache
				    toSize: cacheLength + bufferLength];
				      size: cacheLength + bufferLength];

		/*
		 * It's possible that cacheLen + len is 0 and thus cache was
		 * set to NULL by resizeMemory:toSize:.
		 * set to NULL by resizeMemory:size:.
		 */
		if (cache != NULL)
			memcpy(cache + cacheLength, buffer,
			    bufferLength);

		cacheLength += bufferLength;
	} @finally {
876
877
878
879
880
881
882
883

884
885
886
887
888
889
890
876
877
878
879
880
881
882

883
884
885
886
887
888
889
890







-
+







	     length: (size_t)length
{
	if (!writeBufferEnabled)
		[self _writeBuffer: buffer
			    length: length];
	else {
		writeBuffer = [self resizeMemory: writeBuffer
					  toSize: writeBufferLength + length];
					    size: writeBufferLength + length];
		memcpy(writeBuffer + writeBufferLength, buffer, length);
		writeBufferLength += length;
	}
}

- (void)writeInt8: (uint8_t)int8
{
939
940
941
942
943
944
945
946
947


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


946
947
948
949
950
951
952
953
954







-
-
+
+








#ifdef OF_BIG_ENDIAN
	[self writeBuffer: buffer
		   length: size];
#else
	uint16_t *tmp;

	tmp = [self allocMemoryWithItemSize: sizeof(uint16_t)
				      count: nInt16s];
	tmp = [self allocMemoryWithSize: 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
969
970
971
972
973
974
975


976
977
978
979
980
981
982
983
984







-
-
+
+








#ifdef OF_BIG_ENDIAN
	[self writeBuffer: buffer
		   length: size];
#else
	uint32_t *tmp;

	tmp = [self allocMemoryWithItemSize: sizeof(uint32_t)
				      count: nInt32s];
	tmp = [self allocMemoryWithSize: 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
999
1000
1001
1002
1003
1004
1005


1006
1007
1008
1009
1010
1011
1012
1013
1014







-
-
+
+








#ifdef OF_BIG_ENDIAN
	[self writeBuffer: buffer
		   length: size];
#else
	uint64_t *tmp;

	tmp = [self allocMemoryWithItemSize: sizeof(uint64_t)
				      count: nInt64s];
	tmp = [self allocMemoryWithSize: 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
1029
1030
1031
1032
1033
1034
1035


1036
1037
1038
1039
1040
1041
1042
1043
1044







-
-
+
+








#ifdef OF_FLOAT_BIG_ENDIAN
	[self writeBuffer: buffer
		   length: size];
#else
	float *tmp;

	tmp = [self allocMemoryWithItemSize: sizeof(float)
				      count: nFloats];
	tmp = [self allocMemoryWithSize: 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
1059
1060
1061
1062
1063
1064
1065


1066
1067
1068
1069
1070
1071
1072
1073
1074







-
-
+
+








#ifdef OF_FLOAT_BIG_ENDIAN
	[self writeBuffer: buffer
		   length: size];
#else
	double *tmp;

	tmp = [self allocMemoryWithItemSize: sizeof(double)
				      count: nDoubles];
	tmp = [self allocMemoryWithSize: 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
1129
1130
1131
1132
1133
1134
1135


1136
1137
1138
1139
1140
1141
1142
1143
1144







-
-
+
+








#ifndef OF_BIG_ENDIAN
	[self writeBuffer: buffer
		   length: size];
#else
	uint16_t *tmp;

	tmp = [self allocMemoryWithItemSize: sizeof(uint16_t)
				      count: nInt16s];
	tmp = [self allocMemoryWithSize: 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
1159
1160
1161
1162
1163
1164
1165


1166
1167
1168
1169
1170
1171
1172
1173
1174







-
-
+
+








#ifndef OF_BIG_ENDIAN
	[self writeBuffer: buffer
		   length: size];
#else
	uint32_t *tmp;

	tmp = [self allocMemoryWithItemSize: sizeof(uint32_t)
				      count: nInt32s];
	tmp = [self allocMemoryWithSize: 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
1189
1190
1191
1192
1193
1194
1195


1196
1197
1198
1199
1200
1201
1202
1203
1204







-
-
+
+








#ifndef OF_BIG_ENDIAN
	[self writeBuffer: buffer
		   length: size];
#else
	uint64_t *tmp;

	tmp = [self allocMemoryWithItemSize: sizeof(uint64_t)
				      count: nInt64s];
	tmp = [self allocMemoryWithSize: 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
1219
1220
1221
1222
1223
1224
1225


1226
1227
1228
1229
1230
1231
1232
1233
1234







-
-
+
+








#ifndef OF_FLOAT_BIG_ENDIAN
	[self writeBuffer: buffer
		   length: size];
#else
	float *tmp;

	tmp = [self allocMemoryWithItemSize: sizeof(float)
				      count: nFloats];
	tmp = [self allocMemoryWithSize: 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
1249
1250
1251
1252
1253
1254
1255


1256
1257
1258
1259
1260
1261
1262
1263
1264







-
-
+
+








#ifndef OF_FLOAT_BIG_ENDIAN
	[self writeBuffer: buffer
		   length: size];
#else
	double *tmp;

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

	@try {
		size_t i;

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