Changeset 1391 for branches/GNU/src/gcc/libobjc/archive.c
- Timestamp:
- Apr 27, 2004, 8:39:34 PM (21 years ago)
- Location:
- branches/GNU/src/gcc
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/GNU/src/gcc
- Property svn:ignore
-
old new 26 26 configure.vr 27 27 configure.vrs 28 dir.info 28 29 Makefile 29 dir.info30 30 lost+found 31 31 update.out
-
- Property svn:ignore
-
branches/GNU/src/gcc/libobjc/archive.c
-
Property cvs2svn:cvs-rev
changed from
1.1
to1.1.1.2
r1390 r1391 1 /* GNU Objective C Runtime archiving2 Copyright (C) 1993, 1995, 1996, 1997 Free Software Foundation, Inc.1 /* GNU Objective C Runtime archiving 2 Copyright (C) 1993, 1995, 1996, 1997, 2002 Free Software Foundation, Inc. 3 3 Contributed by Kresten Krab Thorup 4 4 … … 29 29 #include "typedstream.h" 30 30 #include "encoding.h" 31 32 #ifdef HAVE_STDLIB_H33 31 #include <stdlib.h> 34 #endif 35 36 extern int fflush(FILE*); 32 33 extern int fflush (FILE *); 37 34 38 35 #define ROUND(V, A) \ 39 ({ typeof (V) __v=(V); typeof(A) __a=(A); \40 __a *((__v+__a-1)/__a); })41 42 #define PTR2LONG(P) (((char *)(P))-(char*)0)43 #define LONG2PTR(L) (((char *)0)+(L))36 ({ typeof (V) __v = (V); typeof (A) __a = (A); \ 37 __a * ((__v + __a - 1)/__a); }) 38 39 #define PTR2LONG(P) (((char *) (P))-(char *) 0) 40 #define LONG2PTR(L) (((char *) 0) + (L)) 44 41 45 42 /* Declare some functions... */ 46 43 47 44 static int 48 objc_read_class (struct objc_typed_stream * stream, Class*class);49 50 int objc_sizeof_type (const char*type);45 objc_read_class (struct objc_typed_stream *stream, Class *class); 46 47 int objc_sizeof_type (const char *type); 51 48 52 49 static int 53 objc_write_use_common (struct objc_typed_stream *stream, unsigned long key);50 objc_write_use_common (struct objc_typed_stream *stream, unsigned long key); 54 51 55 52 static int 56 objc_write_register_common (struct objc_typed_stream *stream,53 objc_write_register_common (struct objc_typed_stream *stream, 57 54 unsigned long key); 58 55 59 56 static int 60 objc_write_class (struct objc_typed_stream *stream,61 struct objc_class *class);62 63 const char * objc_skip_type (const char*type);64 65 static void __objc_finish_write_root_object (struct objc_typed_stream*);66 static void __objc_finish_read_root_object (struct objc_typed_stream*);57 objc_write_class (struct objc_typed_stream *stream, 58 struct objc_class *class); 59 60 const char *objc_skip_type (const char *type); 61 62 static void __objc_finish_write_root_object (struct objc_typed_stream *); 63 static void __objc_finish_read_root_object (struct objc_typed_stream *); 67 64 68 65 static __inline__ int 69 __objc_code_unsigned_char (unsigned char *buf, unsigned char val)66 __objc_code_unsigned_char (unsigned char *buf, unsigned char val) 70 67 { 71 68 if ((val&_B_VALUE) == val) … … 83 80 84 81 int 85 objc_write_unsigned_char (struct objc_typed_stream *stream,82 objc_write_unsigned_char (struct objc_typed_stream *stream, 86 83 unsigned char value) 87 84 { 88 unsigned char buf[sizeof (unsigned char) +1];85 unsigned char buf[sizeof (unsigned char) + 1]; 89 86 int len = __objc_code_unsigned_char (buf, value); 90 return (*stream->write) (stream->physical, buf, len);87 return (*stream->write) (stream->physical, buf, len); 91 88 } 92 89 93 90 static __inline__ int 94 __objc_code_char (unsigned char *buf, signed char val)91 __objc_code_char (unsigned char *buf, signed char val) 95 92 { 96 93 if (val >= 0) … … 105 102 106 103 int 107 objc_write_char (struct objc_typed_stream *stream, signed char value)108 { 109 unsigned char buf[sizeof (char) +1];104 objc_write_char (struct objc_typed_stream *stream, signed char value) 105 { 106 unsigned char buf[sizeof (char) + 1]; 110 107 int len = __objc_code_char (buf, value); 111 return (*stream->write) (stream->physical, buf, len);108 return (*stream->write) (stream->physical, buf, len); 112 109 } 113 110 114 111 static __inline__ int 115 __objc_code_unsigned_short (unsigned char *buf, unsigned short val)112 __objc_code_unsigned_short (unsigned char *buf, unsigned short val) 116 113 { 117 114 if ((val&_B_VALUE) == val) … … 126 123 buf[0] = _B_NINT; 127 124 128 for (c = sizeof(short); c != 0; c -= 1)129 if (((val >>(8*(c-1)))%0x100) != 0)125 for (c = sizeof (short); c != 0; c -= 1) 126 if (((val >> (8*(c - 1)))%0x100) != 0) 130 127 break; 131 128 … … 134 131 for (b = 1; c != 0; c--, b++) 135 132 { 136 buf[b] = (val >> (8*(c -1)))%0x100;133 buf[b] = (val >> (8*(c - 1)))%0x100; 137 134 } 138 135 … … 142 139 143 140 int 144 objc_write_unsigned_short (struct objc_typed_stream *stream,141 objc_write_unsigned_short (struct objc_typed_stream *stream, 145 142 unsigned short value) 146 143 { 147 unsigned char buf[sizeof (unsigned short) +1];144 unsigned char buf[sizeof (unsigned short) + 1]; 148 145 int len = __objc_code_unsigned_short (buf, value); 149 return (*stream->write) (stream->physical, buf, len);146 return (*stream->write) (stream->physical, buf, len); 150 147 } 151 148 152 149 static __inline__ int 153 __objc_code_short (unsigned char *buf, short val)150 __objc_code_short (unsigned char *buf, short val) 154 151 { 155 152 int sign = (val < 0); … … 161 158 162 159 int 163 objc_write_short (struct objc_typed_stream *stream, short value)164 { 165 unsigned char buf[sizeof (short) +1];160 objc_write_short (struct objc_typed_stream *stream, short value) 161 { 162 unsigned char buf[sizeof (short) + 1]; 166 163 int len = __objc_code_short (buf, value); 167 return (*stream->write) (stream->physical, buf, len);164 return (*stream->write) (stream->physical, buf, len); 168 165 } 169 166 170 167 171 168 static __inline__ int 172 __objc_code_unsigned_int (unsigned char *buf, unsigned int val)169 __objc_code_unsigned_int (unsigned char *buf, unsigned int val) 173 170 { 174 171 if ((val&_B_VALUE) == val) … … 183 180 buf[0] = _B_NINT; 184 181 185 for (c = sizeof(int); c != 0; c -= 1)186 if (((val >>(8*(c-1)))%0x100) != 0)182 for (c = sizeof (int); c != 0; c -= 1) 183 if (((val >> (8*(c - 1)))%0x100) != 0) 187 184 break; 188 185 … … 199 196 200 197 int 201 objc_write_unsigned_int (struct objc_typed_stream *stream, unsigned int value)202 { 203 unsigned char buf[sizeof (unsigned int)+1];198 objc_write_unsigned_int (struct objc_typed_stream *stream, unsigned int value) 199 { 200 unsigned char buf[sizeof (unsigned int) + 1]; 204 201 int len = __objc_code_unsigned_int (buf, value); 205 return (*stream->write) (stream->physical, buf, len);202 return (*stream->write) (stream->physical, buf, len); 206 203 } 207 204 208 205 static __inline__ int 209 __objc_code_int (unsigned char *buf, int val)206 __objc_code_int (unsigned char *buf, int val) 210 207 { 211 208 int sign = (val < 0); … … 217 214 218 215 int 219 objc_write_int (struct objc_typed_stream *stream, int value)220 { 221 unsigned char buf[sizeof (int)+1];216 objc_write_int (struct objc_typed_stream *stream, int value) 217 { 218 unsigned char buf[sizeof (int) + 1]; 222 219 int len = __objc_code_int (buf, value); 223 return (*stream->write) (stream->physical, buf, len);220 return (*stream->write) (stream->physical, buf, len); 224 221 } 225 222 226 223 static __inline__ int 227 __objc_code_unsigned_long (unsigned char *buf, unsigned long val)224 __objc_code_unsigned_long (unsigned char *buf, unsigned long val) 228 225 { 229 226 if ((val&_B_VALUE) == val) … … 238 235 buf[0] = _B_NINT; 239 236 240 for (c = sizeof(long); c != 0; c -= 1)241 if (((val >>(8*(c-1)))%0x100) != 0)237 for (c = sizeof (long); c != 0; c -= 1) 238 if (((val >> (8*(c - 1)))%0x100) != 0) 242 239 break; 243 240 … … 246 243 for (b = 1; c != 0; c--, b++) 247 244 { 248 buf[b] = (val >> (8*(c -1)))%0x100;245 buf[b] = (val >> (8*(c - 1)))%0x100; 249 246 } 250 247 … … 254 251 255 252 int 256 objc_write_unsigned_long (struct objc_typed_stream *stream,253 objc_write_unsigned_long (struct objc_typed_stream *stream, 257 254 unsigned long value) 258 255 { 259 unsigned char buf[sizeof (unsigned long)+1];256 unsigned char buf[sizeof (unsigned long) + 1]; 260 257 int len = __objc_code_unsigned_long (buf, value); 261 return (*stream->write) (stream->physical, buf, len);258 return (*stream->write) (stream->physical, buf, len); 262 259 } 263 260 264 261 static __inline__ int 265 __objc_code_long (unsigned char *buf, long val)262 __objc_code_long (unsigned char *buf, long val) 266 263 { 267 264 int sign = (val < 0); … … 273 270 274 271 int 275 objc_write_long (struct objc_typed_stream *stream, long value)276 { 277 unsigned char buf[sizeof (long)+1];272 objc_write_long (struct objc_typed_stream *stream, long value) 273 { 274 unsigned char buf[sizeof (long) + 1]; 278 275 int len = __objc_code_long (buf, value); 279 return (*stream->write) (stream->physical, buf, len);276 return (*stream->write) (stream->physical, buf, len); 280 277 } 281 278 282 279 283 280 int 284 objc_write_string (struct objc_typed_stream *stream,285 const unsigned char *string, unsigned int nbytes)286 { 287 unsigned char buf[sizeof (unsigned int)+1];281 objc_write_string (struct objc_typed_stream *stream, 282 const unsigned char *string, unsigned int nbytes) 283 { 284 unsigned char buf[sizeof (unsigned int) + 1]; 288 285 int len = __objc_code_unsigned_int (buf, nbytes); 289 286 … … 294 291 buf[0] = (buf[0]&_B_VALUE)|_B_NSTR; 295 292 296 if ((*stream->write) (stream->physical, buf, len) != 0)297 return (*stream->write) (stream->physical, string, nbytes);293 if ((*stream->write) (stream->physical, buf, len) != 0) 294 return (*stream->write) (stream->physical, string, nbytes); 298 295 else 299 296 return 0; … … 301 298 302 299 int 303 objc_write_string_atomic (struct objc_typed_stream *stream,304 unsigned char *string, unsigned int nbytes)300 objc_write_string_atomic (struct objc_typed_stream *stream, 301 unsigned char *string, unsigned int nbytes) 305 302 { 306 303 unsigned long key; … … 318 315 319 316 static int 320 objc_write_register_common (struct objc_typed_stream *stream,317 objc_write_register_common (struct objc_typed_stream *stream, 321 318 unsigned long key) 322 319 { 323 320 unsigned char buf[sizeof (unsigned long)+2]; 324 int len = __objc_code_unsigned_long (buf +1, key);321 int len = __objc_code_unsigned_long (buf + 1, key); 325 322 if (len == 1) 326 323 { 327 324 buf[0] = _B_RCOMM|0x01; 328 325 buf[1] &= _B_VALUE; 329 return (*stream->write) (stream->physical, buf, len+1);326 return (*stream->write) (stream->physical, buf, len + 1); 330 327 } 331 328 else 332 329 { 333 330 buf[1] = (buf[1]&_B_VALUE)|_B_RCOMM; 334 return (*stream->write) (stream->physical, buf+1, len);331 return (*stream->write) (stream->physical, buf + 1, len); 335 332 } 336 333 } 337 334 338 335 static int 339 objc_write_use_common (struct objc_typed_stream *stream, unsigned long key)336 objc_write_use_common (struct objc_typed_stream *stream, unsigned long key) 340 337 { 341 338 unsigned char buf[sizeof (unsigned long)+2]; 342 int len = __objc_code_unsigned_long (buf +1, key);339 int len = __objc_code_unsigned_long (buf + 1, key); 343 340 if (len == 1) 344 341 { 345 342 buf[0] = _B_UCOMM|0x01; 346 343 buf[1] &= _B_VALUE; 347 return (*stream->write) (stream->physical, buf, 2);344 return (*stream->write) (stream->physical, buf, 2); 348 345 } 349 346 else 350 347 { 351 348 buf[1] = (buf[1]&_B_VALUE)|_B_UCOMM; 352 return (*stream->write) (stream->physical, buf+1, len);349 return (*stream->write) (stream->physical, buf + 1, len); 353 350 } 354 351 } 355 352 356 353 static __inline__ int 357 __objc_write_extension (struct objc_typed_stream *stream, unsigned char code)354 __objc_write_extension (struct objc_typed_stream *stream, unsigned char code) 358 355 { 359 356 if (code <= _B_VALUE) 360 357 { 361 358 unsigned char buf = code|_B_EXT; 362 return (*stream->write) (stream->physical, &buf, 1);359 return (*stream->write) (stream->physical, &buf, 1); 363 360 } 364 361 else 365 362 { 366 objc_error (nil, OBJC_ERR_BAD_OPCODE,367 "__objc_write_extension: bad opcode %c\n", code);363 objc_error (nil, OBJC_ERR_BAD_OPCODE, 364 "__objc_write_extension: bad opcode %c\n", code); 368 365 return -1; 369 366 } … … 371 368 372 369 __inline__ int 373 __objc_write_object (struct objc_typed_stream *stream, id object)370 __objc_write_object (struct objc_typed_stream *stream, id object) 374 371 { 375 372 unsigned char buf = '\0'; … … 379 376 __objc_write_extension (stream, _BX_OBJECT); 380 377 objc_write_class (stream, object->class_pointer); 381 (*objc_msg_lookup (object, write_sel))(object, write_sel, stream);382 return (*stream->write) (stream->physical, &buf, 1);378 (*objc_msg_lookup (object, write_sel)) (object, write_sel, stream); 379 return (*stream->write) (stream->physical, &buf, 1); 383 380 } 384 381 else 385 return objc_write_use_common (stream, 0);382 return objc_write_use_common (stream, 0); 386 383 } 387 384 388 385 int 389 objc_write_object_reference (struct objc_typed_stream *stream, id object)386 objc_write_object_reference (struct objc_typed_stream *stream, id object) 390 387 { 391 388 unsigned long key; … … 398 395 399 396 int 400 objc_write_root_object (struct objc_typed_stream *stream, id object)397 objc_write_root_object (struct objc_typed_stream *stream, id object) 401 398 { 402 399 int len = 0; … … 408 405 stream->writing_root_p = 1; 409 406 __objc_write_extension (stream, _BX_OBJROOT); 410 if ((len = objc_write_object (stream, object)))411 __objc_finish_write_root_object (stream);407 if ((len = objc_write_object (stream, object))) 408 __objc_finish_write_root_object (stream); 412 409 stream->writing_root_p = 0; 413 410 } … … 416 413 417 414 int 418 objc_write_object (struct objc_typed_stream *stream, id object)415 objc_write_object (struct objc_typed_stream *stream, id object) 419 416 { 420 417 unsigned long key; … … 423 420 424 421 else if (object == nil) 425 return objc_write_use_common (stream, 0);422 return objc_write_use_common (stream, 0); 426 423 427 424 else … … 436 433 437 434 __inline__ int 438 __objc_write_class (struct objc_typed_stream * stream, struct objc_class*class)435 __objc_write_class (struct objc_typed_stream *stream, struct objc_class *class) 439 436 { 440 437 __objc_write_extension (stream, _BX_CLASS); 441 objc_write_string_atomic (stream, (char*)class->name,442 strlen ((char*)class->name));438 objc_write_string_atomic (stream, (char *) class->name, 439 strlen ((char *) class->name)); 443 440 return objc_write_unsigned_long (stream, class->version); 444 441 } … … 446 443 447 444 static int 448 objc_write_class (struct objc_typed_stream *stream,449 struct objc_class *class)445 objc_write_class (struct objc_typed_stream *stream, 446 struct objc_class *class) 450 447 { 451 448 unsigned long key; … … 455 452 { 456 453 int length; 457 hash_add (&stream->stream_table, LONG2PTR(key =PTR2LONG(class)), class);454 hash_add (&stream->stream_table, LONG2PTR(key = PTR2LONG(class)), class); 458 455 if ((length = objc_write_register_common (stream, key))) 459 456 return __objc_write_class (stream, class); … … 464 461 465 462 __inline__ int 466 __objc_write_selector (struct objc_typed_stream *stream, SEL selector)467 { 468 const char *sel_name;463 __objc_write_selector (struct objc_typed_stream *stream, SEL selector) 464 { 465 const char *sel_name; 469 466 __objc_write_extension (stream, _BX_SEL); 470 467 /* to handle NULL selectors */ … … 476 473 477 474 int 478 objc_write_selector (struct objc_typed_stream *stream, SEL selector)479 { 480 const char *sel_name;475 objc_write_selector (struct objc_typed_stream *stream, SEL selector) 476 { 477 const char *sel_name; 481 478 unsigned long key; 482 479 … … 492 489 int length; 493 490 hash_add (&stream->stream_table, 494 LONG2PTR(key =PTR2LONG(sel_name)), (char*)sel_name);491 LONG2PTR(key = PTR2LONG(sel_name)), (char *) sel_name); 495 492 if ((length = objc_write_register_common (stream, key))) 496 493 return __objc_write_selector (stream, selector); … … 506 503 507 504 __inline__ int 508 objc_read_char (struct objc_typed_stream * stream, char*val)505 objc_read_char (struct objc_typed_stream *stream, char *val) 509 506 { 510 507 unsigned char buf; 511 508 int len; 512 len = (*stream->read) (stream->physical, &buf, 1);509 len = (*stream->read) (stream->physical, &buf, 1); 513 510 if (len != 0) 514 511 { … … 518 515 else if ((buf & _B_NUMBER) == 1) 519 516 { 520 len = (*stream->read) (stream->physical, val, 1);517 len = (*stream->read) (stream->physical, val, 1); 521 518 if (buf&_B_SIGN) 522 (*val) = -1 *(*val);519 (*val) = -1 * (*val); 523 520 } 524 521 525 522 else 526 objc_error (nil, OBJC_ERR_BAD_DATA,527 "expected 8bit signed int, got %dbit int",528 (int)(buf&_B_NUMBER)*8);523 objc_error (nil, OBJC_ERR_BAD_DATA, 524 "expected 8bit signed int, got %dbit int", 525 (int) (buf&_B_NUMBER)*8); 529 526 } 530 527 return len; … … 533 530 534 531 __inline__ int 535 objc_read_unsigned_char (struct objc_typed_stream * stream, unsigned char*val)532 objc_read_unsigned_char (struct objc_typed_stream *stream, unsigned char *val) 536 533 { 537 534 unsigned char buf; 538 535 int len; 539 if ((len = (*stream->read) (stream->physical, &buf, 1)))536 if ((len = (*stream->read) (stream->physical, &buf, 1))) 540 537 { 541 538 if ((buf & _B_CODE) == _B_SINT) … … 543 540 544 541 else if ((buf & _B_NUMBER) == 1) 545 len = (*stream->read) (stream->physical, val, 1);542 len = (*stream->read) (stream->physical, val, 1); 546 543 547 544 else 548 objc_error (nil, OBJC_ERR_BAD_DATA,549 "expected 8bit unsigned int, got %dbit int",550 (int)(buf&_B_NUMBER)*8);545 objc_error (nil, OBJC_ERR_BAD_DATA, 546 "expected 8bit unsigned int, got %dbit int", 547 (int) (buf&_B_NUMBER)*8); 551 548 } 552 549 return len; … … 554 551 555 552 __inline__ int 556 objc_read_short (struct objc_typed_stream * stream, short*value)557 { 558 unsigned char buf[sizeof (short)+1];553 objc_read_short (struct objc_typed_stream *stream, short *value) 554 { 555 unsigned char buf[sizeof (short) + 1]; 559 556 int len; 560 if ((len = (*stream->read) (stream->physical, buf, 1)))557 if ((len = (*stream->read) (stream->physical, buf, 1))) 561 558 { 562 559 if ((buf[0] & _B_CODE) == _B_SINT) … … 567 564 int pos = 1; 568 565 int nbytes = buf[0] & _B_NUMBER; 569 if (nbytes > sizeof (short))570 objc_error (nil, OBJC_ERR_BAD_DATA,571 "expected short, got bigger (%dbits)", nbytes*8);572 len = (*stream->read) (stream->physical, buf+1, nbytes);566 if (nbytes > (int) sizeof (short)) 567 objc_error (nil, OBJC_ERR_BAD_DATA, 568 "expected short, got bigger (%dbits)", nbytes*8); 569 len = (*stream->read) (stream->physical, buf + 1, nbytes); 573 570 (*value) = 0; 574 571 while (pos <= nbytes) … … 582 579 583 580 __inline__ int 584 objc_read_unsigned_short (struct objc_typed_stream *stream,585 unsigned short *value)586 { 587 unsigned char buf[sizeof (unsigned short)+1];581 objc_read_unsigned_short (struct objc_typed_stream *stream, 582 unsigned short *value) 583 { 584 unsigned char buf[sizeof (unsigned short) + 1]; 588 585 int len; 589 if ((len = (*stream->read) (stream->physical, buf, 1)))586 if ((len = (*stream->read) (stream->physical, buf, 1))) 590 587 { 591 588 if ((buf[0] & _B_CODE) == _B_SINT) … … 596 593 int pos = 1; 597 594 int nbytes = buf[0] & _B_NUMBER; 598 if (nbytes > sizeof (short))599 objc_error (nil, OBJC_ERR_BAD_DATA,600 "expected short, got int or bigger");601 len = (*stream->read) (stream->physical, buf+1, nbytes);595 if (nbytes > (int) sizeof (short)) 596 objc_error (nil, OBJC_ERR_BAD_DATA, 597 "expected short, got int or bigger"); 598 len = (*stream->read) (stream->physical, buf + 1, nbytes); 602 599 (*value) = 0; 603 600 while (pos <= nbytes) … … 610 607 611 608 __inline__ int 612 objc_read_int (struct objc_typed_stream * stream, int*value)613 { 614 unsigned char buf[sizeof (int)+1];609 objc_read_int (struct objc_typed_stream *stream, int *value) 610 { 611 unsigned char buf[sizeof (int) + 1]; 615 612 int len; 616 if ((len = (*stream->read) (stream->physical, buf, 1)))613 if ((len = (*stream->read) (stream->physical, buf, 1))) 617 614 { 618 615 if ((buf[0] & _B_CODE) == _B_SINT) … … 623 620 int pos = 1; 624 621 int nbytes = buf[0] & _B_NUMBER; 625 if (nbytes > sizeof (int))626 objc_error (nil, OBJC_ERR_BAD_DATA, "expected int, got bigger");627 len = (*stream->read) (stream->physical, buf+1, nbytes);622 if (nbytes > (int) sizeof (int)) 623 objc_error (nil, OBJC_ERR_BAD_DATA, "expected int, got bigger"); 624 len = (*stream->read) (stream->physical, buf + 1, nbytes); 628 625 (*value) = 0; 629 626 while (pos <= nbytes) … … 637 634 638 635 __inline__ int 639 objc_read_long (struct objc_typed_stream * stream, long*value)640 { 641 unsigned char buf[sizeof (long)+1];636 objc_read_long (struct objc_typed_stream *stream, long *value) 637 { 638 unsigned char buf[sizeof (long) + 1]; 642 639 int len; 643 if ((len = (*stream->read) (stream->physical, buf, 1)))640 if ((len = (*stream->read) (stream->physical, buf, 1))) 644 641 { 645 642 if ((buf[0] & _B_CODE) == _B_SINT) … … 650 647 int pos = 1; 651 648 int nbytes = buf[0] & _B_NUMBER; 652 if (nbytes > sizeof (long))653 objc_error (nil, OBJC_ERR_BAD_DATA, "expected long, got bigger");654 len = (*stream->read) (stream->physical, buf+1, nbytes);649 if (nbytes > (int) sizeof (long)) 650 objc_error (nil, OBJC_ERR_BAD_DATA, "expected long, got bigger"); 651 len = (*stream->read) (stream->physical, buf + 1, nbytes); 655 652 (*value) = 0; 656 653 while (pos <= nbytes) … … 664 661 665 662 __inline__ int 666 __objc_read_nbyte_uint (struct objc_typed_stream* stream, 667 unsigned int nbytes, unsigned int* val) 668 { 669 int len, pos = 0; 670 unsigned char buf[sizeof(unsigned int)+1]; 663 __objc_read_nbyte_uint (struct objc_typed_stream *stream, 664 unsigned int nbytes, unsigned int *val) 665 { 666 int len; 667 unsigned int pos = 0; 668 unsigned char buf[sizeof (unsigned int) + 1]; 671 669 672 670 if (nbytes > sizeof (int)) 673 objc_error (nil, OBJC_ERR_BAD_DATA, "expected int, got bigger");674 675 len = (*stream->read) (stream->physical, buf, nbytes);671 objc_error (nil, OBJC_ERR_BAD_DATA, "expected int, got bigger"); 672 673 len = (*stream->read) (stream->physical, buf, nbytes); 676 674 (*val) = 0; 677 675 while (pos < nbytes) … … 682 680 683 681 __inline__ int 684 objc_read_unsigned_int (struct objc_typed_stream *stream,685 unsigned int *value)686 { 687 unsigned char buf[sizeof (unsigned int)+1];682 objc_read_unsigned_int (struct objc_typed_stream *stream, 683 unsigned int *value) 684 { 685 unsigned char buf[sizeof (unsigned int) + 1]; 688 686 int len; 689 if ((len = (*stream->read) (stream->physical, buf, 1)))687 if ((len = (*stream->read) (stream->physical, buf, 1))) 690 688 { 691 689 if ((buf[0] & _B_CODE) == _B_SINT) … … 700 698 701 699 int 702 __objc_read_nbyte_ulong (struct objc_typed_stream* stream, 703 unsigned int nbytes, unsigned long* val) 704 { 705 int len, pos = 0; 706 unsigned char buf[sizeof(unsigned long)+1]; 700 __objc_read_nbyte_ulong (struct objc_typed_stream *stream, 701 unsigned int nbytes, unsigned long *val) 702 { 703 int len; 704 unsigned int pos = 0; 705 unsigned char buf[sizeof (unsigned long) + 1]; 707 706 708 707 if (nbytes > sizeof (long)) 709 objc_error (nil, OBJC_ERR_BAD_DATA, "expected long, got bigger");710 711 len = (*stream->read) (stream->physical, buf, nbytes);708 objc_error (nil, OBJC_ERR_BAD_DATA, "expected long, got bigger"); 709 710 len = (*stream->read) (stream->physical, buf, nbytes); 712 711 (*val) = 0; 713 712 while (pos < nbytes) … … 718 717 719 718 __inline__ int 720 objc_read_unsigned_long (struct objc_typed_stream *stream,721 unsigned long*value)722 { 723 unsigned char buf[sizeof (unsigned long)+1];719 objc_read_unsigned_long (struct objc_typed_stream *stream, 720 unsigned long *value) 721 { 722 unsigned char buf[sizeof (unsigned long) + 1]; 724 723 int len; 725 if ((len = (*stream->read) (stream->physical, buf, 1)))724 if ((len = (*stream->read) (stream->physical, buf, 1))) 726 725 { 727 726 if ((buf[0] & _B_CODE) == _B_SINT) … … 736 735 737 736 __inline__ int 738 objc_read_string (struct objc_typed_stream *stream,739 char **string)740 { 741 unsigned char buf[sizeof (unsigned int)+1];737 objc_read_string (struct objc_typed_stream *stream, 738 char **string) 739 { 740 unsigned char buf[sizeof (unsigned int) + 1]; 742 741 int len; 743 if ((len = (*stream->read) (stream->physical, buf, 1)))742 if ((len = (*stream->read) (stream->physical, buf, 1))) 744 743 { 745 744 unsigned long key = 0; … … 747 746 if ((buf[0]&_B_CODE) == _B_RCOMM) /* register following */ 748 747 { 749 len = __objc_read_nbyte_ulong (stream, (buf[0] & _B_VALUE), &key);750 len = (*stream->read) (stream->physical, buf, 1);748 len = __objc_read_nbyte_ulong (stream, (buf[0] & _B_VALUE), &key); 749 len = (*stream->read) (stream->physical, buf, 1); 751 750 } 752 751 … … 755 754 { 756 755 int length = buf[0]&_B_VALUE; 757 (*string) = (char*)objc_malloc (length+1);756 (*string) = (char*)objc_malloc (length + 1); 758 757 if (key) 759 758 hash_add (&stream->stream_table, LONG2PTR(key), *string); 760 len = (*stream->read) (stream->physical, *string, length);759 len = (*stream->read) (stream->physical, *string, length); 761 760 (*string)[length] = '\0'; 762 761 } … … 766 765 { 767 766 char *tmp; 768 len = __objc_read_nbyte_ulong (stream, (buf[0] & _B_VALUE), &key);767 len = __objc_read_nbyte_ulong (stream, (buf[0] & _B_VALUE), &key); 769 768 tmp = hash_value_for_key (stream->stream_table, LONG2PTR (key)); 770 *string = objc_malloc (strlen (tmp) + 1);769 *string = objc_malloc (strlen (tmp) + 1); 771 770 strcpy (*string, tmp); 772 771 } … … 776 775 { 777 776 unsigned int nbytes = buf[0]&_B_VALUE; 778 len = __objc_read_nbyte_uint (stream, nbytes, &nbytes);777 len = __objc_read_nbyte_uint (stream, nbytes, &nbytes); 779 778 if (len) { 780 (*string) = (char*)objc_malloc (nbytes+1);779 (*string) = (char*)objc_malloc (nbytes + 1); 781 780 if (key) 782 781 hash_add (&stream->stream_table, LONG2PTR(key), *string); 783 len = (*stream->read) (stream->physical, *string, nbytes);782 len = (*stream->read) (stream->physical, *string, nbytes); 784 783 (*string)[nbytes] = '\0'; 785 784 } … … 788 787 789 788 default: 790 objc_error (nil, OBJC_ERR_BAD_DATA,791 "expected string, got opcode %c\n", (buf[0]&_B_CODE));789 objc_error (nil, OBJC_ERR_BAD_DATA, 790 "expected string, got opcode %c\n", (buf[0]&_B_CODE)); 792 791 } 793 792 } … … 798 797 799 798 int 800 objc_read_object (struct objc_typed_stream * stream, id*object)799 objc_read_object (struct objc_typed_stream *stream, id *object) 801 800 { 802 801 unsigned char buf[sizeof (unsigned int)]; 803 802 int len; 804 if ((len = (*stream->read) (stream->physical, buf, 1)))803 if ((len = (*stream->read) (stream->physical, buf, 1))) 805 804 { 806 805 SEL read_sel = sel_get_any_uid ("read:"); … … 809 808 if ((buf[0]&_B_CODE) == _B_RCOMM) /* register common */ 810 809 { 811 len = __objc_read_nbyte_ulong (stream, (buf[0] & _B_VALUE), &key);812 len = (*stream->read) (stream->physical, buf, 1);810 len = __objc_read_nbyte_ulong (stream, (buf[0] & _B_VALUE), &key); 811 len = (*stream->read) (stream->physical, buf, 1); 813 812 } 814 813 … … 821 820 822 821 /* create instance */ 823 (*object) = class_create_instance (class);822 (*object) = class_create_instance (class); 824 823 825 824 /* register? */ … … 829 828 /* send -read: */ 830 829 if (__objc_responds_to (*object, read_sel)) 831 (*get_imp (class, read_sel))(*object, read_sel, stream);830 (*get_imp (class, read_sel)) (*object, read_sel, stream); 832 831 833 832 /* check null-byte */ 834 len = (*stream->read) (stream->physical, buf, 1);833 len = (*stream->read) (stream->physical, buf, 1); 835 834 if (buf[0] != '\0') 836 objc_error (nil, OBJC_ERR_BAD_DATA,837 "expected null-byte, got opcode %c", buf[0]);835 objc_error (nil, OBJC_ERR_BAD_DATA, 836 "expected null-byte, got opcode %c", buf[0]); 838 837 } 839 838 … … 841 840 { 842 841 if (key) 843 objc_error (nil, OBJC_ERR_BAD_KEY, "cannot register use upcode...");844 len = __objc_read_nbyte_ulong (stream, (buf[0] & _B_VALUE), &key);842 objc_error (nil, OBJC_ERR_BAD_KEY, "cannot register use upcode..."); 843 len = __objc_read_nbyte_ulong (stream, (buf[0] & _B_VALUE), &key); 845 844 (*object) = hash_value_for_key (stream->object_table, LONG2PTR(key)); 846 845 } … … 848 847 else if (buf[0] == (_B_EXT | _BX_OBJREF)) /* a forward reference */ 849 848 { 850 struct objc_list *other;849 struct objc_list *other; 851 850 len = objc_read_unsigned_long (stream, &key); 852 other = (struct objc_list *)hash_value_for_key (stream->object_refs,853 LONG2PTR(key));851 other = (struct objc_list *) hash_value_for_key (stream->object_refs, 852 LONG2PTR(key)); 854 853 hash_add (&stream->object_refs, LONG2PTR(key), 855 (void *)list_cons(object, other));854 (void *)list_cons (object, other)); 856 855 } 857 856 … … 859 858 { 860 859 if (key) 861 objc_error (nil, OBJC_ERR_BAD_KEY,862 "cannot register root object...");860 objc_error (nil, OBJC_ERR_BAD_KEY, 861 "cannot register root object..."); 863 862 len = objc_read_object (stream, object); 864 863 __objc_finish_read_root_object (stream); … … 866 865 867 866 else 868 objc_error (nil, OBJC_ERR_BAD_DATA,869 "expected object, got opcode %c", buf[0]);867 objc_error (nil, OBJC_ERR_BAD_DATA, 868 "expected object, got opcode %c", buf[0]); 870 869 } 871 870 return len; … … 873 872 874 873 static int 875 objc_read_class (struct objc_typed_stream * stream, Class*class)874 objc_read_class (struct objc_typed_stream *stream, Class *class) 876 875 { 877 876 unsigned char buf[sizeof (unsigned int)]; 878 877 int len; 879 if ((len = (*stream->read) (stream->physical, buf, 1)))878 if ((len = (*stream->read) (stream->physical, buf, 1))) 880 879 { 881 880 unsigned long key = 0; … … 883 882 if ((buf[0]&_B_CODE) == _B_RCOMM) /* register following */ 884 883 { 885 len = __objc_read_nbyte_ulong (stream, (buf[0] & _B_VALUE), &key);886 len = (*stream->read) (stream->physical, buf, 1);884 len = __objc_read_nbyte_ulong (stream, (buf[0] & _B_VALUE), &key); 885 len = (*stream->read) (stream->physical, buf, 1); 887 886 } 888 887 889 888 if (buf[0] == (_B_EXT | _BX_CLASS)) 890 889 { 891 char *class_name;890 char *class_name; 892 891 unsigned long version; 893 892 894 893 /* get class */ 895 894 len = objc_read_string (stream, &class_name); 896 (*class) = objc_get_class (class_name);897 objc_free (class_name);895 (*class) = objc_get_class (class_name); 896 objc_free (class_name); 898 897 899 898 /* register */ … … 901 900 hash_add (&stream->stream_table, LONG2PTR(key), *class); 902 901 903 objc_read_unsigned_long (stream, &version);904 hash_add (&stream->class_table, (*class)->name, (void *)version);902 objc_read_unsigned_long (stream, &version); 903 hash_add (&stream->class_table, (*class)->name, (void *)version); 905 904 } 906 905 … … 908 907 { 909 908 if (key) 910 objc_error (nil, OBJC_ERR_BAD_KEY, "cannot register use upcode...");911 len = __objc_read_nbyte_ulong (stream, (buf[0] & _B_VALUE), &key);912 (*class)= hash_value_for_key (stream->stream_table, LONG2PTR(key));913 if (! *class)914 objc_error (nil, OBJC_ERR_BAD_CLASS,915 "cannot find class for key %lu", key);909 objc_error (nil, OBJC_ERR_BAD_KEY, "cannot register use upcode..."); 910 len = __objc_read_nbyte_ulong (stream, (buf[0] & _B_VALUE), &key); 911 *class = hash_value_for_key (stream->stream_table, LONG2PTR(key)); 912 if (! *class) 913 objc_error (nil, OBJC_ERR_BAD_CLASS, 914 "cannot find class for key %lu", key); 916 915 } 917 916 918 917 else 919 objc_error (nil, OBJC_ERR_BAD_DATA,920 "expected class, got opcode %c", buf[0]);918 objc_error (nil, OBJC_ERR_BAD_DATA, 919 "expected class, got opcode %c", buf[0]); 921 920 } 922 921 return len; … … 924 923 925 924 int 926 objc_read_selector (struct objc_typed_stream *stream, SEL* selector)925 objc_read_selector (struct objc_typed_stream *stream, SEL* selector) 927 926 { 928 927 unsigned char buf[sizeof (unsigned int)]; 929 928 int len; 930 if ((len = (*stream->read) (stream->physical, buf, 1)))929 if ((len = (*stream->read) (stream->physical, buf, 1))) 931 930 { 932 931 unsigned long key = 0; … … 934 933 if ((buf[0]&_B_CODE) == _B_RCOMM) /* register following */ 935 934 { 936 len = __objc_read_nbyte_ulong (stream, (buf[0] & _B_VALUE), &key);937 len = (*stream->read) (stream->physical, buf, 1);935 len = __objc_read_nbyte_ulong (stream, (buf[0] & _B_VALUE), &key); 936 len = (*stream->read) (stream->physical, buf, 1); 938 937 } 939 938 940 939 if (buf[0] == (_B_EXT|_BX_SEL)) /* selector! */ 941 940 { 942 char *selector_name;941 char *selector_name; 943 942 944 943 /* get selector */ 945 944 len = objc_read_string (stream, &selector_name); 946 945 /* To handle NULL selectors */ 947 if (0 == strlen (selector_name))946 if (0 == strlen (selector_name)) 948 947 { 949 948 (*selector) = (SEL)0; … … 951 950 } 952 951 else 953 (*selector) = sel_get_any_uid (selector_name);954 objc_free (selector_name);952 (*selector) = sel_get_any_uid (selector_name); 953 objc_free (selector_name); 955 954 956 955 /* register */ 957 956 if (key) 958 hash_add (&stream->stream_table, LONG2PTR(key), (void *)*selector);957 hash_add (&stream->stream_table, LONG2PTR(key), (void *) *selector); 959 958 } 960 959 … … 962 961 { 963 962 if (key) 964 objc_error (nil, OBJC_ERR_BAD_KEY, "cannot register use upcode...");965 len = __objc_read_nbyte_ulong (stream, (buf[0] & _B_VALUE), &key);963 objc_error (nil, OBJC_ERR_BAD_KEY, "cannot register use upcode..."); 964 len = __objc_read_nbyte_ulong (stream, (buf[0] & _B_VALUE), &key); 966 965 (*selector) = hash_value_for_key (stream->stream_table, 967 966 LONG2PTR(key)); … … 969 968 970 969 else 971 objc_error (nil, OBJC_ERR_BAD_DATA,972 "expected selector, got opcode %c", buf[0]);970 objc_error (nil, OBJC_ERR_BAD_DATA, 971 "expected selector, got opcode %c", buf[0]); 973 972 } 974 973 return len; … … 985 984 986 985 int 987 objc_write_type (TypedStream* stream, const char* type, const void*data)988 { 989 switch (*type) {986 objc_write_type (TypedStream *stream, const char *type, const void *data) 987 { 988 switch (*type) { 990 989 case _C_ID: 991 return objc_write_object (stream, *(id *)data);990 return objc_write_object (stream, *(id *) data); 992 991 break; 993 992 994 993 case _C_CLASS: 995 return objc_write_class (stream, *(Class *)data);994 return objc_write_class (stream, *(Class *) data); 996 995 break; 997 996 998 997 case _C_SEL: 999 return objc_write_selector (stream, *(SEL *)data);998 return objc_write_selector (stream, *(SEL *) data); 1000 999 break; 1001 1000 1002 1001 case _C_CHR: 1003 return objc_write_char (stream, *(signed char*)data);1002 return objc_write_char (stream, *(signed char *) data); 1004 1003 break; 1005 1004 1006 1005 case _C_UCHR: 1007 return objc_write_unsigned_char (stream, *(unsigned char*)data);1006 return objc_write_unsigned_char (stream, *(unsigned char *) data); 1008 1007 break; 1009 1008 1010 1009 case _C_SHT: 1011 return objc_write_short (stream, *(short*)data);1010 return objc_write_short (stream, *(short *) data); 1012 1011 break; 1013 1012 1014 1013 case _C_USHT: 1015 return objc_write_unsigned_short (stream, *(unsigned short*)data);1014 return objc_write_unsigned_short (stream, *(unsigned short *) data); 1016 1015 break; 1017 1016 1018 1017 case _C_INT: 1019 return objc_write_int (stream, *(int*)data);1018 return objc_write_int (stream, *(int *) data); 1020 1019 break; 1021 1020 1022 1021 case _C_UINT: 1023 return objc_write_unsigned_int (stream, *(unsigned int*)data);1022 return objc_write_unsigned_int (stream, *(unsigned int *) data); 1024 1023 break; 1025 1024 1026 1025 case _C_LNG: 1027 return objc_write_long (stream, *(long*)data);1026 return objc_write_long (stream, *(long *) data); 1028 1027 break; 1029 1028 1030 1029 case _C_ULNG: 1031 return objc_write_unsigned_long (stream, *(unsigned long*)data);1030 return objc_write_unsigned_long (stream, *(unsigned long *) data); 1032 1031 break; 1033 1032 1034 1033 case _C_CHARPTR: 1035 return objc_write_string (stream, *(char**)data, strlen(*(char**)data)); 1034 return objc_write_string (stream, 1035 *(char **) data, strlen (*(char **) data)); 1036 1036 break; 1037 1037 1038 1038 case _C_ATOM: 1039 return objc_write_string_atomic (stream, *(char **)data,1040 strlen (*(char**)data));1039 return objc_write_string_atomic (stream, *(char **) data, 1040 strlen (*(char **) data)); 1041 1041 break; 1042 1042 1043 1043 case _C_ARY_B: 1044 1044 { 1045 int len = atoi (type+1);1046 while (isdigit (*++type))1045 int len = atoi (type + 1); 1046 while (isdigit ((unsigned char) *++type)) 1047 1047 ; 1048 1048 return objc_write_array (stream, type, len, data); … … 1060 1060 align = objc_alignof_type (type); /* padd to alignment */ 1061 1061 acc_size += ROUND (acc_size, align); 1062 objc_write_type (stream, type, ((char *)data)+acc_size);1062 objc_write_type (stream, type, ((char *) data) + acc_size); 1063 1063 acc_size += objc_sizeof_type (type); /* add component size */ 1064 1064 type = objc_skip_typespec (type); /* skip component */ … … 1069 1069 default: 1070 1070 { 1071 objc_error (nil, OBJC_ERR_BAD_TYPE,1072 "objc_write_type: cannot parse typespec: %s\n", type);1071 objc_error (nil, OBJC_ERR_BAD_TYPE, 1072 "objc_write_type: cannot parse typespec: %s\n", type); 1073 1073 return 0; 1074 1074 } … … 1084 1084 1085 1085 int 1086 objc_read_type(TypedStream * stream, const char* type, void*data)1086 objc_read_type(TypedStream *stream, const char *type, void *data) 1087 1087 { 1088 1088 char c; 1089 switch (c = *type) {1089 switch (c = *type) { 1090 1090 case _C_ID: 1091 1091 return objc_read_object (stream, (id*)data); … … 1139 1139 case _C_ARY_B: 1140 1140 { 1141 int len = atoi (type+1);1142 while (isdigit (*++type))1141 int len = atoi (type + 1); 1142 while (isdigit ((unsigned char) *++type)) 1143 1143 ; 1144 1144 return objc_read_array (stream, type, len, data); … … 1165 1165 default: 1166 1166 { 1167 objc_error (nil, OBJC_ERR_BAD_TYPE,1168 "objc_read_type: cannot parse typespec: %s\n", type);1167 objc_error (nil, OBJC_ERR_BAD_TYPE, 1168 "objc_read_type: cannot parse typespec: %s\n", type); 1169 1169 return 0; 1170 1170 } … … 1183 1183 1184 1184 int 1185 objc_write_types (TypedStream * stream, const char*type, ...)1185 objc_write_types (TypedStream *stream, const char *type, ...) 1186 1186 { 1187 1187 va_list args; … … 1193 1193 for (c = type; *c; c = objc_skip_typespec (c)) 1194 1194 { 1195 switch (*c) {1195 switch (*c) { 1196 1196 case _C_ID: 1197 1197 res = objc_write_object (stream, *va_arg (args, id*)); … … 1199 1199 1200 1200 case _C_CLASS: 1201 res = objc_write_class (stream, *va_arg (args, Class*));1201 res = objc_write_class (stream, *va_arg (args, Class*)); 1202 1202 break; 1203 1203 1204 1204 case _C_SEL: 1205 res = objc_write_selector (stream, *va_arg (args, SEL*));1205 res = objc_write_selector (stream, *va_arg (args, SEL*)); 1206 1206 break; 1207 1207 … … 1216 1216 1217 1217 case _C_SHT: 1218 res = objc_write_short (stream, *va_arg (args, short*));1218 res = objc_write_short (stream, *va_arg (args, short*)); 1219 1219 break; 1220 1220 1221 1221 case _C_USHT: 1222 1222 res = objc_write_unsigned_short (stream, 1223 *va_arg (args, unsigned short*));1223 *va_arg (args, unsigned short*)); 1224 1224 break; 1225 1225 1226 1226 case _C_INT: 1227 res = objc_write_int(stream, *va_arg (args, int*));1227 res = objc_write_int(stream, *va_arg (args, int*)); 1228 1228 break; 1229 1229 1230 1230 case _C_UINT: 1231 res = objc_write_unsigned_int(stream, *va_arg (args, unsigned int*));1231 res = objc_write_unsigned_int(stream, *va_arg (args, unsigned int*)); 1232 1232 break; 1233 1233 1234 1234 case _C_LNG: 1235 res = objc_write_long(stream, *va_arg (args, long*));1235 res = objc_write_long(stream, *va_arg (args, long*)); 1236 1236 break; 1237 1237 1238 1238 case _C_ULNG: 1239 res = objc_write_unsigned_long(stream, *va_arg (args, unsigned long*));1239 res = objc_write_unsigned_long(stream, *va_arg (args, unsigned long*)); 1240 1240 break; 1241 1241 1242 1242 case _C_CHARPTR: 1243 1243 { 1244 char ** str = va_arg(args, char**);1245 res = objc_write_string (stream, *str, strlen (*str));1244 char **str = va_arg (args, char **); 1245 res = objc_write_string (stream, *str, strlen (*str)); 1246 1246 } 1247 1247 break; … … 1249 1249 case _C_ATOM: 1250 1250 { 1251 char ** str = va_arg(args, char**);1252 res = objc_write_string_atomic (stream, *str, strlen (*str));1251 char **str = va_arg (args, char **); 1252 res = objc_write_string_atomic (stream, *str, strlen (*str)); 1253 1253 } 1254 1254 break; … … 1256 1256 case _C_ARY_B: 1257 1257 { 1258 int len = atoi (c+1);1259 const char *t = c;1260 while (isdigit (*++t))1258 int len = atoi (c + 1); 1259 const char *t = c; 1260 while (isdigit ((unsigned char) *++t)) 1261 1261 ; 1262 res = objc_write_array (stream, t, len, va_arg (args, void*));1262 res = objc_write_array (stream, t, len, va_arg (args, void *)); 1263 1263 t = objc_skip_typespec (t); 1264 1264 if (*t != _C_ARY_E) 1265 objc_error (nil, OBJC_ERR_BAD_TYPE, "expected `]', got: %s", t);1265 objc_error (nil, OBJC_ERR_BAD_TYPE, "expected `]', got: %s", t); 1266 1266 } 1267 1267 break; 1268 1268 1269 1269 default: 1270 objc_error (nil, OBJC_ERR_BAD_TYPE,1271 "objc_write_types: cannot parse typespec: %s\n", type);1270 objc_error (nil, OBJC_ERR_BAD_TYPE, 1271 "objc_write_types: cannot parse typespec: %s\n", type); 1272 1272 } 1273 1273 } … … 1283 1283 1284 1284 int 1285 objc_read_types(TypedStream * stream, const char*type, ...)1285 objc_read_types(TypedStream *stream, const char *type, ...) 1286 1286 { 1287 1287 va_list args; … … 1289 1289 int res = 0; 1290 1290 1291 va_start (args, type);1291 va_start (args, type); 1292 1292 1293 1293 for (c = type; *c; c = objc_skip_typespec(c)) 1294 1294 { 1295 switch (*c) {1295 switch (*c) { 1296 1296 case _C_ID: 1297 res = objc_read_object(stream, va_arg (args, id*));1297 res = objc_read_object(stream, va_arg (args, id*)); 1298 1298 break; 1299 1299 1300 1300 case _C_CLASS: 1301 res = objc_read_class(stream, va_arg (args, Class*));1301 res = objc_read_class(stream, va_arg (args, Class*)); 1302 1302 break; 1303 1303 1304 1304 case _C_SEL: 1305 res = objc_read_selector(stream, va_arg (args, SEL*));1305 res = objc_read_selector(stream, va_arg (args, SEL*)); 1306 1306 break; 1307 1307 1308 1308 case _C_CHR: 1309 res = objc_read_char(stream, va_arg (args, char*));1309 res = objc_read_char(stream, va_arg (args, char*)); 1310 1310 break; 1311 1311 1312 1312 case _C_UCHR: 1313 res = objc_read_unsigned_char(stream, va_arg (args, unsigned char*));1313 res = objc_read_unsigned_char(stream, va_arg (args, unsigned char*)); 1314 1314 break; 1315 1315 1316 1316 case _C_SHT: 1317 res = objc_read_short(stream, va_arg (args, short*));1317 res = objc_read_short(stream, va_arg (args, short*)); 1318 1318 break; 1319 1319 1320 1320 case _C_USHT: 1321 res = objc_read_unsigned_short(stream, va_arg (args, unsigned short*));1321 res = objc_read_unsigned_short(stream, va_arg (args, unsigned short*)); 1322 1322 break; 1323 1323 1324 1324 case _C_INT: 1325 res = objc_read_int(stream, va_arg (args, int*));1325 res = objc_read_int(stream, va_arg (args, int*)); 1326 1326 break; 1327 1327 1328 1328 case _C_UINT: 1329 res = objc_read_unsigned_int(stream, va_arg (args, unsigned int*));1329 res = objc_read_unsigned_int(stream, va_arg (args, unsigned int*)); 1330 1330 break; 1331 1331 1332 1332 case _C_LNG: 1333 res = objc_read_long(stream, va_arg (args, long*));1333 res = objc_read_long(stream, va_arg (args, long*)); 1334 1334 break; 1335 1335 1336 1336 case _C_ULNG: 1337 res = objc_read_unsigned_long(stream, va_arg (args, unsigned long*));1337 res = objc_read_unsigned_long(stream, va_arg (args, unsigned long*)); 1338 1338 break; 1339 1339 … … 1341 1341 case _C_ATOM: 1342 1342 { 1343 char ** str = va_arg(args, char**);1343 char **str = va_arg (args, char **); 1344 1344 res = objc_read_string (stream, str); 1345 1345 } … … 1348 1348 case _C_ARY_B: 1349 1349 { 1350 int len = atoi (c+1);1351 const char *t = c;1352 while (isdigit (*++t))1350 int len = atoi (c + 1); 1351 const char *t = c; 1352 while (isdigit ((unsigned char) *++t)) 1353 1353 ; 1354 res = objc_read_array (stream, t, len, va_arg (args, void*));1354 res = objc_read_array (stream, t, len, va_arg (args, void *)); 1355 1355 t = objc_skip_typespec (t); 1356 1356 if (*t != _C_ARY_E) 1357 objc_error (nil, OBJC_ERR_BAD_TYPE, "expected `]', got: %s", t);1357 objc_error (nil, OBJC_ERR_BAD_TYPE, "expected `]', got: %s", t); 1358 1358 } 1359 1359 break; 1360 1360 1361 1361 default: 1362 objc_error (nil, OBJC_ERR_BAD_TYPE,1363 "objc_read_types: cannot parse typespec: %s\n", type);1362 objc_error (nil, OBJC_ERR_BAD_TYPE, 1363 "objc_read_types: cannot parse typespec: %s\n", type); 1364 1364 } 1365 1365 } 1366 va_end (args);1366 va_end (args); 1367 1367 return res; 1368 1368 } … … 1374 1374 1375 1375 int 1376 objc_write_array (TypedStream * stream, const char*type,1377 int count, const void *data)1376 objc_write_array (TypedStream *stream, const char *type, 1377 int count, const void *data) 1378 1378 { 1379 1379 int off = objc_sizeof_type(type); 1380 const char *where = data;1380 const char *where = data; 1381 1381 1382 1382 while (count-- > 0) … … 1396 1396 1397 1397 int 1398 objc_read_array (TypedStream * stream, const char*type,1399 int count, void *data)1398 objc_read_array (TypedStream *stream, const char *type, 1399 int count, void *data) 1400 1400 { 1401 1401 int off = objc_sizeof_type(type); 1402 char *where = (char*)data;1402 char *where = (char*)data; 1403 1403 1404 1404 while (count-- > 0) … … 1411 1411 1412 1412 static int 1413 __objc_fread (FILE* file, char*data, int len)1413 __objc_fread (FILE *file, char *data, int len) 1414 1414 { 1415 1415 return fread(data, len, 1, file); … … 1417 1417 1418 1418 static int 1419 __objc_fwrite (FILE* file, char*data, int len)1419 __objc_fwrite (FILE *file, char *data, int len) 1420 1420 { 1421 1421 return fwrite(data, len, 1, file); … … 1423 1423 1424 1424 static int 1425 __objc_feof (FILE*file)1425 __objc_feof (FILE *file) 1426 1426 { 1427 1427 return feof(file); … … 1429 1429 1430 1430 static int 1431 __objc_no_write(FILE* file, char* data, int len) 1431 __objc_no_write (FILE *file __attribute__ ((__unused__)), 1432 const char *data __attribute__ ((__unused__)), 1433 int len __attribute__ ((__unused__))) 1432 1434 { 1433 1435 objc_error (nil, OBJC_ERR_NO_WRITE, "TypedStream not open for writing"); … … 1436 1438 1437 1439 static int 1438 __objc_no_read(FILE* file, char* data, int len) 1440 __objc_no_read (FILE *file __attribute__ ((__unused__)), 1441 const char *data __attribute__ ((__unused__)), 1442 int len __attribute__ ((__unused__))) 1439 1443 { 1440 1444 objc_error (nil, OBJC_ERR_NO_READ, "TypedStream not open for reading"); … … 1443 1447 1444 1448 static int 1445 __objc_read_typed_stream_signature (TypedStream *stream)1449 __objc_read_typed_stream_signature (TypedStream *stream) 1446 1450 { 1447 1451 char buffer[80]; 1448 1452 int pos = 0; 1449 1453 do 1450 (*stream->read) (stream->physical, buffer+pos, 1);1454 (*stream->read) (stream->physical, buffer+pos, 1); 1451 1455 while (buffer[pos++] != '\0') 1452 1456 ; … … 1459 1463 1460 1464 static int 1461 __objc_write_typed_stream_signature (TypedStream *stream)1465 __objc_write_typed_stream_signature (TypedStream *stream) 1462 1466 { 1463 1467 char buffer[80]; 1464 1468 sprintf(buffer, "GNU TypedStream %d", OBJC_TYPED_STREAM_VERSION); 1465 1469 stream->version = OBJC_TYPED_STREAM_VERSION; 1466 (*stream->write) (stream->physical, buffer, strlen(buffer)+1);1470 (*stream->write) (stream->physical, buffer, strlen (buffer) + 1); 1467 1471 return 1; 1468 1472 } 1469 1473 1470 static void __objc_finish_write_root_object(struct objc_typed_stream *stream)1474 static void __objc_finish_write_root_object(struct objc_typed_stream *stream) 1471 1475 { 1472 1476 hash_delete (stream->object_table); … … 1476 1480 } 1477 1481 1478 static void __objc_finish_read_root_object(struct objc_typed_stream *stream)1482 static void __objc_finish_read_root_object(struct objc_typed_stream *stream) 1479 1483 { 1480 1484 node_ptr node; … … 1488 1492 node = hash_next (stream->object_refs, node)) 1489 1493 { 1490 struct objc_list *reflist = node->value;1491 const void *key = node->key;1494 struct objc_list *reflist = node->value; 1495 const void *key = node->key; 1492 1496 id object = hash_value_for_key (stream->object_table, key); 1493 while (reflist)1494 { 1495 *((id*) reflist->head) = object;1497 while (reflist) 1498 { 1499 *((id*) reflist->head) = object; 1496 1500 if (hash_value_for_key (free_list,reflist) == NULL) 1497 1501 hash_add (&free_list,reflist,reflist); … … 1521 1525 id object = node->value; 1522 1526 if (__objc_responds_to (object, awake_sel)) 1523 (*objc_msg_lookup (object, awake_sel))(object, awake_sel);1527 (*objc_msg_lookup (object, awake_sel)) (object, awake_sel); 1524 1528 } 1525 1529 } … … 1536 1540 */ 1537 1541 1538 TypedStream *1539 objc_open_typed_stream (FILE *physical, int mode)1540 { 1541 TypedStream * s = (TypedStream*)objc_malloc(sizeof(TypedStream));1542 TypedStream * 1543 objc_open_typed_stream (FILE *physical, int mode) 1544 { 1545 TypedStream *s = (TypedStream *) objc_malloc (sizeof (TypedStream)); 1542 1546 1543 1547 s->mode = mode; 1544 1548 s->physical = physical; 1545 s->stream_table = hash_new (64,1546 (hash_func_type)hash_ptr,1547 (compare_func_type)compare_ptrs);1548 s->object_table = hash_new (64,1549 (hash_func_type)hash_ptr,1550 (compare_func_type)compare_ptrs);1551 s->eof = (objc_typed_eof_func) __objc_feof;1552 s->flush = (objc_typed_flush_func) fflush;1549 s->stream_table = hash_new (64, 1550 (hash_func_type) hash_ptr, 1551 (compare_func_type) compare_ptrs); 1552 s->object_table = hash_new (64, 1553 (hash_func_type) hash_ptr, 1554 (compare_func_type) compare_ptrs); 1555 s->eof = (objc_typed_eof_func) __objc_feof; 1556 s->flush = (objc_typed_flush_func) fflush; 1553 1557 s->writing_root_p = 0; 1554 1558 if (mode == OBJC_READONLY) 1555 1559 { 1556 s->class_table = hash_new (8, (hash_func_type)hash_string,1557 (compare_func_type)compare_strings);1558 s->object_refs = hash_new (8, (hash_func_type)hash_ptr,1559 (compare_func_type)compare_ptrs);1560 s->read = (objc_typed_read_func) __objc_fread;1561 s->write = (objc_typed_write_func) __objc_no_write;1560 s->class_table = hash_new (8, (hash_func_type) hash_string, 1561 (compare_func_type) compare_strings); 1562 s->object_refs = hash_new (8, (hash_func_type) hash_ptr, 1563 (compare_func_type) compare_ptrs); 1564 s->read = (objc_typed_read_func) __objc_fread; 1565 s->write = (objc_typed_write_func) __objc_no_write; 1562 1566 __objc_read_typed_stream_signature (s); 1563 1567 } … … 1566 1570 s->class_table = 0; 1567 1571 s->object_refs = 0; 1568 s->read = (objc_typed_read_func) __objc_no_read;1569 s->write = (objc_typed_write_func) __objc_fwrite;1572 s->read = (objc_typed_read_func) __objc_no_read; 1573 s->write = (objc_typed_write_func) __objc_fwrite; 1570 1574 __objc_write_typed_stream_signature (s); 1571 1575 } … … 1584 1588 1585 1589 TypedStream* 1586 objc_open_typed_stream_for_file (const char *file_name, int mode)1587 { 1588 FILE *file = NULL;1589 TypedStream *s;1590 objc_open_typed_stream_for_file (const char *file_name, int mode) 1591 { 1592 FILE *file = NULL; 1593 TypedStream *s; 1590 1594 1591 1595 if (mode == OBJC_READONLY) … … 1611 1615 1612 1616 void 1613 objc_close_typed_stream (TypedStream *stream)1617 objc_close_typed_stream (TypedStream *stream) 1614 1618 { 1615 1619 if (stream->mode == OBJC_READONLY) … … 1624 1628 1625 1629 if (stream->type == (OBJC_MANAGED_STREAM | OBJC_FILE_STREAM)) 1626 fclose ((FILE *)stream->physical);1630 fclose ((FILE *)stream->physical); 1627 1631 1628 1632 objc_free(stream); … … 1630 1634 1631 1635 BOOL 1632 objc_end_of_typed_stream (TypedStream *stream)1633 { 1634 return (*stream->eof) (stream->physical);1636 objc_end_of_typed_stream (TypedStream *stream) 1637 { 1638 return (*stream->eof) (stream->physical); 1635 1639 } 1636 1640 1637 1641 void 1638 objc_flush_typed_stream (TypedStream *stream)1639 { 1640 (*stream->flush) (stream->physical);1642 objc_flush_typed_stream (TypedStream *stream) 1643 { 1644 (*stream->flush) (stream->physical); 1641 1645 } 1642 1646 1643 1647 long 1644 objc_get_stream_class_version (TypedStream *stream, Class class)1648 objc_get_stream_class_version (TypedStream *stream, Class class) 1645 1649 { 1646 1650 if (stream->class_table) -
Property cvs2svn:cvs-rev
changed from
Note:
See TracChangeset
for help on using the changeset viewer.