diff options
| author | Richard M. Stallman | 1995-04-03 21:34:15 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 1995-04-03 21:34:15 +0000 |
| commit | d007f5c88942066223e6f8dc847771da917fa8c3 (patch) | |
| tree | 6ff6561aaad1944cb09c569fc9ae8b5aad7007e6 /src | |
| parent | 59f36b08082a7ef690cdcfe16fd9d5315ea4ad00 (diff) | |
| download | emacs-d007f5c88942066223e6f8dc847771da917fa8c3.tar.gz emacs-d007f5c88942066223e6f8dc847771da917fa8c3.zip | |
(oblookup): Save bucket num in oblookup_last_bucket_number.
(Funintern): New function.
(syms_of_lread): defsubr it.
Diffstat (limited to 'src')
| -rw-r--r-- | src/lread.c | 90 |
1 files changed, 82 insertions, 8 deletions
diff --git a/src/lread.c b/src/lread.c index 267db735404..62a57675d6b 100644 --- a/src/lread.c +++ b/src/lread.c | |||
| @@ -1569,6 +1569,16 @@ read_list (flag, readcharfun) | |||
| 1569 | Lisp_Object Vobarray; | 1569 | Lisp_Object Vobarray; |
| 1570 | Lisp_Object initial_obarray; | 1570 | Lisp_Object initial_obarray; |
| 1571 | 1571 | ||
| 1572 | /* oblookup stores the bucket number here, for the sake of Funintern. */ | ||
| 1573 | |||
| 1574 | int oblookup_last_bucket_number; | ||
| 1575 | |||
| 1576 | static int hash_string (); | ||
| 1577 | Lisp_Object oblookup (); | ||
| 1578 | |||
| 1579 | /* Get an error if OBARRAY is not an obarray. | ||
| 1580 | If it is one, return it. */ | ||
| 1581 | |||
| 1572 | Lisp_Object | 1582 | Lisp_Object |
| 1573 | check_obarray (obarray) | 1583 | check_obarray (obarray) |
| 1574 | Lisp_Object obarray; | 1584 | Lisp_Object obarray; |
| @@ -1583,8 +1593,8 @@ check_obarray (obarray) | |||
| 1583 | return obarray; | 1593 | return obarray; |
| 1584 | } | 1594 | } |
| 1585 | 1595 | ||
| 1586 | static int hash_string (); | 1596 | /* Intern the C string STR: return a symbol with that name, |
| 1587 | Lisp_Object oblookup (); | 1597 | interned in the current obarray. */ |
| 1588 | 1598 | ||
| 1589 | Lisp_Object | 1599 | Lisp_Object |
| 1590 | intern (str) | 1600 | intern (str) |
| @@ -1605,7 +1615,7 @@ intern (str) | |||
| 1605 | : make_string (str, len)), | 1615 | : make_string (str, len)), |
| 1606 | obarray); | 1616 | obarray); |
| 1607 | } | 1617 | } |
| 1608 | 1618 | ||
| 1609 | DEFUN ("intern", Fintern, Sintern, 1, 2, 0, | 1619 | DEFUN ("intern", Fintern, Sintern, 1, 2, 0, |
| 1610 | "Return the canonical symbol whose name is STRING.\n\ | 1620 | "Return the canonical symbol whose name is STRING.\n\ |
| 1611 | If there is none, one is created by this function and returned.\n\ | 1621 | If there is none, one is created by this function and returned.\n\ |
| @@ -1657,12 +1667,73 @@ it defaults to the value of `obarray'.") | |||
| 1657 | return tem; | 1667 | return tem; |
| 1658 | return Qnil; | 1668 | return Qnil; |
| 1659 | } | 1669 | } |
| 1670 | |||
| 1671 | DEFUN ("unintern", Funintern, Sunintern, 1, 2, 0, | ||
| 1672 | "Delete the symbol named NAME, if any, from OBARRAY.\n\ | ||
| 1673 | The value is t if a symbol was found and deleted, nil otherwise.\n\ | ||
| 1674 | NAME may be a string or a symbol. If it is a symbol, that symbol\n\ | ||
| 1675 | is deleted, if it belongs to OBARRAY--no other symbol is deleted.\n\ | ||
| 1676 | OBARRAY defaults to the value of the variable `obarray'.") | ||
| 1677 | (name, obarray) | ||
| 1678 | Lisp_Object name, obarray; | ||
| 1679 | { | ||
| 1680 | register Lisp_Object string, tem; | ||
| 1681 | int hash; | ||
| 1682 | |||
| 1683 | if (NILP (obarray)) obarray = Vobarray; | ||
| 1684 | obarray = check_obarray (obarray); | ||
| 1685 | |||
| 1686 | if (SYMBOLP (name)) | ||
| 1687 | XSETSTRING (string, XSYMBOL (name)->name); | ||
| 1688 | else | ||
| 1689 | { | ||
| 1690 | CHECK_STRING (name, 0); | ||
| 1691 | string = name; | ||
| 1692 | } | ||
| 1693 | |||
| 1694 | tem = oblookup (obarray, XSTRING (string)->data, XSTRING (string)->size); | ||
| 1695 | if (INTEGERP (tem)) | ||
| 1696 | return Qnil; | ||
| 1697 | /* If arg was a symbol, don't delete anything but that symbol itself. */ | ||
| 1698 | if (SYMBOLP (name) && !EQ (name, tem)) | ||
| 1699 | return Qnil; | ||
| 1700 | |||
| 1701 | hash = oblookup_last_bucket_number; | ||
| 1702 | |||
| 1703 | if (EQ (XVECTOR (obarray)->contents[hash], tem)) | ||
| 1704 | XSETSYMBOL (XVECTOR (obarray)->contents[hash], XSYMBOL (tem)->next); | ||
| 1705 | else | ||
| 1706 | { | ||
| 1707 | Lisp_Object tail, following; | ||
| 1708 | |||
| 1709 | for (tail = XVECTOR (obarray)->contents[hash]; | ||
| 1710 | XSYMBOL (tail)->next; | ||
| 1711 | tail = following) | ||
| 1712 | { | ||
| 1713 | XSETSYMBOL (following, XSYMBOL (tail)->next); | ||
| 1714 | if (EQ (following, tem)) | ||
| 1715 | { | ||
| 1716 | XSYMBOL (tail)->next = XSYMBOL (following)->next; | ||
| 1717 | break; | ||
| 1718 | } | ||
| 1719 | } | ||
| 1720 | } | ||
| 1721 | |||
| 1722 | return Qt; | ||
| 1723 | } | ||
| 1724 | |||
| 1725 | /* Return the symbol in OBARRAY whose names matches the string | ||
| 1726 | of SIZE characters at PTR. If there is no such symbol in OBARRAY, | ||
| 1727 | return nil. | ||
| 1728 | |||
| 1729 | Also store the bucket number in oblookup_last_bucket_number. */ | ||
| 1660 | 1730 | ||
| 1661 | Lisp_Object | 1731 | Lisp_Object |
| 1662 | oblookup (obarray, ptr, size) | 1732 | oblookup (obarray, ptr, size, hashp) |
| 1663 | Lisp_Object obarray; | 1733 | Lisp_Object obarray; |
| 1664 | register char *ptr; | 1734 | register char *ptr; |
| 1665 | register int size; | 1735 | register int size; |
| 1736 | int *hashp; | ||
| 1666 | { | 1737 | { |
| 1667 | int hash; | 1738 | int hash; |
| 1668 | int obsize; | 1739 | int obsize; |
| @@ -1679,14 +1750,16 @@ oblookup (obarray, ptr, size) | |||
| 1679 | hash = hash_string (ptr, size); | 1750 | hash = hash_string (ptr, size); |
| 1680 | hash %= obsize; | 1751 | hash %= obsize; |
| 1681 | bucket = XVECTOR (obarray)->contents[hash]; | 1752 | bucket = XVECTOR (obarray)->contents[hash]; |
| 1753 | oblookup_last_bucket_number = hash; | ||
| 1682 | if (XFASTINT (bucket) == 0) | 1754 | if (XFASTINT (bucket) == 0) |
| 1683 | ; | 1755 | ; |
| 1684 | else if (!SYMBOLP (bucket)) | 1756 | else if (!SYMBOLP (bucket)) |
| 1685 | error ("Bad data in guts of obarray"); /* Like CADR error message */ | 1757 | error ("Bad data in guts of obarray"); /* Like CADR error message */ |
| 1686 | else for (tail = bucket; ; XSETSYMBOL (tail, XSYMBOL (tail)->next)) | 1758 | else |
| 1759 | for (tail = bucket; ; XSETSYMBOL (tail, XSYMBOL (tail)->next)) | ||
| 1687 | { | 1760 | { |
| 1688 | if (XSYMBOL (tail)->name->size == size && | 1761 | if (XSYMBOL (tail)->name->size == size |
| 1689 | !bcmp (XSYMBOL (tail)->name->data, ptr, size)) | 1762 | && !bcmp (XSYMBOL (tail)->name->data, ptr, size)) |
| 1690 | return tail; | 1763 | return tail; |
| 1691 | else if (XSYMBOL (tail)->next == 0) | 1764 | else if (XSYMBOL (tail)->next == 0) |
| 1692 | break; | 1765 | break; |
| @@ -1713,7 +1786,7 @@ hash_string (ptr, len) | |||
| 1713 | } | 1786 | } |
| 1714 | return hash & 07777777777; | 1787 | return hash & 07777777777; |
| 1715 | } | 1788 | } |
| 1716 | 1789 | ||
| 1717 | void | 1790 | void |
| 1718 | map_obarray (obarray, fn, arg) | 1791 | map_obarray (obarray, fn, arg) |
| 1719 | Lisp_Object obarray; | 1792 | Lisp_Object obarray; |
| @@ -2028,6 +2101,7 @@ syms_of_lread () | |||
| 2028 | defsubr (&Sread_from_string); | 2101 | defsubr (&Sread_from_string); |
| 2029 | defsubr (&Sintern); | 2102 | defsubr (&Sintern); |
| 2030 | defsubr (&Sintern_soft); | 2103 | defsubr (&Sintern_soft); |
| 2104 | defsubr (&Sunintern); | ||
| 2031 | defsubr (&Sload); | 2105 | defsubr (&Sload); |
| 2032 | defsubr (&Seval_buffer); | 2106 | defsubr (&Seval_buffer); |
| 2033 | defsubr (&Seval_region); | 2107 | defsubr (&Seval_region); |