Mercurial > hg > xemacs-beta
changeset 3063:d30cd499e445
[xemacs-hg @ 2005-11-13 10:48:01 by ben]
further error-checking, etc.
alloc.c, lrecord.h: Move around the handling of setting of lheader->uid so it's in
set_lheader_implementation() -- that way, even non-MC-ALLOC builds
get useful uid's in their bare lrecords. Redo related code for
strings so the non-ascii count that is stored in the uid isn't hosed.
events.c: Save and restore the uid around event zeroing/deadbeefing.
lisp.h: Set the correct value of MAX_STRING_ASCII_BEGIN under MC_ALLOC.
lisp.h: rearrange the basic code handling ints and chars. basic int stuff goes
first, followed by basic char stuff, followed in turn by stuff that
mixes ints and chars. this is required since some basic defn's have
become inline functions.
XCHAR and CHARP have additional error-checking in that they check to make
sure that the value in question is not just a character but a valid
character (i.e. its numeric value is valid).
print.c: debug_p4 now has a useful UID in all cases and uses it; but it also prints
the raw header address (previously, you just got one of them).
text.h: some basic char defn's that belonged in lisp.h have been moved there.
valid_ichar_p() is moved too since the inline functions need it.
author | ben |
---|---|
date | Sun, 13 Nov 2005 10:48:04 +0000 |
parents | 21d92abaac3a |
children | b350e85a2a5e |
files | src/ChangeLog src/alloc.c src/events.c src/lisp.h src/lrecord.h src/print.c src/text.h |
diffstat | 7 files changed, 285 insertions(+), 186 deletions(-) [+] |
line wrap: on
line diff
--- a/src/ChangeLog Sun Nov 13 10:39:41 2005 +0000 +++ b/src/ChangeLog Sun Nov 13 10:48:04 2005 +0000 @@ -1,3 +1,54 @@ +2005-11-13 Ben Wing <ben@xemacs.org> + + * alloc.c: + * alloc.c (alloc_lrecord): + * alloc.c (noseeum_alloc_lrecord): + * alloc.c (make_uninit_string): + * alloc.c (Fmake_string): + * alloc.c (make_string_nocopy): + * lrecord.h: + * lrecord.h (struct lrecord_header): + * lrecord.h (set_lheader_implementation): + Move around the handling of setting of lheader->uid so it's in + set_lheader_implementation() -- that way, even non-MC-ALLOC builds + get useful uid's in their bare lrecords. Redo related code for + strings so the non-ascii count that is stored in the uid isn't hosed. + + * events.c: + * events.c (deinitialize_event): + * events.c (zero_event): + Save and restore the uid around event zeroing/deadbeefing. + + * lisp.h: + Set the correct value of MAX_STRING_ASCII_BEGIN under MC_ALLOC. + + * lisp.h (ZEROP): + * lisp.h (XINT): + * lisp.h (CHECK_INT): + * lisp.h (CONCHECK_INT): + * lisp.h (NATNUMP): + * lisp.h (CHECK_NATNUM): + * lisp.h (CONCHECK_NATNUM): + * lisp.h (XCHAR): + * lisp.h (XCHAR_OR_INT): + * lisp.h (CHAR_INTP): + rearrange the basic code handling ints and chars. basic int stuff goes + first, followed by basic char stuff, followed in turn by stuff that + mixes ints and chars. this is required since some basic defn's have + become inline functions. + + XCHAR and CHARP have additional error-checking in that they check to make + sure that the value in question is not just a character but a valid + character (i.e. its numeric value is valid). + + * print.c: + * print.c (debug_p4): + debug_p4 now has a useful UID in all cases and uses it; but it also prints + the raw header address (previously, you just got one of them). + * text.h: + some basic char defn's that belonged in lisp.h have been moved there. + valid_ichar_p() is moved too since the inline functions need it. + 2005-11-13 Ben Wing <ben@xemacs.org> * Makefile.in.in (distclean-noconfig):
--- a/src/alloc.c Sun Nov 13 10:39:41 2005 +0000 +++ b/src/alloc.c Sun Nov 13 10:48:04 2005 +0000 @@ -185,7 +185,7 @@ EMACS_INT gc_generation_number[1]; /* This is just for use by the printer, to allow things to print uniquely */ -static int lrecord_uid_counter; +int lrecord_uid_counter; /* Nonzero when calling certain hooks or doing other things where a GC would be bad */ @@ -606,7 +606,6 @@ lheader = (struct lrecord_header *) mc_alloc (size); gc_checking_assert (LRECORD_FREE_P (lheader)); set_lheader_implementation (lheader, implementation); - lheader->uid = lrecord_uid_counter++; #ifdef ALLOC_TYPE_STATS inc_lrecord_stats (size, lheader); #endif /* ALLOC_TYPE_STATS */ @@ -628,7 +627,6 @@ lheader = (struct lrecord_header *) mc_alloc (size); gc_checking_assert (LRECORD_FREE_P (lheader)); set_lheader_implementation (lheader, implementation); - lheader->uid = lrecord_uid_counter++; #ifdef ALLOC_TYPE_STATS inc_lrecord_stats (size, lheader); #endif /* ALLOC_TYPE_STATS */ @@ -2484,6 +2482,10 @@ set_lheader_implementation (&s->u.lheader, &lrecord_string); #endif /* not MC_ALLOC */ + /* The above allocations set the UID field, which overlaps with the + ascii-length field, to some non-zero value. We need to zero it. */ + XSET_STRING_ASCII_BEGIN (wrap_string (s), 0); + set_lispstringp_data (s, BIG_STRING_FULLSIZE_P (fullsize) ? allocate_big_string_chars (length + 1) : allocate_string_chars_struct (wrap_string (s), @@ -2712,16 +2714,6 @@ EMACS_INT i; Ibyte *ptr = XSTRING_DATA (val); -#ifdef MC_ALLOC - /* Need this for the new allocator: strings are using the uid - field for ascii_begin. The uid field is set for debugging, - but the string code assumes here that ascii_begin is always - zero, when not touched. This assumption is not true with - the new allocator, so ascii_begin has to be set to zero - here. */ - XSET_STRING_ASCII_BEGIN (val, 0); -#endif /* not MC_ALLOC */ - for (i = XINT (length); i; i--) { Ibyte *init_ptr = init_str; @@ -2872,6 +2864,8 @@ set_lheader_implementation (&s->u.lheader, &lrecord_string); SET_C_READONLY_RECORD_HEADER (&s->u.lheader); #endif /* not MC_ALLOC */ + /* Don't need to XSET_STRING_ASCII_BEGIN() here because it happens in + init_string_ascii_begin(). */ s->plist = Qnil; set_lispstringp_data (s, (Ibyte *) contents); set_lispstringp_length (s, length);
--- a/src/events.c Sun Nov 13 10:39:41 2005 +0000 +++ b/src/events.c Sun Nov 13 10:48:04 2005 +0000 @@ -1,7 +1,7 @@ /* Events: printing them, converting them to and from characters. Copyright (C) 1991, 1992, 1993, 1994 Free Software Foundation, Inc. Copyright (C) 1994, 1995 Board of Trustees, University of Illinois. - Copyright (C) 2001, 2002 Ben Wing. + Copyright (C) 2001, 2002, 2005 Ben Wing. This file is part of XEmacs. @@ -86,11 +86,14 @@ deinitialize_event (Lisp_Object ev) { Lisp_Event *event = XEVENT (ev); + int i; + /* Preserve the old UID for this event, for tracking it */ + unsigned int old_uid = event->lheader.uid; - int i; for (i = 0; i < (int) (sizeof (Lisp_Event) / sizeof (int)); i++) ((int *) event) [i] = 0xdeadbeef; /* -559038737 base 10 */ set_lheader_implementation (&event->lheader, &lrecord_event); + event->lheader.uid = old_uid; set_event_type (event, dead_event); SET_EVENT_CHANNEL (event, Qnil); XSET_EVENT_NEXT (ev, Qnil); @@ -100,8 +103,12 @@ void zero_event (Lisp_Event *e) { + /* Preserve the old UID for this event, for tracking it */ + unsigned int old_uid = e->lheader.uid; + xzero (*e); set_lheader_implementation (&e->lheader, &lrecord_event); + e->lheader.uid = old_uid; set_event_type (e, empty_event); SET_EVENT_CHANNEL (e, Qnil); SET_EVENT_NEXT (e, Qnil);
--- a/src/lisp.h Sun Nov 13 10:39:41 2005 +0000 +++ b/src/lisp.h Sun Nov 13 10:48:04 2005 +0000 @@ -2314,7 +2314,11 @@ }; typedef struct Lisp_String Lisp_String; +#ifdef MC_ALLOC +#define MAX_STRING_ASCII_BEGIN ((1 << 22) - 1) +#else #define MAX_STRING_ASCII_BEGIN ((1 << 21) - 1) +#endif DECLARE_MODULE_API_LRECORD (string, Lisp_String); #define XSTRING(x) XRECORD (x, string, Lisp_String) @@ -2559,32 +2563,221 @@ #define marker_next(m) ((m)->next) #define marker_prev(m) ((m)->prev) -/*------------------------------- char ---------------------------------*/ - -#define CHARP(x) (XTYPE (x) == Lisp_Type_Char) +/*-------------------basic int (no connection to char)------------------*/ + +#define ZEROP(x) EQ (x, Qzero) #ifdef ERROR_CHECK_TYPES +#define XINT(x) XINT_1 (x, __FILE__, __LINE__) + +DECLARE_INLINE_HEADER ( +EMACS_INT +XINT_1 (Lisp_Object obj, const Ascbyte *file, int line) +) +{ + assert_at_line (INTP (obj), file, line); + return XREALINT (obj); +} + +#else /* no error checking */ + +#define XINT(obj) XREALINT (obj) + +#endif /* no error checking */ + +#define CHECK_INT(x) do { \ + if (!INTP (x)) \ + dead_wrong_type_argument (Qintegerp, x); \ +} while (0) + +#define CONCHECK_INT(x) do { \ + if (!INTP (x)) \ + x = wrong_type_argument (Qintegerp, x); \ +} while (0) + +#define NATNUMP(x) (INTP (x) && XINT (x) >= 0) + +#define CHECK_NATNUM(x) do { \ + if (!NATNUMP (x)) \ + dead_wrong_type_argument (Qnatnump, x); \ +} while (0) + +#define CONCHECK_NATNUM(x) do { \ + if (!NATNUMP (x)) \ + x = wrong_type_argument (Qnatnump, x); \ +} while (0) + +/*------------------------------- char ---------------------------------*/ + +/* NOTE: There are basic functions for converting between a character and + the string representation of a character in text.h, as well as lots of + other character-related stuff. There are other functions/macros for + working with Ichars in charset.h, for retrieving the charset of an + Ichar, the length of an Ichar when converted to text, etc. +*/ + +#ifdef MULE + +MODULE_API int non_ascii_valid_ichar_p (Ichar ch); + +/* Return whether the given Ichar is valid. + */ + +DECLARE_INLINE_HEADER ( +int +valid_ichar_p (Ichar ch) +) +{ + return (! (ch & ~0xFF)) || non_ascii_valid_ichar_p (ch); +} + +#else /* not MULE */ + +/* This works when CH is negative, and correctly returns non-zero only when CH + is in the range [0, 255], inclusive. */ +#define valid_ichar_p(ch) (! (ch & ~0xFF)) + +#endif /* not MULE */ + +#ifdef ERROR_CHECK_TYPES + +DECLARE_INLINE_HEADER ( +int +CHARP_1 (Lisp_Object obj, const Ascbyte *file, int line) +) +{ + if (XTYPE (obj) != Lisp_Type_Char) + return 0; + assert_at_line (valid_ichar_p (XCHARVAL (obj)), file, line); + return 1; +} + +#define CHARP(x) CHARP_1 (x, __FILE__, __LINE__) + DECLARE_INLINE_HEADER ( Ichar XCHAR_1 (Lisp_Object obj, const Ascbyte *file, int line) ) { + Ichar ch; assert_at_line (CHARP (obj), file, line); - return XCHARVAL (obj); + ch = XCHARVAL (obj); + assert_at_line (valid_ichar_p (ch), file, line); + return ch; } #define XCHAR(x) XCHAR_1 (x, __FILE__, __LINE__) +#else /* not ERROR_CHECK_TYPES */ + +#define CHARP(x) (XTYPE (x) == Lisp_Type_Char) +#define XCHAR(x) ((Ichar) XCHARVAL (x)) + +#endif /* (else) not ERROR_CHECK_TYPES */ + +#define CONCHECK_CHAR(x) do { \ + if (!CHARP (x)) \ + x = wrong_type_argument (Qcharacterp, x); \ + } while (0) + +#define CHECK_CHAR(x) do { \ + if (!CHARP (x)) \ + dead_wrong_type_argument (Qcharacterp, x); \ + } while (0) + + +DECLARE_INLINE_HEADER ( +Lisp_Object +make_char (Ichar val) +) +{ + type_checking_assert (valid_ichar_p (val)); + /* This is defined in lisp-union.h or lisp-disunion.h */ + return make_char_1 (val); +} + +/*------------------------- int-char connection ------------------------*/ + +#ifdef ERROR_CHECK_TYPES + +#define XCHAR_OR_INT(x) XCHAR_OR_INT_1 (x, __FILE__, __LINE__) + +DECLARE_INLINE_HEADER ( +EMACS_INT +XCHAR_OR_INT_1 (Lisp_Object obj, const Ascbyte *file, int line) +) +{ + assert_at_line (INTP (obj) || CHARP (obj), file, line); + return CHARP (obj) ? XCHAR (obj) : XINT (obj); +} + #else /* no error checking */ -#define XCHAR(x) ((Ichar) XCHARVAL (x)) +#define XCHAR_OR_INT(obj) (CHARP (obj) ? XCHAR (obj) : XINT (obj)) #endif /* no error checking */ -#define CHECK_CHAR(x) CHECK_NONRECORD (x, Lisp_Type_Char, Qcharacterp) -#define CONCHECK_CHAR(x) CONCHECK_NONRECORD (x, Lisp_Type_Char, Qcharacterp) - +/* True of X is an integer whose value is the valid integral equivalent of a + character. */ + +#define CHAR_INTP(x) (INTP (x) && valid_ichar_p (XINT (x))) + +/* True of X is a character or an integral value that can be converted into a + character. */ +#define CHAR_OR_CHAR_INTP(x) (CHARP (x) || CHAR_INTP (x)) + +DECLARE_INLINE_HEADER ( +Ichar +XCHAR_OR_CHAR_INT (Lisp_Object obj) +) +{ + return CHARP (obj) ? XCHAR (obj) : XINT (obj); +} + +/* Signal an error if CH is not a valid character or integer Lisp_Object. + If CH is an integer Lisp_Object, convert it to a character Lisp_Object, + but merely by repackaging, without performing tests for char validity. + */ + +#define CHECK_CHAR_COERCE_INT(x) do { \ + if (CHARP (x)) \ + ; \ + else if (CHAR_INTP (x)) \ + x = make_char (XINT (x)); \ + else \ + x = wrong_type_argument (Qcharacterp, x); \ +} while (0) + +/* next three always continuable because they coerce their arguments. */ +#define CHECK_INT_COERCE_CHAR(x) do { \ + if (INTP (x)) \ + ; \ + else if (CHARP (x)) \ + x = make_int (XCHAR (x)); \ + else \ + x = wrong_type_argument (Qinteger_or_char_p, x); \ +} while (0) + +#define CHECK_INT_COERCE_MARKER(x) do { \ + if (INTP (x)) \ + ; \ + else if (MARKERP (x)) \ + x = make_int (marker_position (x)); \ + else \ + x = wrong_type_argument (Qinteger_or_marker_p, x); \ +} while (0) + +#define CHECK_INT_COERCE_CHAR_OR_MARKER(x) do { \ + if (INTP (x)) \ + ; \ + else if (CHARP (x)) \ + x = make_int (XCHAR (x)); \ + else if (MARKERP (x)) \ + x = make_int (marker_position (x)); \ + else \ + x = wrong_type_argument (Qinteger_char_or_marker_p, x); \ +} while (0) /*------------------------------ float ---------------------------------*/ @@ -2624,93 +2817,6 @@ # define INT_OR_FLOATP(x) (INTP (x) || FLOATP (x)) -/*-------------------------------- int ---------------------------------*/ - -#define ZEROP(x) EQ (x, Qzero) - -#ifdef ERROR_CHECK_TYPES - -#define XCHAR_OR_INT(x) XCHAR_OR_INT_1 (x, __FILE__, __LINE__) -#define XINT(x) XINT_1 (x, __FILE__, __LINE__) - -DECLARE_INLINE_HEADER ( -EMACS_INT -XINT_1 (Lisp_Object obj, const Ascbyte *file, int line) -) -{ - assert_at_line (INTP (obj), file, line); - return XREALINT (obj); -} - -DECLARE_INLINE_HEADER ( -EMACS_INT -XCHAR_OR_INT_1 (Lisp_Object obj, const Ascbyte *file, int line) -) -{ - assert_at_line (INTP (obj) || CHARP (obj), file, line); - return CHARP (obj) ? XCHAR (obj) : XINT (obj); -} - -#else /* no error checking */ - -#define XINT(obj) XREALINT (obj) -#define XCHAR_OR_INT(obj) (CHARP (obj) ? XCHAR (obj) : XINT (obj)) - -#endif /* no error checking */ - -#define CHECK_INT(x) do { \ - if (!INTP (x)) \ - dead_wrong_type_argument (Qintegerp, x); \ -} while (0) - -#define CONCHECK_INT(x) do { \ - if (!INTP (x)) \ - x = wrong_type_argument (Qintegerp, x); \ -} while (0) - -#define NATNUMP(x) (INTP (x) && XINT (x) >= 0) - -#define CHECK_NATNUM(x) do { \ - if (!NATNUMP (x)) \ - dead_wrong_type_argument (Qnatnump, x); \ -} while (0) - -#define CONCHECK_NATNUM(x) do { \ - if (!NATNUMP (x)) \ - x = wrong_type_argument (Qnatnump, x); \ -} while (0) - -/* next three always continuable because they coerce their arguments. */ -#define CHECK_INT_COERCE_CHAR(x) do { \ - if (INTP (x)) \ - ; \ - else if (CHARP (x)) \ - x = make_int (XCHAR (x)); \ - else \ - x = wrong_type_argument (Qinteger_or_char_p, x); \ -} while (0) - -#define CHECK_INT_COERCE_MARKER(x) do { \ - if (INTP (x)) \ - ; \ - else if (MARKERP (x)) \ - x = make_int (marker_position (x)); \ - else \ - x = wrong_type_argument (Qinteger_or_marker_p, x); \ -} while (0) - -#define CHECK_INT_COERCE_CHAR_OR_MARKER(x) do { \ - if (INTP (x)) \ - ; \ - else if (CHARP (x)) \ - x = make_int (XCHAR (x)); \ - else if (MARKERP (x)) \ - x = make_int (marker_position (x)); \ - else \ - x = wrong_type_argument (Qinteger_char_or_marker_p, x); \ -} while (0) - - /*--------------------------- readonly objects -------------------------*/ #ifndef MC_ALLOC
--- a/src/lrecord.h Sun Nov 13 10:39:41 2005 +0000 +++ b/src/lrecord.h Sun Nov 13 10:48:04 2005 +0000 @@ -120,9 +120,9 @@ debugging. */ unsigned int free :1; - /* The `uid' field is just for debugging/printing convenience. - Having this slot doesn't hurt us much spacewise, since the - bits are unused anyway. */ + /* The `uid' field is just for debugging/printing convenience. Having + this slot doesn't hurt us spacewise, since the bits are unused + anyway. (The bits are used for strings, though.) */ unsigned int uid :22; #else /* not MC_ALLOC */ @@ -140,13 +140,17 @@ /* 1 if the object is readonly from lisp */ unsigned int lisp_readonly :1; - unsigned int unused :21; + /* The `uid' field is just for debugging/printing convenience. Having + this slot doesn't hurt us spacewise, since the bits are unused + anyway. (The bits are used for strings, though.) */ + unsigned int uid :21; #endif /* not MC_ALLOC */ }; struct lrecord_implementation; int lrecord_type_index (const struct lrecord_implementation *implementation); +extern int lrecord_uid_counter; #ifdef MC_ALLOC #define set_lheader_implementation(header,imp) do { \ @@ -154,6 +158,7 @@ SLI_header->type = (imp)->lrecord_type_index; \ SLI_header->lisp_readonly = 0; \ SLI_header->free = 0; \ + SLI_header->uid = lrecord_uid_counter++; \ } while (0) #else /* not MC_ALLOC */ #define set_lheader_implementation(header,imp) do { \ @@ -162,6 +167,7 @@ SLI_header->mark = 0; \ SLI_header->c_readonly = 0; \ SLI_header->lisp_readonly = 0; \ + SLI_header->uid = lrecord_uid_counter++; \ } while (0) #endif /* not MC_ALLOC */
--- a/src/print.c Sun Nov 13 10:39:41 2005 +0000 +++ b/src/print.c Sun Nov 13 10:48:04 2005 +0000 @@ -1,6 +1,6 @@ /* Lisp object printing and output streams. Copyright (C) 1985, 1986, 1988, 1992-1995 Free Software Foundation, Inc. - Copyright (C) 1995, 1996, 2000, 2001, 2002, 2003 Ben Wing. + Copyright (C) 1995, 1996, 2000, 2001, 2002, 2003, 2005 Ben Wing. This file is part of XEmacs. @@ -2211,14 +2211,16 @@ (EMACS_INT) header); else #ifdef MC_ALLOC - debug_out ("#<%s 0x%lx>", + debug_out ("#<%s addr=0x%lx uid=0x%lx>", LHEADER_IMPLEMENTATION (header)->name, + (EMACS_INT) header, (EMACS_INT) ((struct lrecord_header *) header)->uid); #else /* not MC_ALLOC */ - debug_out ("#<%s 0x%lx>", + debug_out ("#<%s addr=0x%lx uid=0x%lx>", LHEADER_IMPLEMENTATION (header)->name, + (EMACS_INT) header, LHEADER_IMPLEMENTATION (header)->basic_p ? - (EMACS_INT) header : + ((struct lrecord_header *) header)->uid : ((struct old_lcrecord_header *) header)->uid); #endif /* not MC_ALLOC */ }
--- a/src/text.h Sun Nov 13 10:39:41 2005 +0000 +++ b/src/text.h Sun Nov 13 10:48:04 2005 +0000 @@ -1,7 +1,7 @@ /* Header file for text manipulation primitives and macros. Copyright (C) 1985-1995 Free Software Foundation, Inc. Copyright (C) 1995 Sun Microsystems, Inc. - Copyright (C) 2000, 2001, 2002, 2003, 2004 Ben Wing. + Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005 Ben Wing. This file is part of XEmacs. @@ -1006,73 +1006,6 @@ #define itext_ichar_n(ptr, offset) \ itext_ichar (itext_n_addr (ptr, offset)) - -/* ---------------------------- */ -/* Working with Ichars */ -/* ---------------------------- */ - -/* NOTE: There are other functions/macros for working with Ichars in - charset.h, for retrieving the charset of an Ichar, the length of an - Ichar when converted to text, etc. -*/ - -#ifdef MULE - -MODULE_API int non_ascii_valid_ichar_p (Ichar ch); - -/* Return whether the given Ichar is valid. - */ - -DECLARE_INLINE_HEADER ( -int -valid_ichar_p (Ichar ch) -) -{ - return (! (ch & ~0xFF)) || non_ascii_valid_ichar_p (ch); -} - -#else /* not MULE */ - -#define valid_ichar_p(ch) (! (ch & ~0xFF)) - -#endif /* not MULE */ - -DECLARE_INLINE_HEADER ( -Lisp_Object -make_char (Ichar val) -) -{ - type_checking_assert (valid_ichar_p (val)); - return make_char_1 (val); -} - -#define CHAR_INTP(x) (INTP (x) && valid_ichar_p (XINT (x))) - -#define CHAR_OR_CHAR_INTP(x) (CHARP (x) || CHAR_INTP (x)) - -DECLARE_INLINE_HEADER ( -Ichar -XCHAR_OR_CHAR_INT (Lisp_Object obj) -) -{ - return CHARP (obj) ? XCHAR (obj) : XINT (obj); -} - -/* Signal an error if CH is not a valid character or integer Lisp_Object. - If CH is an integer Lisp_Object, convert it to a character Lisp_Object, - but merely by repackaging, without performing tests for char validity. - */ - -#define CHECK_CHAR_COERCE_INT(x) do { \ - if (CHARP (x)) \ - ; \ - else if (CHAR_INTP (x)) \ - x = make_char (XINT (x)); \ - else \ - x = wrong_type_argument (Qcharacterp, x); \ -} while (0) - - /************************************************************************/ /* */