Overview
Comment: | Clean up the method replacement mess. |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
2d08ba105c2051dbd62575407b87d10e |
User & Date: | js on 2012-03-06 16:17:24 |
Other Links: | manifest | tags |
Context
2012-03-07
| ||
22:22 | Fix a missing (auto)release. check-in: fde986d949 user: js tags: trunk | |
2012-03-06
| ||
16:31 | Merge changes from default branch into runtime branch. check-in: 9bb186a7a3 user: js tags: runtime | |
16:17 | Clean up the method replacement mess. check-in: 2d08ba105c user: js tags: trunk | |
16:05 | Add OFTLSSocket.h to ObjFW.h. check-in: b8307fa156 user: js tags: trunk | |
Changes
Modified extra.mk.in from [512d8f1f74] to [c78962a205].
1 2 | OBJFW_SHARED_LIB = @OBJFW_SHARED_LIB@ OBJFW_STATIC_LIB = @OBJFW_STATIC_LIB@ | | | | 1 2 3 4 5 6 7 8 9 10 11 | OBJFW_SHARED_LIB = @OBJFW_SHARED_LIB@ OBJFW_STATIC_LIB = @OBJFW_STATIC_LIB@ OBJFW_LIB_MAJOR = 6 OBJFW_LIB_MINOR = 0 OBJFW_LIB_MAJOR_MINOR = ${OBJFW_LIB_MAJOR}.${OBJFW_LIB_MINOR} ASPRINTF_M = @ASPRINTF_M@ ATOMIC_H = @ATOMIC_H@ BIN_PREFIX = @BIN_PREFIX@ EXCEPTIONS_A = @EXCEPTIONS_A@ EXCEPTIONS_EXCEPTIONS_A = @EXCEPTIONS_EXCEPTIONS_A@ |
︙ | ︙ |
Modified src/OFObject.h from [131792314e] to [502b05ce3f].
︙ | ︙ | |||
372 373 374 375 376 377 378 | * * This is mostly for debugging purposes. * * \return A description for the class, which is usually the class name */ + (OFString*)description; | < < < < < < < < < < < < < < < < < < < < < | | | | > | < | > | < | | | | > | < | > | < | 372 373 374 375 376 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 402 403 404 405 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 | * * This is mostly for debugging purposes. * * \return A description for the class, which is usually the class name */ + (OFString*)description; /** * \brief Replaces a class method with a class method from another class. * * \param selector The selector of the class method to replace * \param class_ The class from which the new class method should be taken * \return The old implementation */ + (IMP)replaceClassMethod: (SEL)selector withMethodFromClass: (Class)class_; /** * \brief Replaces an instance method with an instance method from another * class. * * \param selector The selector of the instance method to replace * \param class_ The class from which the new instance method should be taken * \return The old implementation */ + (IMP)replaceInstanceMethod: (SEL)selector withMethodFromClass: (Class)class_; /** * \brief Replaces or adds a class method. * * If the method already exists, it is replaced and the old implementation * returned. If the method does not exist, it is added with the specified type * encoding. * * \param selector The selector for the new method * \param implementation The implementation for the new method * \param typeEncoding The type encoding for the new method * \return The old implementation or nil if the method was added */ + (IMP)replaceClassMethod: (SEL)selector withImplementation: (IMP)implementation typeEncoding: (const char*)typeEncoding; /** * \brief Replaces or adds an instance method. * * If the method already exists, it is replaced and the old implementation * returned. If the method does not exist, it is added with the specified type * encoding. * * \param selector The selector for the new method * \param implementation The implementation for the new method * \param typeEncoding The type encoding for the new method * \return The old implementation or nil if the method was added */ + (IMP)replaceInstanceMethod: (SEL)selector withImplementation: (IMP)implementation typeEncoding: (const char*)typeEncoding; /** * \brief Adds all methods from the specified class to the class that is the * receiver. * * Methods implemented by the receiving class itself will not be overridden, * however methods implemented by its superclass will. Therefore it behaves |
︙ | ︙ |
Modified src/OFObject.m from [fc6752589f] to [836c79ac97].
︙ | ︙ | |||
363 364 365 366 367 368 369 | } + (OFString*)description { return [self className]; } | < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < | < < < | < < | < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < | < | < < < < < < < < < < < | < | < < < > > | < > | > | < | > | | > > > > > > > > | > > | | > | < | | | | > > > > > > > > > | > > | | 363 364 365 366 367 368 369 370 371 372 373 374 375 376 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 402 403 404 405 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 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 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 | } + (OFString*)description { return [self className]; } + (IMP)replaceClassMethod: (SEL)selector withMethodFromClass: (Class)class { IMP newImp; const char *typeEncoding; newImp = [class methodForSelector: selector]; typeEncoding = [class typeEncodingForSelector: selector]; return [self replaceClassMethod: selector withImplementation: newImp typeEncoding: typeEncoding]; } + (IMP)replaceInstanceMethod: (SEL)selector withMethodFromClass: (Class)class { IMP newImp; const char *typeEncoding; newImp = [class instanceMethodForSelector: selector]; typeEncoding = [class typeEncodingForInstanceSelector: selector]; return [self replaceInstanceMethod: selector withImplementation: newImp typeEncoding: typeEncoding]; } + (IMP)replaceInstanceMethod: (SEL)selector withImplementation: (IMP)implementation typeEncoding: (const char*)typeEncoding { #if defined(OF_APPLE_RUNTIME) || defined(OF_GNU_RUNTIME) return class_replaceMethod(self, selector, implementation, typeEncoding); #elif defined(OF_OLD_GNU_RUNTIME) MethodList_t methodList; for (methodList = ((Class)self)->methods; methodList != NULL; methodList = methodList->method_next) { int i; for (i = 0; i < methodList->method_count; i++) { if (sel_eq(methodList->method_list[i].method_name, selector)) { IMP oldImp; oldImp = methodList->method_list[i].method_imp; methodList->method_list[i].method_imp = implementation; __objc_update_dispatch_table_for_class(self); return oldImp; } } } if ((methodList = malloc(sizeof(*methodList))) == NULL) @throw [OFOutOfMemoryException exceptionWithClass: self requestedSize: sizeof(*methodList)]; methodList->method_next = ((Class)self)->methods; methodList->method_count = 1; methodList->method_list[0].method_name = selector; methodList->method_list[0].method_types = typeEncoding; methodList->method_list[0].method_imp = implementation; ((Class)self)->methods = methodList; __objc_update_dispatch_table_for_class(self); return (IMP)nil; #else @throw [OFNotImplementedException exceptionWithClass: self selector: _cmd]; #endif } + (IMP)replaceClassMethod: (SEL)selector withImplementation: (IMP)implementation typeEncoding: (const char*)typeEncoding { #if defined(OF_APPLE_RUNTIME) || defined(OF_GNU_RUNTIME) return class_replaceMethod(((OFObject*)self)->isa, selector, implementation, typeEncoding); #elif defined(OF_OLD_GNU_RUNTIME) MethodList_t methodList; for (methodList = ((Class)self->class_pointer)->methods; methodList != NULL; methodList = methodList->method_next) { int i; for (i = 0; i < methodList->method_count; i++) { if (sel_eq(methodList->method_list[i].method_name, selector)) { IMP oldImp; oldImp = methodList->method_list[i].method_imp; methodList->method_list[i].method_imp = implementation; __objc_update_dispatch_table_for_class( (Class)self->class_pointer); return oldImp; } } } if ((methodList = malloc(sizeof(*methodList))) == NULL) @throw [OFOutOfMemoryException exceptionWithClass: self requestedSize: sizeof(*methodList)]; methodList->method_next = ((Class)self->class_pointer)->methods; methodList->method_count = 1; methodList->method_list[0].method_name = selector; methodList->method_list[0].method_types = typeEncoding; methodList->method_list[0].method_imp = implementation; ((Class)self->class_pointer)->methods = methodList; __objc_update_dispatch_table_for_class((Class)self->class_pointer); return (IMP)nil; #else @throw [OFNotImplementedException exceptionWithClass: self selector: _cmd]; #endif } + (void)inheritMethodsFromClass: (Class)class |
︙ | ︙ | |||
608 609 610 611 612 613 614 | Method *methodList; unsigned i, count; methodList = class_copyMethodList(((OFObject*)class)->isa, &count); @try { for (i = 0; i < count; i++) { SEL selector = method_getName(methodList[i]); | < < < < < | < < < | < < < < < < < < < | < < < | < < < < < < < < | < < < | < < < < < < < < < | < < < | < < < | 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 | Method *methodList; unsigned i, count; methodList = class_copyMethodList(((OFObject*)class)->isa, &count); @try { for (i = 0; i < count; i++) { SEL selector = method_getName(methodList[i]); /* * Don't replace methods implemented in receiving class. */ if ([self methodForSelector: selector] != [superclass methodForSelector: selector]) continue; [self replaceClassMethod: selector withMethodFromClass: class]; } } @finally { free(methodList); } methodList = class_copyMethodList(class, &count); @try { for (i = 0; i < count; i++) { SEL selector = method_getName(methodList[i]); /* * Don't replace methods implemented in receiving class. */ if ([self instanceMethodForSelector: selector] != [superclass instanceMethodForSelector: selector]) continue; [self replaceInstanceMethod: selector withMethodFromClass: class]; } } @finally { free(methodList); } #elif defined(OF_OLD_GNU_RUNTIME) MethodList_t methodList; for (methodList = class->class_pointer->methods; methodList != NULL; methodList = methodList->method_next) { int i; for (i = 0; i < methodList->method_count; i++) { SEL selector = methodList->method_list[i].method_name; /* * Don't replace methods implemented in receiving class. */ if ([self methodForSelector: selector] != [superclass methodForSelector: selector]) continue; [self replaceClassMethod: selector withMethodFromClass: class]; } } for (methodList = class->methods; methodList != NULL; methodList = methodList->method_next) { int i; for (i = 0; i < methodList->method_count; i++) { SEL selector = methodList->method_list[i].method_name; /* * Don't replace methods implemented in receiving class. */ if ([self instanceMethodForSelector: selector] != [superclass instanceMethodForSelector: selector]) continue; [self replaceInstanceMethod: selector withMethodFromClass: class]; } } #else @throw [OFNotImplementedException exceptionWithClass: self selector: _cmd]; #endif |
︙ | ︙ |