Skip to content
This repository
7 include/parrot/misc.h
@@ -101,10 +101,12 @@ INTVAL Parrot_util_intval_mod(INTVAL i2, INTVAL i3);
101 101 void Parrot_util_quicksort(PARROT_INTERP,
102 102 ARGMOD(void **data),
103 103 UINTVAL n,
104   - ARGIN(PMC *cmp))
  104 + ARGIN(PMC *cmp),
  105 + ARGIN(const char * cmp_signature))
105 106 __attribute__nonnull__(1)
106 107 __attribute__nonnull__(2)
107 108 __attribute__nonnull__(4)
  109 + __attribute__nonnull__(5)
108 110 FUNC_MODIFIES(*data);
109 111
110 112 #define ASSERT_ARGS_Parrot_util_byte_index __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
@@ -131,7 +133,8 @@ void Parrot_util_quicksort(PARROT_INTERP,
131 133 #define ASSERT_ARGS_Parrot_util_quicksort __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
132 134 PARROT_ASSERT_ARG(interp) \
133 135 , PARROT_ASSERT_ARG(data) \
134   - , PARROT_ASSERT_ARG(cmp))
  136 + , PARROT_ASSERT_ARG(cmp) \
  137 + , PARROT_ASSERT_ARG(cmp_signature))
135 138 /* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */
136 139 /* HEADERIZER END: src/utils.c */
137 140
2  src/pmc/fixedintegerarray.pmc
@@ -631,7 +631,7 @@ Sort the array and return self.
631 631 qsort(int_array, n, sizeof (INTVAL),
632 632 (int (*)(const void *, const void*))auxcmpfunc);
633 633 else
634   - Parrot_util_quicksort(INTERP, (void**)int_array, n, cmp_func);
  634 + Parrot_util_quicksort(INTERP, (void**)int_array, n, cmp_func, "II->I");
635 635 }
636 636 RETURN(PMC *SELF);
637 637 }
2  src/pmc/fixedpmcarray.pmc
@@ -54,7 +54,7 @@ Sort this array, optionally using the provided cmp_func
54 54 Parrot_pcc_invoke_method_from_c_args(INTERP, parent, CONST_STRING(INTERP, "sort"), "P->", cmp_func);
55 55 }
56 56 else
57   - Parrot_util_quicksort(INTERP, (void **)PMC_array(SELF), n, cmp_func);
  57 + Parrot_util_quicksort(INTERP, (void **)PMC_array(SELF), n, cmp_func, "PP->I");
58 58 }
59 59 RETURN(PMC *SELF);
60 60 }
33 src/utils.c
@@ -53,11 +53,13 @@ static void _srand48(long seed);
53 53 static INTVAL COMPARE(PARROT_INTERP,
54 54 ARGIN(void *a),
55 55 ARGIN(void *b),
56   - ARGIN(PMC *cmp))
  56 + ARGIN(PMC *cmp),
  57 + ARGIN(const char * cmp_signature))
57 58 __attribute__nonnull__(1)
58 59 __attribute__nonnull__(2)
59 60 __attribute__nonnull__(3)
60   - __attribute__nonnull__(4);
  61 + __attribute__nonnull__(4)
  62 + __attribute__nonnull__(5);
61 63
62 64 static void next_rand(_rand_buf X);
63 65 static void process_cycle_without_exit(
@@ -81,7 +83,8 @@ static void rec_climb_back_and_mark(
81 83 PARROT_ASSERT_ARG(interp) \
82 84 , PARROT_ASSERT_ARG(a) \
83 85 , PARROT_ASSERT_ARG(b) \
84   - , PARROT_ASSERT_ARG(cmp))
  86 + , PARROT_ASSERT_ARG(cmp) \
  87 + , PARROT_ASSERT_ARG(cmp_signature))
85 88 #define ASSERT_ARGS_next_rand __attribute__unused__ int _ASSERT_ARGS_CHECK = (0)
86 89 #define ASSERT_ARGS_process_cycle_without_exit __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
87 90 PARROT_ASSERT_ARG(c))
@@ -905,7 +908,8 @@ typedef INTVAL (*sort_func_t)(PARROT_INTERP, void *, void *);
905 908
906 909 /*
907 910
908   -=item C<static INTVAL COMPARE(PARROT_INTERP, void *a, void *b, PMC *cmp)>
  911 +=item C<static INTVAL COMPARE(PARROT_INTERP, void *a, void *b, PMC *cmp, const
  912 +char * cmp_signature)>
909 913
910 914 General PMC comparison function. Takes two PMCs. Returns 0 if they are equal,
911 915 returns 1 if C<a> is bigger, and returns -1 if C<b> is bigger.
@@ -919,7 +923,9 @@ returns 1 if C<a> is bigger, and returns -1 if C<b> is bigger.
919 923 /* comparisons that never change. We ought to precompute everything. */
920 924 /* XXX We should be able to guarantee that *a and *b never change via const parameters. */
921 925 static INTVAL
922   -COMPARE(PARROT_INTERP, ARGIN(void *a), ARGIN(void *b), ARGIN(PMC *cmp))
  926 +COMPARE(PARROT_INTERP, ARGIN(void *a), ARGIN(void *b),
  927 + ARGIN(PMC *cmp),
  928 + ARGIN(const char * cmp_signature))
923 929 {
924 930 ASSERT_ARGS(COMPARE)
925 931 INTVAL result = 0;
@@ -931,23 +937,26 @@ COMPARE(PARROT_INTERP, ARGIN(void *a), ARGIN(void *b), ARGIN(PMC *cmp))
931 937 return f(interp, a, b);
932 938 }
933 939
934   - Parrot_ext_call(interp, cmp, "PP->I", a, b, &result);
  940 + Parrot_ext_call(interp, cmp, cmp_signature, a, b, &result);
935 941 return result;
936 942 }
937 943
938 944 /*
939 945
940 946 =item C<void Parrot_util_quicksort(PARROT_INTERP, void **data, UINTVAL n, PMC
941   -*cmp)>
  947 +*cmp, const char * cmp_signature)>
942 948
943 949 Perform a quicksort on a PMC array.
944 950
  951 +cmp_signature is PCC signature for C<cmp>. E.g. C<II->I> for FIA.
945 952 =cut
946 953
947 954 */
948 955
949 956 void
950   -Parrot_util_quicksort(PARROT_INTERP, ARGMOD(void **data), UINTVAL n, ARGIN(PMC *cmp))
  957 +Parrot_util_quicksort(PARROT_INTERP, ARGMOD(void **data), UINTVAL n,
  958 + ARGIN(PMC *cmp),
  959 + ARGIN(const char * cmp_signature))
951 960 {
952 961 ASSERT_ARGS(Parrot_util_quicksort)
953 962 while (n > 1) {
@@ -962,11 +971,11 @@ Parrot_util_quicksort(PARROT_INTERP, ARGMOD(void **data), UINTVAL n, ARGIN(PMC *
962 971 for (i = 0, j = n; ;) {
963 972 do
964 973 --j;
965   - while (j > 0 && COMPARE(interp, data[j], data[0], cmp) > 0);
  974 + while (j > 0 && COMPARE(interp, data[j], data[0], cmp, cmp_signature) > 0);
966 975
967 976 do
968 977 ++i;
969   - while (i < j && COMPARE(interp, data[i], data[0], cmp) < 0);
  978 + while (i < j && COMPARE(interp, data[i], data[0], cmp, cmp_signature) < 0);
970 979
971 980 if (i >= j)
972 981 break;
@@ -986,12 +995,12 @@ Parrot_util_quicksort(PARROT_INTERP, ARGMOD(void **data), UINTVAL n, ARGIN(PMC *
986 995 rn = n - ++j;
987 996
988 997 if (ln < rn) {
989   - Parrot_util_quicksort(interp, data, ln, cmp);
  998 + Parrot_util_quicksort(interp, data, ln, cmp, cmp_signature);
990 999 data += j;
991 1000 n = rn;
992 1001 }
993 1002 else {
994   - Parrot_util_quicksort(interp, data + j, rn, cmp);
  1003 + Parrot_util_quicksort(interp, data + j, rn, cmp, cmp_signature);
995 1004 n = ln;
996 1005 }
997 1006 }

0 comments on commit 4379aa4

Please sign in to comment.
Something went wrong with that request. Please try again.