comparison src/fns.c @ 647:b39c14581166

[xemacs-hg @ 2001-08-13 04:45:47 by ben] removal of unsigned, size_t, etc.
author ben
date Mon, 13 Aug 2001 04:46:48 +0000
parents 190b164ddcac
children fdefd0186b75
comparison
equal deleted inserted replaced
646:00c54252fe4f 647:b39c14581166
67 } 67 }
68 68
69 static void 69 static void
70 print_bit_vector (Lisp_Object obj, Lisp_Object printcharfun, int escapeflag) 70 print_bit_vector (Lisp_Object obj, Lisp_Object printcharfun, int escapeflag)
71 { 71 {
72 size_t i; 72 Element_Count i;
73 Lisp_Bit_Vector *v = XBIT_VECTOR (obj); 73 Lisp_Bit_Vector *v = XBIT_VECTOR (obj);
74 size_t len = bit_vector_length (v); 74 Element_Count len = bit_vector_length (v);
75 size_t last = len; 75 Element_Count last = len;
76 76
77 if (INTP (Vprint_length)) 77 if (INTP (Vprint_length))
78 last = min (len, XINT (Vprint_length)); 78 last = min (len, XINT (Vprint_length));
79 write_c_string ("#*", printcharfun); 79 write_c_string ("#*", printcharfun);
80 for (i = 0; i < last; i++) 80 for (i = 0; i < last; i++)
99 !memcmp (v1->bits, v2->bits, 99 !memcmp (v1->bits, v2->bits,
100 BIT_VECTOR_LONG_STORAGE (bit_vector_length (v1)) * 100 BIT_VECTOR_LONG_STORAGE (bit_vector_length (v1)) *
101 sizeof (long))); 101 sizeof (long)));
102 } 102 }
103 103
104 static unsigned long 104 static Hash_Code
105 bit_vector_hash (Lisp_Object obj, int depth) 105 bit_vector_hash (Lisp_Object obj, int depth)
106 { 106 {
107 Lisp_Bit_Vector *v = XBIT_VECTOR (obj); 107 Lisp_Bit_Vector *v = XBIT_VECTOR (obj);
108 return HASH2 (bit_vector_length (v), 108 return HASH2 (bit_vector_length (v),
109 memory_hash (v->bits, 109 memory_hash (v->bits,
110 BIT_VECTOR_LONG_STORAGE (bit_vector_length (v)) * 110 BIT_VECTOR_LONG_STORAGE (bit_vector_length (v)) *
111 sizeof (long))); 111 sizeof (long)));
112 } 112 }
113 113
114 static size_t 114 static Memory_Count
115 size_bit_vector (const void *lheader) 115 size_bit_vector (const void *lheader)
116 { 116 {
117 Lisp_Bit_Vector *v = (Lisp_Bit_Vector *) lheader; 117 Lisp_Bit_Vector *v = (Lisp_Bit_Vector *) lheader;
118 return FLEXIBLE_ARRAY_STRUCT_SIZEOF (Lisp_Bit_Vector, unsigned long, bits, 118 return FLEXIBLE_ARRAY_STRUCT_SIZEOF (Lisp_Bit_Vector, unsigned long, bits,
119 BIT_VECTOR_LONG_STORAGE (bit_vector_length (v))); 119 BIT_VECTOR_LONG_STORAGE (bit_vector_length (v)));
221 retry: 221 retry:
222 if (STRINGP (sequence)) 222 if (STRINGP (sequence))
223 return make_int (XSTRING_CHAR_LENGTH (sequence)); 223 return make_int (XSTRING_CHAR_LENGTH (sequence));
224 else if (CONSP (sequence)) 224 else if (CONSP (sequence))
225 { 225 {
226 size_t len; 226 Element_Count len;
227 GET_EXTERNAL_LIST_LENGTH (sequence, len); 227 GET_EXTERNAL_LIST_LENGTH (sequence, len);
228 return make_int (len); 228 return make_int (len);
229 } 229 }
230 else if (VECTORP (sequence)) 230 else if (VECTORP (sequence))
231 return make_int (XVECTOR_LENGTH (sequence)); 231 return make_int (XVECTOR_LENGTH (sequence));
248 which is at least the number of distinct elements. 248 which is at least the number of distinct elements.
249 */ 249 */
250 (list)) 250 (list))
251 { 251 {
252 Lisp_Object hare, tortoise; 252 Lisp_Object hare, tortoise;
253 size_t len; 253 Element_Count len;
254 254
255 for (hare = tortoise = list, len = 0; 255 for (hare = tortoise = list, len = 0;
256 CONSP (hare) && (! EQ (hare, tortoise) || len == 0); 256 CONSP (hare) && (! EQ (hare, tortoise) || len == 0);
257 hare = XCDR (hare), len++) 257 hare = XCDR (hare), len++)
258 { 258 {
528 copy_list (Lisp_Object list) 528 copy_list (Lisp_Object list)
529 { 529 {
530 Lisp_Object list_copy = Fcons (XCAR (list), XCDR (list)); 530 Lisp_Object list_copy = Fcons (XCAR (list), XCDR (list));
531 Lisp_Object last = list_copy; 531 Lisp_Object last = list_copy;
532 Lisp_Object hare, tortoise; 532 Lisp_Object hare, tortoise;
533 size_t len; 533 Element_Count len;
534 534
535 for (tortoise = hare = XCDR (list), len = 1; 535 for (tortoise = hare = XCDR (list), len = 1;
536 CONSP (hare); 536 CONSP (hare);
537 hare = XCDR (hare), len++) 537 hare = XCDR (hare), len++)
538 { 538 {
1013 DEFUN ("nthcdr", Fnthcdr, 2, 2, 0, /* 1013 DEFUN ("nthcdr", Fnthcdr, 2, 2, 0, /*
1014 Take cdr N times on LIST, and return the result. 1014 Take cdr N times on LIST, and return the result.
1015 */ 1015 */
1016 (n, list)) 1016 (n, list))
1017 { 1017 {
1018 REGISTER size_t i; 1018 REGISTER EMACS_INT i;
1019 REGISTER Lisp_Object tail = list; 1019 REGISTER Lisp_Object tail = list;
1020 CHECK_NATNUM (n); 1020 CHECK_NATNUM (n);
1021 for (i = XINT (n); i; i--) 1021 for (i = XINT (n); i; i--)
1022 { 1022 {
1023 if (CONSP (tail)) 1023 if (CONSP (tail))
2749 bump_string_modiff (array); 2749 bump_string_modiff (array);
2750 } 2750 }
2751 else if (VECTORP (array)) 2751 else if (VECTORP (array))
2752 { 2752 {
2753 Lisp_Object *p = XVECTOR_DATA (array); 2753 Lisp_Object *p = XVECTOR_DATA (array);
2754 size_t len = XVECTOR_LENGTH (array); 2754 Element_Count len = XVECTOR_LENGTH (array);
2755 CHECK_LISP_WRITEABLE (array); 2755 CHECK_LISP_WRITEABLE (array);
2756 while (len--) 2756 while (len--)
2757 *p++ = item; 2757 *p++ = item;
2758 } 2758 }
2759 else if (BIT_VECTORP (array)) 2759 else if (BIT_VECTORP (array))
2760 { 2760 {
2761 Lisp_Bit_Vector *v = XBIT_VECTOR (array); 2761 Lisp_Bit_Vector *v = XBIT_VECTOR (array);
2762 size_t len = bit_vector_length (v); 2762 Element_Count len = bit_vector_length (v);
2763 int bit; 2763 int bit;
2764 CHECK_BIT (item); 2764 CHECK_BIT (item);
2765 bit = XINT (item); 2765 bit = XINT (item);
2766 CHECK_LISP_WRITEABLE (array); 2766 CHECK_LISP_WRITEABLE (array);
2767 while (len--) 2767 while (len--)
2796 2796
2797 if (CONSP (args[0])) 2797 if (CONSP (args[0]))
2798 { 2798 {
2799 /* (setcdr (last args[0]) args[1]) */ 2799 /* (setcdr (last args[0]) args[1]) */
2800 Lisp_Object tortoise, hare; 2800 Lisp_Object tortoise, hare;
2801 size_t count; 2801 Element_Count count;
2802 2802
2803 for (hare = tortoise = args[0], count = 0; 2803 for (hare = tortoise = args[0], count = 0;
2804 CONSP (XCDR (hare)); 2804 CONSP (XCDR (hare));
2805 hare = XCDR (hare), count++) 2805 hare = XCDR (hare), count++)
2806 { 2806 {
2865 Lisp_Object next = args[argnum]; 2865 Lisp_Object next = args[argnum];
2866 retry_next: 2866 retry_next:
2867 if (CONSP (next) || argnum == nargs -1) 2867 if (CONSP (next) || argnum == nargs -1)
2868 { 2868 {
2869 /* (setcdr (last val) next) */ 2869 /* (setcdr (last val) next) */
2870 size_t count; 2870 Element_Count count;
2871 2871
2872 for (count = 0; 2872 for (count = 0;
2873 CONSP (XCDR (last_cons)); 2873 CONSP (XCDR (last_cons));
2874 last_cons = XCDR (last_cons), count++) 2874 last_cons = XCDR (last_cons), count++)
2875 { 2875 {
2914 LENI is the length of VALS, which should also be the length of SEQUENCE. 2914 LENI is the length of VALS, which should also be the length of SEQUENCE.
2915 2915
2916 If VALS is a null pointer, do not accumulate the results. */ 2916 If VALS is a null pointer, do not accumulate the results. */
2917 2917
2918 static void 2918 static void
2919 mapcar1 (size_t leni, Lisp_Object *vals, 2919 mapcar1 (Element_Count leni, Lisp_Object *vals,
2920 Lisp_Object function, Lisp_Object sequence) 2920 Lisp_Object function, Lisp_Object sequence)
2921 { 2921 {
2922 Lisp_Object result; 2922 Lisp_Object result;
2923 Lisp_Object args[2]; 2923 Lisp_Object args[2];
2924 struct gcpro gcpro1; 2924 struct gcpro gcpro1;
2948 So we use EXTERNAL_LIST_LOOP_3_NO_DECLARE and GCPRO the tail. */ 2948 So we use EXTERNAL_LIST_LOOP_3_NO_DECLARE and GCPRO the tail. */
2949 2949
2950 if (vals) 2950 if (vals)
2951 { 2951 {
2952 Lisp_Object *val = vals; 2952 Lisp_Object *val = vals;
2953 size_t i; 2953 Element_Count i;
2954 2954
2955 LIST_LOOP_2 (elt, sequence) 2955 LIST_LOOP_2 (elt, sequence)
2956 *val++ = elt; 2956 *val++ = elt;
2957 2957
2958 gcpro1.nvars = leni; 2958 gcpro1.nvars = leni;
2983 } 2983 }
2984 } 2984 }
2985 else if (VECTORP (sequence)) 2985 else if (VECTORP (sequence))
2986 { 2986 {
2987 Lisp_Object *objs = XVECTOR_DATA (sequence); 2987 Lisp_Object *objs = XVECTOR_DATA (sequence);
2988 size_t i; 2988 Element_Count i;
2989 for (i = 0; i < leni; i++) 2989 for (i = 0; i < leni; i++)
2990 { 2990 {
2991 args[1] = *objs++; 2991 args[1] = *objs++;
2992 result = Ffuncall (2, args); 2992 result = Ffuncall (2, args);
2993 if (vals) vals[gcpro1.nvars++] = result; 2993 if (vals) vals[gcpro1.nvars++] = result;
3011 } 3011 }
3012 } 3012 }
3013 else if (BIT_VECTORP (sequence)) 3013 else if (BIT_VECTORP (sequence))
3014 { 3014 {
3015 Lisp_Bit_Vector *v = XBIT_VECTOR (sequence); 3015 Lisp_Bit_Vector *v = XBIT_VECTOR (sequence);
3016 size_t i; 3016 Element_Count i;
3017 for (i = 0; i < leni; i++) 3017 for (i = 0; i < leni; i++)
3018 { 3018 {
3019 args[1] = make_int (bit_vector_bit (v, i)); 3019 args[1] = make_int (bit_vector_bit (v, i));
3020 result = Ffuncall (2, args); 3020 result = Ffuncall (2, args);
3021 if (vals) vals[gcpro1.nvars++] = result; 3021 if (vals) vals[gcpro1.nvars++] = result;
3061 The result is a list of the same length as SEQUENCE. 3061 The result is a list of the same length as SEQUENCE.
3062 SEQUENCE may be a list, a vector, a bit vector, or a string. 3062 SEQUENCE may be a list, a vector, a bit vector, or a string.
3063 */ 3063 */
3064 (function, sequence)) 3064 (function, sequence))
3065 { 3065 {
3066 size_t len = XINT (Flength (sequence)); 3066 Element_Count len = XINT (Flength (sequence));
3067 Lisp_Object *args = alloca_array (Lisp_Object, len); 3067 Lisp_Object *args = alloca_array (Lisp_Object, len);
3068 3068
3069 mapcar1 (len, args, function, sequence); 3069 mapcar1 (len, args, function, sequence);
3070 3070
3071 return Flist (len, args); 3071 return Flist ((int) len, args);
3072 } 3072 }
3073 3073
3074 DEFUN ("mapvector", Fmapvector, 2, 2, 0, /* 3074 DEFUN ("mapvector", Fmapvector, 2, 2, 0, /*
3075 Apply FUNCTION to each element of SEQUENCE; return a vector of the results. 3075 Apply FUNCTION to each element of SEQUENCE; return a vector of the results.
3076 The result is a vector of the same length as SEQUENCE. 3076 The result is a vector of the same length as SEQUENCE.
3077 SEQUENCE may be a list, a vector, a bit vector, or a string. 3077 SEQUENCE may be a list, a vector, a bit vector, or a string.
3078 */ 3078 */
3079 (function, sequence)) 3079 (function, sequence))
3080 { 3080 {
3081 size_t len = XINT (Flength (sequence)); 3081 Element_Count len = XINT (Flength (sequence));
3082 Lisp_Object result = make_vector (len, Qnil); 3082 Lisp_Object result = make_vector (len, Qnil);
3083 struct gcpro gcpro1; 3083 struct gcpro gcpro1;
3084 3084
3085 GCPRO1 (result); 3085 GCPRO1 (result);
3086 mapcar1 (len, XVECTOR_DATA (result), function, sequence); 3086 mapcar1 (len, XVECTOR_DATA (result), function, sequence);
3597 3597
3598 /* We need to setup proper unwinding, because there is a number of 3598 /* We need to setup proper unwinding, because there is a number of
3599 ways these functions can blow up, and we don't want to have memory 3599 ways these functions can blow up, and we don't want to have memory
3600 leaks in those cases. */ 3600 leaks in those cases. */
3601 #define XMALLOC_OR_ALLOCA(ptr, len, type) do { \ 3601 #define XMALLOC_OR_ALLOCA(ptr, len, type) do { \
3602 size_t XOA_len = (len); \ 3602 Element_Count XOA_len = (len); \
3603 if (XOA_len > MAX_ALLOCA) \ 3603 if (XOA_len > MAX_ALLOCA) \
3604 { \ 3604 { \
3605 ptr = xnew_array (type, XOA_len); \ 3605 ptr = xnew_array (type, XOA_len); \
3606 record_unwind_protect (free_malloced_ptr, \ 3606 record_unwind_protect (free_malloced_ptr, \
3607 make_opaque_ptr ((void *)ptr)); \ 3607 make_opaque_ptr ((void *)ptr)); \