204
198
char c = type_map[(t2 & _GSC_MASK)];
205
if ((c == _C_INT || c == _C_LNG
209
) && (t1 == _C_INT || t1 == _C_LNG
214
if ((c == _C_UINT || c == _C_ULNG
218
) && (t1 == _C_UINT || t1 == _C_ULNG
204
case _C_SHT: s1 = _GSC_S_SHT; break;
205
case _C_USHT: s1 = _GSC_S_SHT; break;
206
case _C_INT: s1 = _GSC_S_INT; break;
207
case _C_UINT: s1 = _GSC_S_INT; break;
208
case _C_LNG: s1 = _GSC_S_LNG; break;
209
case _C_ULNG: s1 = _GSC_S_LNG; break;
210
case _C_LNG_LNG: s1 = _GSC_S_LNG_LNG; break;
211
case _C_ULNG_LNG: s1 = _GSC_S_LNG_LNG; break;
217
case _C_SHT: s2 = _GSC_S_SHT; break;
218
case _C_USHT: s2 = _GSC_S_SHT; break;
219
case _C_INT: s2 = _GSC_S_INT; break;
220
case _C_UINT: s2 = _GSC_S_INT; break;
221
case _C_LNG: s2 = _GSC_S_LNG; break;
222
case _C_ULNG: s2 = _GSC_S_LNG; break;
223
case _C_LNG_LNG: s2 = _GSC_S_LNG_LNG; break;
224
case _C_ULNG_LNG: s2 = _GSC_S_LNG_LNG; break;
228
if ((c == _C_INT || c == _C_LNG || c == _C_LNG_LNG)
229
&& (t1 == _C_INT || t1 == _C_LNG || t1 == _C_LNG_LNG))
230
return s1 == s2 ? YES : NO;
232
if ((c == _C_UINT || c == _C_ULNG || c == _C_ULNG_LNG)
233
&& (t1 == _C_UINT || t1 == _C_ULNG || t1 == _C_ULNG_LNG))
234
return s1 == s2 ? YES : NO;
236
/* HACK also allow float and double to be used interchangably as MacOS-X
237
* intorduced CGFloat, which may be aither a float or a double.
239
if ((c == _C_FLT || c == _C_DBL) && (t1 == _C_FLT || t1 == _C_DBL))
224
242
[NSException raise: NSInternalInconsistencyException
225
243
format: @"expected %s and got %s",
226
244
typeToName1(t1), typeToName2(t2)];
230
249
#define PREFIX "GNUstep archive"
972
typeCheck(*type, info & _GSC_MASK);
973
if ((info & _GSC_SIZE) == _GSC_S_LNG)
979
if (YES == typeCheck(*type, info & _GSC_MASK)
980
&& (info & _GSC_SIZE) == _GSC_S_LNG)
975
982
(*desImp)(src, desSel, address, type, &cursor, nil);
981
987
case _GSC_LNG_LNG:
982
988
case _GSC_ULNG_LNG:
983
typeCheck(*type, info & _GSC_MASK);
984
if ((info & _GSC_SIZE) == _GSC_S_LNG_LNG)
989
if (YES == typeCheck(*type, info & _GSC_MASK)
990
&& (info & _GSC_SIZE) == _GSC_S_LNG_LNG)
986
992
(*desImp)(src, desSel, address, type, &cursor, nil);
993
typeCheck(*type, _GSC_FLT);
994
(*desImp)(src, desSel, address, type, &cursor, nil);
998
if (YES == typeCheck(*type, _GSC_FLT)
1001
(*desImp)(src, desSel, address, type, &cursor, nil);
1007
/* We found a float when expecting a double ... handle it.
1009
(*desImp)(src, desSel, &val, @encode(float), &cursor, nil);
1010
*(double*)address = (double)val;
998
typeCheck(*type, _GSC_DBL);
999
(*desImp)(src, desSel, address, type, &cursor, nil);
1015
if (YES == typeCheck(*type, _GSC_DBL)
1018
(*desImp)(src, desSel, address, type, &cursor, nil);
1024
/* We found a double when expecting a float ... handle it.
1026
(*desImp)(src, desSel, &val, @encode(double), &cursor, nil);
1027
*(float*)address = (float)val;
1004
1033
format: @"read unknown type info - %d", info];
1008
1040
* We fall through to here only when we have to decode a value
1009
1041
* whose natural size on this system is not the same as on the
1010
1042
* machine on which the archive was created.
1048
case _C_USHT: size = sizeof(short); break;
1050
case _C_UINT: size = sizeof(int); break;
1052
case _C_ULNG: size = sizeof(long); break;
1054
case _C_ULNG_LNG: size = sizeof(long long); break;
1014
1059
* First, we read the data and convert it to the largest size
1015
1060
* this system can support.
1017
switch (info & _GSC_SIZE)
1019
case _GSC_I16: /* Encoded as 16-bit */
1023
(*desImp)(src, desSel, &val, @encode(uint16_t), &cursor, nil);
1028
case _GSC_I32: /* Encoded as 32-bit */
1032
(*desImp)(src, desSel, &val, @encode(uint32_t), &cursor, nil);
1037
case _GSC_I64: /* Encoded as 64-bit */
1041
(*desImp)(src, desSel, &val, @encode(uint64_t), &cursor, nil);
1045
bigval = GSSwapBigI64ToHost(val);
1050
default: /* A 128-bit value */
1054
(*desImp)(src, desSel, &val, @encode(gsu128), &cursor, nil);
1058
val = GSSwapBigI128ToHost(val);
1060
bigval = *(uint64_t*)&val;
1062
bigval = *(uint32_t*)&val;
1070
* Now we copy from the 'bigval' to the destination location.
1072
switch (info & _GSC_MASK)
1075
*(short*)address = (short)bigval;
1078
*(unsigned short*)address = (unsigned short)bigval;
1081
*(int*)address = (int)bigval;
1084
*(unsigned int*)address = (unsigned int)bigval;
1087
*(long*)address = (long)bigval;
1090
*(unsigned long*)address = (unsigned long)bigval;
1094
*(long long*)address = (long long)bigval;
1097
*(unsigned long long*)address = (unsigned long long)bigval;
1101
[NSException raise: NSInternalInconsistencyException
1102
format: @"type/size information error"];
1065
|| *type == _C_LNG_LNG)
1069
switch (info & _GSC_SIZE)
1071
case _GSC_I16: /* Encoded as 16-bit */
1075
(*desImp)(src, desSel, &val, @encode(int16_t), &cursor, nil);
1080
case _GSC_I32: /* Encoded as 32-bit */
1084
(*desImp)(src, desSel, &val, @encode(int32_t), &cursor, nil);
1089
case _GSC_I64: /* Encoded as 64-bit */
1091
(*desImp)(src, desSel, &big, @encode(int64_t), &cursor, nil);
1095
default: /* A 128-bit value */
1098
[NSException raise: NSInternalInconsistencyException
1099
format: @"Archiving of 128bit integer not allowed"];
1103
* Now we copy from the big value to the destination location.
1108
*(int8_t*)address = (int8_t)big;
1111
if ((int8_t)big >= 0 || (big & ~0xff) != ~0xff)
1113
NSLog(@"Loss of information converting decoded value to int8_t");
1118
*(int16_t*)address = (int16_t)big;
1121
if ((int16_t)big >= 0 || (big & ~0xffff) != ~0xffff)
1123
NSLog(@"Loss of information converting decoded value to int16_t");
1128
*(int32_t*)address = (int32_t)big;
1129
if (big & ~0xffffffff)
1131
if ((int32_t)big >= 0 || (big & ~0xffffffff) != ~0xffffffff)
1133
NSLog(@"Loss of information converting decoded value to int32_t");
1138
*(int64_t*)address = big;
1141
[NSException raise: NSInternalInconsistencyException
1142
format: @"type/size information error"];
1149
switch (info & _GSC_SIZE)
1151
case _GSC_I16: /* Encoded as 16-bit */
1155
(*desImp)(src, desSel, &val, @encode(uint16_t), &cursor, nil);
1160
case _GSC_I32: /* Encoded as 32-bit */
1164
(*desImp)(src, desSel, &val, @encode(uint32_t), &cursor, nil);
1169
case _GSC_I64: /* Encoded as 64-bit */
1171
(*desImp)(src, desSel, &big, @encode(uint64_t), &cursor, nil);
1175
default: /* A 128-bit value */
1178
[NSException raise: NSInternalInconsistencyException
1179
format: @"Archiving of 128bit integer not allowed"];
1183
* Now we copy from the big value to the destination location.
1190
NSLog(@"Loss of information converting decoded value to uint8_t");
1192
*(uint8_t*)address = (uint8_t)big;
1197
NSLog(@"Loss of information converting decoded value to uint16_t");
1199
*(uint8_t*)address = (uint8_t)big;
1200
*(uint16_t*)address = (uint16_t)big;
1203
if (big & ~0xffffffff)
1205
NSLog(@"Loss of information converting decoded value to uint32_t");
1207
*(uint32_t*)address = (uint32_t)big;
1210
*(uint64_t*)address = big;
1213
[NSException raise: NSInternalInconsistencyException
1214
format: @"type/size information error"];
1106
1220
- (NSData*) decodeDataObject