@@ -611,6 +611,73 @@ static ZEND_METHOD(ZendTestForbidDynamicCall, callStatic)
611
611
zend_forbid_dynamic_call ();
612
612
}
613
613
614
+ // TODO HERE
615
+ /* ncm refers to non commutative multiplication */
616
+ static zend_class_entry * ncm_ce ;
617
+ static zend_object_handlers ncm_object_handlers ;
618
+
619
+ static zend_object * ncm_object_create_ex (zend_class_entry * ce , zend_long l ) {
620
+ zend_object * obj = zend_objects_new (ce );
621
+ object_properties_init (obj , ce );
622
+ obj -> handlers = & ncm_object_handlers ;
623
+ ZVAL_LONG (OBJ_PROP_NUM (obj , 0 ), l );
624
+ return obj ;
625
+ }
626
+ static zend_object * ncm_object_create (zend_class_entry * ce ) /* {{{ */
627
+ {
628
+ return ncm_object_create_ex (ce , 0 );
629
+ }
630
+ /* }}} */
631
+
632
+ static inline void ncm_create (zval * target , zend_long l ) /* {{{ */
633
+ {
634
+ ZVAL_OBJ (target , ncm_object_create_ex (ncm_ce , l ));
635
+ }
636
+
637
+ #define IS_NCM (zval ) \
638
+ (Z_TYPE_P(zval) == IS_OBJECT && instanceof_function(Z_OBJCE_P(zval), ncm_ce))
639
+
640
+ static void ncm_subtraction (zval * result , zval * op1 , zval * op2 )
641
+ {
642
+ zend_long val_1 ;
643
+ zend_long val_2 ;
644
+ if (IS_NCM (op1 )) {
645
+ val_1 = Z_LVAL_P (OBJ_PROP_NUM (Z_OBJ_P (op1 ), 0 ));
646
+ } else {
647
+ val_1 = zval_get_long (op1 );
648
+ }
649
+ if (IS_NCM (op2 )) {
650
+ val_2 = Z_LVAL_P (OBJ_PROP_NUM (Z_OBJ_P (op2 ), 0 ));
651
+ } else {
652
+ val_2 = zval_get_long (op2 );
653
+ }
654
+
655
+ ncm_create (result , val_1 - val_2 );
656
+ }
657
+
658
+ static zend_result ncm_do_operation (zend_uchar opcode , zval * result , zval * op1 , zval * op2 )
659
+ {
660
+ switch (opcode ) {
661
+ case ZEND_MUL :
662
+ ncm_subtraction (result , op1 , op2 );
663
+ if (UNEXPECTED (EG (exception ))) { return FAILURE ; }
664
+ return SUCCESS ;
665
+ default :
666
+ return FAILURE ;
667
+ }
668
+ }
669
+
670
+ PHP_METHOD (NonCommutativeMultiplication , __construct )
671
+ {
672
+ zend_long l ;
673
+
674
+ ZEND_PARSE_PARAMETERS_START (1 , 1 )
675
+ Z_PARAM_LONG (l )
676
+ ZEND_PARSE_PARAMETERS_END ();
677
+
678
+ ZVAL_LONG (OBJ_PROP_NUM (Z_OBJ_P (ZEND_THIS ), 0 ), l );
679
+ }
680
+
614
681
PHP_INI_BEGIN ()
615
682
STD_PHP_INI_BOOLEAN ("zend_test.replace_zend_execute_ex" , "0" , PHP_INI_SYSTEM , OnUpdateBool , replace_zend_execute_ex , zend_zend_test_globals , zend_test_globals )
616
683
STD_PHP_INI_BOOLEAN ("zend_test.register_passes" , "0" , PHP_INI_SYSTEM , OnUpdateBool , register_passes , zend_zend_test_globals , zend_test_globals )
@@ -713,6 +780,12 @@ PHP_MINIT_FUNCTION(zend_test)
713
780
zend_test_string_enum = register_class_ZendTestStringEnum ();
714
781
zend_test_int_enum = register_class_ZendTestIntEnum ();
715
782
783
+ /* Non commutative multiplication class */
784
+ ncm_ce = register_class_NonCommutativeMultiplication ();
785
+ ncm_ce -> create_object = ncm_object_create ;
786
+ memcpy (& ncm_object_handlers , & std_object_handlers , sizeof (zend_object_handlers ));
787
+ ncm_object_handlers .do_operation = ncm_do_operation ;
788
+
716
789
zend_register_functions (NULL , ext_function_legacy , NULL , EG (current_module )-> type );
717
790
718
791
// Loading via dl() not supported with the observer API
0 commit comments