New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
unstable sorting for use integer; sort { $b <=> $a } @foo #7982
Comments
From @salvaCreated by @salvasorting a list of numbers as integers (via 'use integer') in $ perl use sort stable; sub pa { print join(", ", @_), "\n"} __END__ 2.7, 1.7, 1, 4.8, 4.3, 0.8 Cheers, - Salvador. Perl Info
|
From @salvaI have found it is not only affecting integer sorts: $ perl use sort stable; @a=map{(int rand 5).(q(#), q(@))[rand 2]} 0..5; sub pa { print join(", ", @_), "\n"} __END__ 2#, 2@, 1#, 3@, 3#, 1@ |
@salva - Status changed from 'new' to 'open' |
From @salvaperlbug-followup@perl.org wrote:
I have not been able to reproduce the bug on any perl compiled by result = (v = foo(), bar(v)); The patch attached breaks the macro in two: dSORTHINTS and SORTHINTS, Cheers, - Salvador. |
From @salvasorthints-0.patch--- pp_sort.c~ 2005-06-20 12:16:05.000000000 +0200
+++ pp_sort.c 2005-06-21 18:09:04.000000000 +0200
@@ -46,9 +46,8 @@
#define sv_cmp_static Perl_sv_cmp
#define sv_cmp_locale_static Perl_sv_cmp_locale
-#define SORTHINTS(hintsv) \
- (((hintsv) = GvSV(gv_fetchpv("sort::hints", GV_ADDMULTI, SVt_IV))), \
- (SvIOK(hintsv) ? ((I32)SvIV(hintsv)) : 0))
+#define dSORTHINTS SV *hintsv = GvSV(gv_fetchpv("sort::hints", GV_ADDMULTI, SVt_IV))
+#define SORTHINTS (SvIOK(hintsv) ? ((I32)SvIV(hintsv)) : 0)
#ifndef SMALLSORT
#define SMALLSORT (200)
@@ -1347,9 +1346,10 @@
STATIC void
S_qsortsv(pTHX_ gptr *list1, size_t nmemb, SVCOMPARE_t cmp, U32 flags)
{
- SV *hintsv;
- if (SORTHINTS(hintsv) & HINT_SORT_STABLE) {
+ dSORTHINTS;
+
+ if (SORTHINTS & HINT_SORT_STABLE) {
register gptr **pp, *q;
register size_t n, j, i;
gptr *small[SMALLSORT], **indir, tmp;
@@ -1442,14 +1442,8 @@
{
void (*sortsvp)(pTHX_ SV **array, size_t nmemb, SVCOMPARE_t cmp, U32 flags)
= S_mergesortsv;
- SV *hintsv;
-
- /* Sun's Compiler (cc: WorkShop Compilers 4.2 30 Oct 1996 C 4.2) used
- to miscompile this function under optimization -O. If you get test
- errors related to picking the correct sort() function, try recompiling
- this file without optimiziation. -- A.D. 4/2002.
- */
- const I32 hints = SORTHINTS(hintsv);
+ dSORTHINTS;
+ const I32 hints = SORTHINTS;
if (hints & HINT_SORT_QUICKSORT) {
sortsvp = S_qsortsv;
}
@@ -1467,14 +1461,8 @@
{
void (*sortsvp)(pTHX_ SV **array, size_t nmemb, SVCOMPARE_t cmp, U32 flags)
= S_mergesortsv;
- SV *hintsv;
-
- /* Sun's Compiler (cc: WorkShop Compilers 4.2 30 Oct 1996 C 4.2) used
- to miscompile this function under optimization -O. If you get test
- errors related to picking the correct sort() function, try recompiling
- this file without optimiziation. -- A.D. 4/2002.
- */
- const I32 hints = SORTHINTS(hintsv);
+ dSORTHINTS;
+ const I32 hints = SORTHINTS;
if (hints & HINT_SORT_QUICKSORT) {
sortsvp = S_qsortsv;
}
|
From @pjcjOn Tue, Jun 21, 2005 at 07:50:35PM +0200, Salvador Fandino wrote:
I think the evaulation order here is quite well defined but, of course,
So yes, hopefully this is fixed too but it would be interesting to hear -- |
From @doughera88On Wed, 22 Jun 2005, Paul Johnson wrote:
That'd be me. What, precisely, would you like me to test? I haven't had -- |
From @doughera88On Wed, 22 Jun 2005, Andy Dougherty wrote:
Ok, I've looked at the RT ticket now. Yes, this patch works fine for me My original problem also had to do with embedding SORTINTS(hintsv) inside I32 hints = SORTHINTS(hintsv); This patch looks similar in spirit to me and is probably fine. -- |
@rgs - Status changed from 'open' to 'resolved' |
From @rgsSalvador Fandino wrote:
Thanks, applied as change #24951. |
Migrated from rt.perl.org#36350 (status was 'resolved')
Searchable as RT36350$
The text was updated successfully, but these errors were encountered: