Ticket #212: count_eh.patch
File count_eh.patch, 6.0 KB (added by rg, 13 years ago) |
---|
-
src/scheduler.c
559 559 560 560 /* 561 561 562 =item C<void Parrot_cx_count_handlers_local> 563 564 Count the number of active handlers of a particular type from the 565 context's list of handlers. 566 567 =cut 568 569 */ 570 571 PARROT_EXPORT 572 INTVAL 573 Parrot_cx_count_handlers_local(PARROT_INTERP, ARGIN(STRING *handler_type)) 574 { 575 ASSERT_ARGS(Parrot_cx_count_handlers_local) 576 PMC *handlers = CONTEXT(interp)->handlers; 577 INTVAL elements; 578 579 if (PMC_IS_NULL(handlers)) 580 return 0; 581 582 elements = VTABLE_elements(interp, handlers); 583 584 if (STRING_IS_NULL(handler_type) || STRING_IS_EMPTY(handler_type)) 585 return elements; 586 587 /* Loop from newest handler to oldest handler. */ 588 { 589 STRING *exception_str = CONST_STRING(interp, "exception"); 590 STRING *event_str = CONST_STRING(interp, "event"); 591 STRING *handler_str = CONST_STRING(interp, "ExceptionHandler"); 592 INTVAL count = 0; 593 INTVAL index; 594 typedef enum { Hunknown, Hexception, Hevent } Htype; 595 596 const Htype htype = 597 (string_equal(interp, handler_type, exception_str) == 0) ? 598 Hexception : 599 (string_equal(interp, handler_type, event_str) == 0) ? 600 Hevent : 601 Hunknown; 602 STRING * const handler_name = (htype == Hexception) ? 603 handler_str : (STRING *) NULL; 604 605 for (index = 0; index < elements; ++index) { 606 PMC *handler = VTABLE_get_pmc_keyed_int(interp, handlers, index); 607 if (!PMC_IS_NULL(handler)) { 608 switch (htype) { 609 case Hexception: 610 if (VTABLE_isa(interp, handler, handler_name)) 611 count++; 612 break; 613 case Hevent: 614 if (handler->vtable->base_type == enum_class_EventHandler) 615 count++; 616 break; 617 default: 618 break; 619 } 620 } 621 } 622 return count; 623 } 624 } 625 626 627 /* 628 562 629 =item C<void Parrot_cx_add_handler> 563 630 564 631 Add a task handler to scheduler's list of handlers. … … 625 692 Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION, 626 693 "Scheduler was not initialized for this interpreter.\n"); 627 694 628 Parrot_PCCINVOKE(interp, interp->scheduler, CONST_STRING(interp, "count_handlers"), "S->I", handler_type, count);695 Parrot_PCCINVOKE(interp, interp->scheduler, CONST_STRING(interp, "count_handlers"), "S->I", handler_type, &count); 629 696 630 697 return count; 631 698 } -
src/ops/core.ops
866 866 } 867 867 868 868 inline op count_eh(out INT) { 869 $1 = Parrot_cx_count_handlers_ typed(interp,869 $1 = Parrot_cx_count_handlers_local(interp, 870 870 string_from_cstring(interp, "exception", 9)); 871 871 } 872 872 -
src/pmc/scheduler.pmc
513 513 METHOD count_handlers(STRING *type :optional, INTVAL have_type :opt_flag) { 514 514 /* avoid uninitialized value warning */ 515 515 PMC *handlers = NULL; 516 INTVAL elements = VTABLE_elements(INTERP, handlers);516 INTVAL elements; 517 517 INTVAL count = 0; 518 518 INTVAL index; 519 519 520 520 GET_ATTR_handlers(INTERP, SELF, handlers); 521 elements = VTABLE_elements(INTERP, handlers); 521 522 522 523 if (!have_type) 523 524 RETURN(INTVAL elements); -
include/parrot/scheduler.h
36 36 __attribute__nonnull__(2); 37 37 38 38 PARROT_EXPORT 39 INTVAL Parrot_cx_count_handlers_local(PARROT_INTERP, 40 ARGIN(STRING *handler_type)) 41 __attribute__nonnull__(1) 42 __attribute__nonnull__(2); 43 44 PARROT_EXPORT 39 45 INTVAL Parrot_cx_count_handlers_typed(PARROT_INTERP, 40 46 ARGIN(STRING *handler_type)) 41 47 __attribute__nonnull__(1) … … 171 177 #define ASSERT_ARGS_Parrot_cx_broadcast_message __attribute__unused__ int _ASSERT_ARGS_CHECK = \ 172 178 PARROT_ASSERT_ARG(interp) \ 173 179 || PARROT_ASSERT_ARG(messagetype) 180 #define ASSERT_ARGS_Parrot_cx_count_handlers_local \ 181 __attribute__unused__ int _ASSERT_ARGS_CHECK = \ 182 PARROT_ASSERT_ARG(interp) \ 183 || PARROT_ASSERT_ARG(handler_type) 174 184 #define ASSERT_ARGS_Parrot_cx_count_handlers_typed \ 175 185 __attribute__unused__ int _ASSERT_ARGS_CHECK = \ 176 186 PARROT_ASSERT_ARG(interp) \ -
t/pmc/exception.t
6 6 use warnings; 7 7 use lib qw( . lib ../lib ../../lib ); 8 8 use Test::More; 9 use Parrot::Test tests => 3 0;9 use Parrot::Test tests => 31; 10 10 11 11 =head1 NAME 12 12 … … 715 715 no segfault 716 716 OUTPUT 717 717 718 pir_output_is( <<'CODE', <<'OUTPUT', "count_eh" ); 719 .sub main :main 720 $I0 = count_eh 721 if $I0 == 0 goto right_number1 722 print "not " 723 right_number1: 724 print "ok 1\n" 725 push_eh _handler1 726 push_eh _handler2 727 print "ok 2\n" 728 $I1 = count_eh 729 if $I1 == 2 goto right_number2 730 print "not " 731 right_number2: 732 print "ok 3\n" 733 pop_eh 734 pop_eh 735 print "ok 4\n" 736 $I2 = count_eh 737 if $I2 == 0 goto right_number3 738 print "not " 739 right_number3: 740 print "ok 5\n" 741 end 742 _handler1: 743 print "first handler\n" 744 end 745 _handler2: 746 print "second handler\n" 747 end 748 .end 749 CODE 750 ok 1 751 ok 2 752 ok 3 753 ok 4 754 ok 5 755 OUTPUT 756 718 757 # Local Variables: 719 758 # mode: cperl 720 759 # cperl-indent-level: 4