diff options
| author | Kim F. Storm | 2006-07-12 13:13:44 +0000 |
|---|---|---|
| committer | Kim F. Storm | 2006-07-12 13:13:44 +0000 |
| commit | c8a39089de0f4b65fc2936618087c1e5e15c3920 (patch) | |
| tree | c929e8b27ee909f570e7402946dc8db92573dc39 /src | |
| parent | b8a6aaa7dd0680fedb2e149094f0a05e311e489c (diff) | |
| download | emacs-c8a39089de0f4b65fc2936618087c1e5e15c3920.tar.gz emacs-c8a39089de0f4b65fc2936618087c1e5e15c3920.zip | |
(CHECK_TYPE): New macro for generic type checking.
(CAR_SAFE, CDR_SAFE): New macros.
(ARRAYP, CHECK_ARRAY): New macros.
(CHECK_VECTOR_OR_STRING, CHECK_SUBR): New macros.
(CHECK_WINDOW_CONFIGURATION): New macro.
(CHECK_LIST_CONS, CHECK_LIST_END): New checks for list traversal.
(CHECK_STRING_OR_BUFFER, CHECK_HASH_TABLE, CHECK_LIST)
(CHECK_STRING, CHECK_STRING_CAR, CHECK_CONS, CHECK_SYMBOL)
(CHECK_CHAR_TABLE, CHECK_VECTOR, CHECK_VECTOR_OR_CHAR_TABLE)
(CHECK_BUFFER, CHECK_WINDOW, CHECK_LIVE_WINDOW, CHECK_PROCESS)
(CHECK_NUMBER, CHECK_NATNUM, CHECK_MARKER, CHECK_OVERLAY)
(CHECK_NUMBER_COERCE_MARKER, CHECK_FLOAT, CHECK_NUMBER_OR_FLOAT)
(CHECK_NUMBER_OR_FLOAT_COERCE_MARKER): Use CHECK_TYPE.
Diffstat (limited to 'src')
| -rw-r--r-- | src/lisp.h | 102 |
1 files changed, 61 insertions, 41 deletions
diff --git a/src/lisp.h b/src/lisp.h index d6c4a1ba609..e276ac02b28 100644 --- a/src/lisp.h +++ b/src/lisp.h | |||
| @@ -591,6 +591,12 @@ extern size_t pure_size; | |||
| 591 | #define STRING_COPYIN(string, index, new, count) \ | 591 | #define STRING_COPYIN(string, index, new, count) \ |
| 592 | bcopy (new, XSTRING (string)->data + index, count) | 592 | bcopy (new, XSTRING (string)->data + index, count) |
| 593 | 593 | ||
| 594 | /* Type checking. */ | ||
| 595 | |||
| 596 | #define CHECK_TYPE(ok, Qxxxp, x) \ | ||
| 597 | do { if (!(ok)) wrong_type_argument (Qxxxp, (x)); } while (0) | ||
| 598 | |||
| 599 | |||
| 594 | 600 | ||
| 595 | /* See the macros in intervals.h. */ | 601 | /* See the macros in intervals.h. */ |
| 596 | 602 | ||
| @@ -598,8 +604,8 @@ typedef struct interval *INTERVAL; | |||
| 598 | 604 | ||
| 599 | /* Complain if object is not string or buffer type */ | 605 | /* Complain if object is not string or buffer type */ |
| 600 | #define CHECK_STRING_OR_BUFFER(x) \ | 606 | #define CHECK_STRING_OR_BUFFER(x) \ |
| 601 | { if (!STRINGP ((x)) && !BUFFERP ((x))) \ | 607 | CHECK_TYPE (STRINGP (x) || BUFFERP (x), Qbuffer_or_string_p, x) |
| 602 | x = wrong_type_argument (Qbuffer_or_string_p, (x)); } | 608 | |
| 603 | 609 | ||
| 604 | /* In a cons, the markbit of the car is the gc mark bit */ | 610 | /* In a cons, the markbit of the car is the gc mark bit */ |
| 605 | 611 | ||
| @@ -668,6 +674,13 @@ struct Lisp_Cons | |||
| 668 | : NILP ((c)) ? Qnil \ | 674 | : NILP ((c)) ? Qnil \ |
| 669 | : wrong_type_argument (Qlistp, (c))) | 675 | : wrong_type_argument (Qlistp, (c))) |
| 670 | 676 | ||
| 677 | /* Take the car or cdr of something whose type is not known. */ | ||
| 678 | #define CAR_SAFE(c) \ | ||
| 679 | (CONSP ((c)) ? XCAR ((c)) : Qnil) | ||
| 680 | |||
| 681 | #define CDR_SAFE(c) \ | ||
| 682 | (CONSP ((c)) ? XCDR ((c)) : Qnil) | ||
| 683 | |||
| 671 | /* Nonzero if STR is a multibyte string. */ | 684 | /* Nonzero if STR is a multibyte string. */ |
| 672 | #define STRING_MULTIBYTE(STR) \ | 685 | #define STRING_MULTIBYTE(STR) \ |
| 673 | (XSTRING (STR)->size_byte >= 0) | 686 | (XSTRING (STR)->size_byte >= 0) |
| @@ -1053,13 +1066,8 @@ struct Lisp_Hash_Table | |||
| 1053 | #define HASH_TABLE_P(OBJ) PSEUDOVECTORP (OBJ, PVEC_HASH_TABLE) | 1066 | #define HASH_TABLE_P(OBJ) PSEUDOVECTORP (OBJ, PVEC_HASH_TABLE) |
| 1054 | #define GC_HASH_TABLE_P(x) GC_PSEUDOVECTORP (x, PVEC_HASH_TABLE) | 1067 | #define GC_HASH_TABLE_P(x) GC_PSEUDOVECTORP (x, PVEC_HASH_TABLE) |
| 1055 | 1068 | ||
| 1056 | #define CHECK_HASH_TABLE(x) \ | 1069 | #define CHECK_HASH_TABLE(x) \ |
| 1057 | do \ | 1070 | CHECK_TYPE (HASH_TABLE_P (x), Qhash_table_p, x) |
| 1058 | { \ | ||
| 1059 | if (!HASH_TABLE_P ((x))) \ | ||
| 1060 | x = wrong_type_argument (Qhash_table_p, (x)); \ | ||
| 1061 | } \ | ||
| 1062 | while (0) | ||
| 1063 | 1071 | ||
| 1064 | /* Value is the key part of entry IDX in hash table H. */ | 1072 | /* Value is the key part of entry IDX in hash table H. */ |
| 1065 | 1073 | ||
| @@ -1524,41 +1532,57 @@ typedef unsigned char UCHAR; | |||
| 1524 | /* Test for image (image . spec) */ | 1532 | /* Test for image (image . spec) */ |
| 1525 | #define IMAGEP(x) (CONSP (x) && EQ (XCAR (x), Qimage)) | 1533 | #define IMAGEP(x) (CONSP (x) && EQ (XCAR (x), Qimage)) |
| 1526 | 1534 | ||
| 1535 | /* Array types. */ | ||
| 1536 | |||
| 1537 | #define ARRAYP(x) \ | ||
| 1538 | (VECTORP (x) || STRINGP (x) || CHAR_TABLE_P (x) || BOOL_VECTOR_P (x)) | ||
| 1527 | 1539 | ||
| 1528 | #define GC_EQ(x, y) EQ (x, y) | 1540 | #define GC_EQ(x, y) EQ (x, y) |
| 1529 | 1541 | ||
| 1530 | #define CHECK_LIST(x) \ | 1542 | #define CHECK_LIST(x) \ |
| 1531 | do { if (!CONSP ((x)) && !NILP (x)) x = wrong_type_argument (Qlistp, (x)); } while (0) | 1543 | CHECK_TYPE (CONSP (x) || NILP (x), Qlistp, x) |
| 1544 | |||
| 1545 | #define CHECK_LIST_CONS(x, y) \ | ||
| 1546 | CHECK_TYPE (CONSP (x), Qlistp, y) | ||
| 1547 | |||
| 1548 | #define CHECK_LIST_END(x, y) \ | ||
| 1549 | CHECK_TYPE (NILP (x), Qlistp, y) | ||
| 1532 | 1550 | ||
| 1533 | #define CHECK_STRING(x) \ | 1551 | #define CHECK_STRING(x) \ |
| 1534 | do { if (!STRINGP ((x))) x = wrong_type_argument (Qstringp, (x)); } while (0) | 1552 | CHECK_TYPE (STRINGP (x), Qstringp, x) |
| 1535 | 1553 | ||
| 1536 | #define CHECK_STRING_CAR(x) \ | 1554 | #define CHECK_STRING_CAR(x) \ |
| 1537 | do { if (!STRINGP (XCAR (x))) XSETCAR (x, wrong_type_argument (Qstringp, XCAR (x))); } while (0) | 1555 | CHECK_TYPE (STRINGP (XCAR (x)), Qstringp, XCAR (x)) |
| 1538 | 1556 | ||
| 1539 | #define CHECK_CONS(x) \ | 1557 | #define CHECK_CONS(x) \ |
| 1540 | do { if (!CONSP ((x))) x = wrong_type_argument (Qconsp, (x)); } while (0) | 1558 | CHECK_TYPE (CONSP (x), Qconsp, x) |
| 1541 | 1559 | ||
| 1542 | #define CHECK_SYMBOL(x) \ | 1560 | #define CHECK_SYMBOL(x) \ |
| 1543 | do { if (!SYMBOLP ((x))) x = wrong_type_argument (Qsymbolp, (x)); } while (0) | 1561 | CHECK_TYPE (SYMBOLP (x), Qsymbolp, x) |
| 1544 | 1562 | ||
| 1545 | #define CHECK_CHAR_TABLE(x) \ | 1563 | #define CHECK_CHAR_TABLE(x) \ |
| 1546 | do { if (!CHAR_TABLE_P ((x))) \ | 1564 | CHECK_TYPE (CHAR_TABLE_P (x), Qchar_table_p, x) |
| 1547 | x = wrong_type_argument (Qchar_table_p, (x)); } while (0) | ||
| 1548 | 1565 | ||
| 1549 | #define CHECK_VECTOR(x) \ | 1566 | #define CHECK_VECTOR(x) \ |
| 1550 | do { if (!VECTORP ((x))) x = wrong_type_argument (Qvectorp, (x)); } while (0) | 1567 | CHECK_TYPE (VECTORP (x), Qvectorp, x) |
| 1551 | 1568 | ||
| 1552 | #define CHECK_VECTOR_OR_CHAR_TABLE(x) \ | 1569 | #define CHECK_VECTOR_OR_STRING(x) \ |
| 1553 | do { if (!VECTORP ((x)) && !CHAR_TABLE_P ((x))) \ | 1570 | CHECK_TYPE (VECTORP (x) || STRINGP (x), Qarrayp, x) |
| 1554 | x = wrong_type_argument (Qvector_or_char_table_p, (x)); \ | 1571 | |
| 1555 | } while (0) | 1572 | #define CHECK_ARRAY(x, Qxxxp) \ |
| 1573 | CHECK_TYPE (ARRAYP (x), Qxxxp, x) | ||
| 1574 | |||
| 1575 | #define CHECK_VECTOR_OR_CHAR_TABLE(x) \ | ||
| 1576 | CHECK_TYPE (VECTORP (x) || CHAR_TABLE_P (x), Qvector_or_char_table_p, x) | ||
| 1556 | 1577 | ||
| 1557 | #define CHECK_BUFFER(x) \ | 1578 | #define CHECK_BUFFER(x) \ |
| 1558 | do { if (!BUFFERP ((x))) x = wrong_type_argument (Qbufferp, (x)); } while (0) | 1579 | CHECK_TYPE (BUFFERP (x), Qbufferp, x) |
| 1559 | 1580 | ||
| 1560 | #define CHECK_WINDOW(x) \ | 1581 | #define CHECK_WINDOW(x) \ |
| 1561 | do { if (!WINDOWP ((x))) x = wrong_type_argument (Qwindowp, (x)); } while (0) | 1582 | CHECK_TYPE (WINDOWP (x), Qwindowp, x) |
| 1583 | |||
| 1584 | #define CHECK_WINDOW_CONFIGURATION(x) \ | ||
| 1585 | CHECK_TYPE (WINDOW_CONFIGURATIONP (x), Qwindow_configuration_p, x) | ||
| 1562 | 1586 | ||
| 1563 | /* This macro rejects windows on the interior of the window tree as | 1587 | /* This macro rejects windows on the interior of the window tree as |
| 1564 | "dead", which is what we want; this is an argument-checking macro, and | 1588 | "dead", which is what we want; this is an argument-checking macro, and |
| @@ -1567,46 +1591,42 @@ typedef unsigned char UCHAR; | |||
| 1567 | A window of any sort, leaf or interior, is dead iff the buffer, | 1591 | A window of any sort, leaf or interior, is dead iff the buffer, |
| 1568 | vchild, and hchild members are all nil. */ | 1592 | vchild, and hchild members are all nil. */ |
| 1569 | 1593 | ||
| 1570 | #define CHECK_LIVE_WINDOW(x) \ | 1594 | #define CHECK_LIVE_WINDOW(x) \ |
| 1571 | do { \ | 1595 | CHECK_TYPE (WINDOWP (x) && !NILP (XWINDOW (x)->buffer), Qwindow_live_p, x) |
| 1572 | if (!WINDOWP ((x)) \ | ||
| 1573 | || NILP (XWINDOW ((x))->buffer)) \ | ||
| 1574 | x = wrong_type_argument (Qwindow_live_p, (x)); \ | ||
| 1575 | } while (0) | ||
| 1576 | 1596 | ||
| 1577 | #define CHECK_PROCESS(x) \ | 1597 | #define CHECK_PROCESS(x) \ |
| 1578 | do { if (!PROCESSP ((x))) x = wrong_type_argument (Qprocessp, (x)); } while (0) | 1598 | CHECK_TYPE (PROCESSP (x), Qprocessp, x) |
| 1599 | |||
| 1600 | #define CHECK_SUBR(x) \ | ||
| 1601 | CHECK_TYPE (SUBRP (x), Qsubrp, x) | ||
| 1579 | 1602 | ||
| 1580 | #define CHECK_NUMBER(x) \ | 1603 | #define CHECK_NUMBER(x) \ |
| 1581 | do { if (!INTEGERP ((x))) x = wrong_type_argument (Qintegerp, (x)); } while (0) | 1604 | CHECK_TYPE (INTEGERP (x), Qintegerp, x) |
| 1582 | 1605 | ||
| 1583 | #define CHECK_NATNUM(x) \ | 1606 | #define CHECK_NATNUM(x) \ |
| 1584 | do { if (!NATNUMP (x)) x = wrong_type_argument (Qwholenump, (x)); } while (0) | 1607 | CHECK_TYPE (NATNUMP (x), Qwholenump, x) |
| 1585 | 1608 | ||
| 1586 | #define CHECK_MARKER(x) \ | 1609 | #define CHECK_MARKER(x) \ |
| 1587 | do { if (!MARKERP ((x))) x = wrong_type_argument (Qmarkerp, (x)); } while (0) | 1610 | CHECK_TYPE (MARKERP (x), Qmarkerp, x) |
| 1588 | 1611 | ||
| 1589 | #define CHECK_NUMBER_COERCE_MARKER(x) \ | 1612 | #define CHECK_NUMBER_COERCE_MARKER(x) \ |
| 1590 | do { if (MARKERP ((x))) XSETFASTINT (x, marker_position (x)); \ | 1613 | do { if (MARKERP ((x))) XSETFASTINT (x, marker_position (x)); \ |
| 1591 | else if (!INTEGERP ((x))) x = wrong_type_argument (Qinteger_or_marker_p, (x)); } while (0) | 1614 | else CHECK_TYPE (INTEGERP (x), Qinteger_or_marker_p, x); } while (0) |
| 1592 | 1615 | ||
| 1593 | #define XFLOATINT(n) extract_float((n)) | 1616 | #define XFLOATINT(n) extract_float((n)) |
| 1594 | 1617 | ||
| 1595 | #define CHECK_FLOAT(x) \ | 1618 | #define CHECK_FLOAT(x) \ |
| 1596 | do { if (!FLOATP (x)) \ | 1619 | CHECK_TYPE (FLOATP (x), Qfloatp, x) |
| 1597 | x = wrong_type_argument (Qfloatp, (x)); } while (0) | ||
| 1598 | 1620 | ||
| 1599 | #define CHECK_NUMBER_OR_FLOAT(x) \ | 1621 | #define CHECK_NUMBER_OR_FLOAT(x) \ |
| 1600 | do { if (!FLOATP (x) && !INTEGERP (x)) \ | 1622 | CHECK_TYPE (FLOATP (x) || INTEGERP (x), Qnumberp, x) |
| 1601 | x = wrong_type_argument (Qnumberp, (x)); } while (0) | ||
| 1602 | 1623 | ||
| 1603 | #define CHECK_NUMBER_OR_FLOAT_COERCE_MARKER(x) \ | 1624 | #define CHECK_NUMBER_OR_FLOAT_COERCE_MARKER(x) \ |
| 1604 | do { if (MARKERP (x)) XSETFASTINT (x, marker_position (x)); \ | 1625 | do { if (MARKERP (x)) XSETFASTINT (x, marker_position (x)); \ |
| 1605 | else if (!INTEGERP (x) && !FLOATP (x)) \ | 1626 | else CHECK_TYPE (INTEGERP (x) || FLOATP (x), Qnumber_or_marker_p, x); } while (0) |
| 1606 | x = wrong_type_argument (Qnumber_or_marker_p, (x)); } while (0) | ||
| 1607 | 1627 | ||
| 1608 | #define CHECK_OVERLAY(x) \ | 1628 | #define CHECK_OVERLAY(x) \ |
| 1609 | do { if (!OVERLAYP ((x))) x = wrong_type_argument (Qoverlayp, (x));} while (0) | 1629 | CHECK_TYPE (OVERLAYP (x), Qoverlayp, x) |
| 1610 | 1630 | ||
| 1611 | /* Since we can't assign directly to the CAR or CDR fields of a cons | 1631 | /* Since we can't assign directly to the CAR or CDR fields of a cons |
| 1612 | cell, use these when checking that those fields contain numbers. */ | 1632 | cell, use these when checking that those fields contain numbers. */ |