File tree Expand file tree Collapse file tree 1 file changed +4
-3
lines changed Expand file tree Collapse file tree 1 file changed +4
-3
lines changed Original file line number Diff line number Diff line change @@ -5570,7 +5570,7 @@ PHPAPI int php_multisort_compare(const void *a, const void *b) /* {{{ */
5570
5570
r ++ ;
5571
5571
} while (Z_TYPE (ab [r ].val ) != IS_UNDEF );
5572
5572
5573
- return 0 ;
5573
+ return stable_sort_fallback ( & ab [ r ], & bb [ r ]) ;
5574
5574
}
5575
5575
/* }}} */
5576
5576
@@ -5707,8 +5707,8 @@ PHP_FUNCTION(array_multisort)
5707
5707
5708
5708
/* Create the indirection array. This array is of size MxN, where
5709
5709
* M is the number of entries in each input array and N is the number
5710
- * of the input arrays + 1. The last column is NULL to indicate the end
5711
- * of the row. */
5710
+ * of the input arrays + 1. The last column is UNDEF to indicate the end
5711
+ * of the row. It also stores the original position for stable sorting. */
5712
5712
indirect = (Bucket * * )safe_emalloc (array_size , sizeof (Bucket * ), 0 );
5713
5713
for (i = 0 ; i < array_size ; i ++ ) {
5714
5714
indirect [i ] = (Bucket * )safe_emalloc ((num_arrays + 1 ), sizeof (Bucket ), 0 );
@@ -5724,6 +5724,7 @@ PHP_FUNCTION(array_multisort)
5724
5724
}
5725
5725
for (k = 0 ; k < array_size ; k ++ ) {
5726
5726
ZVAL_UNDEF (& indirect [k ][num_arrays ].val );
5727
+ Z_EXTRA_P (& indirect [k ][num_arrays ].val ) = k ;
5727
5728
}
5728
5729
5729
5730
/* Do the actual sort magic - bada-bim, bada-boom. */
You can’t perform that action at this time.
0 commit comments