Mercurial > hg > xemacs-beta
comparison src/eval.c @ 617:af57a77cbc92
[xemacs-hg @ 2001-06-18 07:09:50 by ben]
---------------------------------------------------------------
DOCUMENTATION FIXES:
---------------------------------------------------------------
eval.c: Correct documentation.
elhash.c: Doc correction.
---------------------------------------------------------------
LISP OBJECT CLEANUP:
---------------------------------------------------------------
bytecode.h, buffer.h, casetab.h, chartab.h, console-msw.h, console.h, database.c, device.h, eldap.h, elhash.h, events.h, extents.h, faces.h, file-coding.h, frame.h, glyphs.h, gui-x.h, gui.h, keymap.h, lisp-disunion.h, lisp-union.h, lisp.h, lrecord.h, lstream.h, mule-charset.h, objects.h, opaque.h, postgresql.h, process.h, rangetab.h, specifier.h, toolbar.h, tooltalk.h, ui-gtk.h: Add wrap_* to all objects (it was already there for a few of them)
-- an expression to encapsulate a pointer into a Lisp object,
rather than the inconvenient XSET*. "wrap" was chosen because
"make" as in make_int(), make_char() is not appropriate. (It
implies allocation. The issue does not exist for ints and chars
because they are not allocated.)
Full error checking has been added to these expressions. When
used without error checking, non-union build, use of these
expressions will incur no loss of efficiency. (In fact, XSET* is
now defined in terms of wrap_* in a non-union build.) In a union
build, you will also get no loss of efficiency provided that you
have a decent optimizing compiler, and a compiler that either
understands inlines or automatically inlines those particular
functions. (And since people don't normally do their production
builds on union, it doesn't matter.)
Update the sample Lisp object definition in lrecord.h accordingly.
dumper.c: Fix places in dumper that referenced wrap_object to reference
its new name, wrap_pointer_1.
buffer.c, bufslots.h, conslots.h, console.c, console.h, devslots.h, device.c, device.h, frame.c, frame.h, frameslots.h, window.c, window.h, winslots.h: -- Extract out the Lisp objects of `struct device' into devslots.h,
just like for the other structures.
-- Extract out the remaining (not copied into the window config)
Lisp objects in `struct window' into winslots.h; use different
macros (WINDOW_SLOT vs. WINDOW_SAVED_SLOT) to differentiate them.
-- Eliminate the `dead' flag of `struct frame', since it
duplicates information already available in `framemeths', and fix
FRAME_LIVE_P accordingly. (Devices and consoles already work this
way.)
-- In *slots.h, switch to system where MARKED_SLOT is automatically
undef'd at the end of the file. (Follows what winslots.h already
does.)
-- Update the comments at the beginning of *slots.h to be accurate.
-- When making any of the above objects dead, zero it out entirely
and reset all Lisp object slots to Qnil. (We were already doing
this somewhat, but not consistently.) This (1) Eliminates the
possibility of extra objects hanging around that ought to be
GC'd, (2) Causes an immediate crash if anyone tries to access a
structure in one of these objects, (3) Ensures consistent behavior
wrt dead objects.
dialog-msw.c: Use internal_object_printer, since this object should not escape.
---------------------------------------------------------------
FIXING A CRASH THAT I HIT ONCE (AND A RELATED BAD BEHAVIOR):
---------------------------------------------------------------
eval.c: Fix up some comments about the FSF implementation.
Fix two nasty bugs:
(1) condition_case_unwind frees the conses sitting in the
catch->tag slot too quickly, resulting in a crash that I hit.
(2) catches need to be unwound one at a time when calling
unwind-protect code, rather than all at once at the end; otherwise,
incorrect behavior can result. (A comment shows exactly how.)
backtrace.h: Improve comment about FSF differences in the handler stack.
---------------------------------------------------------------
FIXING A CRASH THAT I REPEATEDLY HIT WHEN USING THE MOUSE WHEEL
UNDER MSWINDOWS:
---------------------------------------------------------------
Basic idea: My crash is due either to a dead, non-marked,
GC-collected frame inside of a window mirror, or a prematurely
freed window mirror. We need to mark the Lisp objects inside of
window mirrors. Tracking the lifespan of window mirrors and
scrollbar instances is extremely hard, and there may well be
lurking bugs where such objects are freed too soon. The only safe
way to fix these problems (and it fixes both problems at once) is
to make both of these structures Lisp objects.
lrecord.h, emacs.c, inline.c, scrollbar-gtk.c, scrollbar-msw.c, scrollbar-x.c, scrollbar.c, scrollbar.h, symsinit.h: Make scrollbar instances actual Lisp objects. Mark the window
mirrors in them. inline.c needs to know about scrollbar.h now.
Record the new type in lrecord.h. Fix up scrollbar-*.c
appropriately. Create a hash table in scrollbar-msw.c so that the
scrollbar instances stored in scrollbar HWND's are properly
GC-protected. Create complex_vars_of_scrollbar_mswindows() to
create the hash table at startup, and call it from emacs.c. Don't
store the scrollbar instance as a property of the GTK scrollbar,
as it's not used and if we did this, we'd have to separately
GC-protect it in a hash table, like in MS Windows.
lrecord.h, frame.h, frame.c, frameslots.h, redisplay.c, window.c, window.h: Move mark_window_mirror from redisplay.c to window.c. Make window
mirrors actual Lisp objects. Tell lrecord.h about them. Change
the window mirror member of struct frame from a pointer to a Lisp
object, and add XWINDOW_MIRROR in appropriate places. Mark the
scrollbar instances in the window mirror.
redisplay.c, redisplay.h, alloc.c: Delete mark_redisplay. Don't call mark_redisplay. We now mark
frame-specific structures in mark_frame.
NOTE: I also deleted an extremely questionable call to
update_frame_window_mirrors(). It was extremely questionable
before, and now totally impossible, since it will create
Lisp objects during redisplay.
frame.c: Mark the scrollbar instances, which are now Lisp objects.
Call mark_gutter() here, not in mark_redisplay().
gutter.c: Update comments about correct marking.
---------------------------------------------------------------
ISSUES BROUGHT UP BY MARTIN:
---------------------------------------------------------------
buffer.h: Put back these macros the way Steve T and I think they ought to be.
I already explained in a previous changelog entry why I think these
macros should be the way I'd defined them. Once again:
We fix these macros so they don't care about the type of their
lvalues. The non-C-string equivalents of these already function
in the same way, and it's correct because it should be OK to pass
in a CBufbyte *, a BufByte *, a Char_Binary *, an UChar_Binary *,
etc. The whole reason for these different types is to work around
errors caused by signed-vs-unsigned non-matching types. Any
possible error that might be caught in a DFC macro would also be
caught wherever the argument is used elsewhere. So creating
multiple macro versions would add no useful error-checking and
just further complicate an already complicated area.
As for Martin's "ANSI aliasing" bug, XEmacs is not ANSI-aliasing
clean and probably never will be. Unless the board agrees to
change XEmacs in this way (and we really don't want to go down
that road), this is not a bug.
sound.h: Undo Martin's type change.
signal.c: Fix problem identified by Martin with Linux and g++ due to
non-standard declaration of setitimer().
systime.h: Update the docs for "qxe_" to point out why making the
encapsulation explicit is always the right way to go. (setitimer()
itself serves as an example.)
For 21.4:
update-elc-2.el: Correct misplaced parentheses, making lisp/mule not get
recompiled.
author | ben |
---|---|
date | Mon, 18 Jun 2001 07:10:32 +0000 |
parents | 13e3d7ae7155 |
children | b39c14581166 |
comparison
equal
deleted
inserted
replaced
616:4f1c7a4ac1e6 | 617:af57a77cbc92 |
---|---|
1341 This is used for correct unwinding in Fthrow and Fsignal. */ | 1341 This is used for correct unwinding in Fthrow and Fsignal. */ |
1342 | 1342 |
1343 static void | 1343 static void |
1344 unwind_to_catch (struct catchtag *c, Lisp_Object val) | 1344 unwind_to_catch (struct catchtag *c, Lisp_Object val) |
1345 { | 1345 { |
1346 #if 0 /* FSFmacs */ | |
1347 /* #### */ | |
1348 REGISTER int last_time; | 1346 REGISTER int last_time; |
1349 #endif | |
1350 | 1347 |
1351 /* Unwind the specbind, catch, and handler stacks back to CATCH | 1348 /* Unwind the specbind, catch, and handler stacks back to CATCH |
1352 Before each catch is discarded, unbind all special bindings | 1349 Before each catch is discarded, unbind all special bindings |
1353 and execute all unwind-protect clauses made above that catch. | 1350 and execute all unwind-protect clauses made above that catch. |
1354 At the end, restore some static info saved in CATCH, | 1351 At the end, restore some static info saved in CATCH, |
1363 #if 0 /* FSFmacs */ | 1360 #if 0 /* FSFmacs */ |
1364 /* Restore the polling-suppression count. */ | 1361 /* Restore the polling-suppression count. */ |
1365 set_poll_suppress_count (catch->poll_suppress_count); | 1362 set_poll_suppress_count (catch->poll_suppress_count); |
1366 #endif | 1363 #endif |
1367 | 1364 |
1368 #if 0 /* FSFmacs */ | 1365 #if 1 |
1369 /* #### FSFmacs has the following loop. Is it more correct? */ | |
1370 do | 1366 do |
1371 { | 1367 { |
1372 last_time = catchlist == c; | 1368 last_time = catchlist == c; |
1373 | 1369 |
1374 /* Unwind the specpdl stack, and then restore the proper set of | 1370 /* Unwind the specpdl stack, and then restore the proper set of |
1375 handlers. */ | 1371 handlers. */ |
1376 unbind_to (catchlist->pdlcount, Qnil); | 1372 unbind_to (catchlist->pdlcount, Qnil); |
1377 handlerlist = catchlist->handlerlist; | |
1378 catchlist = catchlist->next; | 1373 catchlist = catchlist->next; |
1379 #ifdef ERROR_CHECK_TYPECHECK | 1374 #ifdef ERROR_CHECK_TYPECHECK |
1380 check_error_state_sanity (); | 1375 check_error_state_sanity (); |
1381 #endif | 1376 #endif |
1382 } | 1377 } |
1383 while (! last_time); | 1378 while (! last_time); |
1384 #else /* Actual XEmacs code */ | 1379 #else |
1380 /* Former XEmacs code. This is definitely not as correct because | |
1381 there may be a number of catches we're unwinding, and a number | |
1382 of unwind-protects in the process. By not undoing the catches till | |
1383 the end, there may be invalid catches still current. (This would | |
1384 be a particular problem with code like this: | |
1385 | |
1386 (catch 'foo | |
1387 (call-some-code-which-does... | |
1388 (catch 'bar | |
1389 (unwind-protect | |
1390 (call-some-code-which-does... | |
1391 (catch 'bar | |
1392 (call-some-code-which-does... | |
1393 (throw 'foo nil)))) | |
1394 (throw 'bar nil))))) | |
1395 | |
1396 This would try to throw to the inner (catch 'bar)! | |
1397 | |
1398 --ben | |
1399 */ | |
1385 /* Unwind the specpdl stack */ | 1400 /* Unwind the specpdl stack */ |
1386 unbind_to (c->pdlcount, Qnil); | 1401 unbind_to (c->pdlcount, Qnil); |
1387 catchlist = c->next; | 1402 catchlist = c->next; |
1388 #ifdef ERROR_CHECK_TYPECHECK | 1403 #ifdef ERROR_CHECK_TYPECHECK |
1389 check_error_state_sanity (); | 1404 check_error_state_sanity (); |
1390 #endif | 1405 #endif |
1391 #endif | 1406 #endif /* Former code */ |
1392 | 1407 |
1393 gcprolist = c->gcpro; | 1408 gcprolist = c->gcpro; |
1394 backtrace_list = c->backlist; | 1409 backtrace_list = c->backlist; |
1395 lisp_eval_depth = c->lisp_eval_depth; | 1410 lisp_eval_depth = c->lisp_eval_depth; |
1396 | 1411 |
1502 /************************************************************************/ | 1517 /************************************************************************/ |
1503 | 1518 |
1504 static Lisp_Object | 1519 static Lisp_Object |
1505 condition_bind_unwind (Lisp_Object loser) | 1520 condition_bind_unwind (Lisp_Object loser) |
1506 { | 1521 { |
1522 /* There is no problem freeing stuff here like there is in | |
1523 condition_case_unwind(), because there are no outside pointers | |
1524 (like the tag below in the catchlist) pointing to the objects. */ | |
1507 Lisp_Cons *victim; | 1525 Lisp_Cons *victim; |
1508 /* ((handler-fun . handler-args) ... other handlers) */ | 1526 /* ((handler-fun . handler-args) ... other handlers) */ |
1509 Lisp_Object tem = XCAR (loser); | 1527 Lisp_Object tem = XCAR (loser); |
1510 | 1528 |
1511 while (CONSP (tem)) | 1529 while (CONSP (tem)) |
1524 } | 1542 } |
1525 | 1543 |
1526 static Lisp_Object | 1544 static Lisp_Object |
1527 condition_case_unwind (Lisp_Object loser) | 1545 condition_case_unwind (Lisp_Object loser) |
1528 { | 1546 { |
1529 Lisp_Cons *victim; | |
1530 | |
1531 /* ((<unbound> . clauses) ... other handlers */ | 1547 /* ((<unbound> . clauses) ... other handlers */ |
1532 victim = XCONS (XCAR (loser)); | 1548 /* NO! Doing this now leaves the tag deleted in a still-active |
1533 free_cons (victim); | 1549 catch. With the recent changes to unwind_to_catch(), the |
1534 | 1550 evil situation might not happen any more; it certainly could |
1535 victim = XCONS (loser); | 1551 happen before because it did. But it's very precarious to rely |
1552 on something like this. #### Instead we should rewrite, adopting | |
1553 the FSF's mechanism with a struct handler instead of | |
1554 Vcondition_handlers; then we have NO Lisp-object structures used | |
1555 to hold all of the values, and there's no possibility either of | |
1556 crashes from freeing objects too quickly, or objects not getting | |
1557 freed and hanging around till the next GC. | |
1558 | |
1559 In practice, the extra consing here should not matter because | |
1560 it only happens when we throw past the condition-case, which almost | |
1561 always is the result of an error. Most of the time, there will be | |
1562 no error, and we will free the objects below in the main function. | |
1563 | |
1564 --ben | |
1565 | |
1566 DO NOT DO: free_cons (XCAR (loser)); | |
1567 */ | |
1568 | |
1536 if (EQ (loser, Vcondition_handlers)) /* may have been rebound to some tail */ | 1569 if (EQ (loser, Vcondition_handlers)) /* may have been rebound to some tail */ |
1537 Vcondition_handlers = victim->cdr; | 1570 Vcondition_handlers = XCDR (loser); |
1538 | 1571 |
1539 free_cons (victim); | 1572 /* DO NOT DO: free_cons (loser); */ |
1540 return Qnil; | 1573 return Qnil; |
1541 } | 1574 } |
1542 | 1575 |
1543 /* Split out from condition_case_3 so that primitive C callers | 1576 /* Split out from condition_case_3 so that primitive C callers |
1544 don't have to cons up a lisp handler form to be evaluated. */ | 1577 don't have to cons up a lisp handler form to be evaluated. */ |
1597 Lisp_Object (*hfun) (Lisp_Object val, Lisp_Object harg), | 1630 Lisp_Object (*hfun) (Lisp_Object val, Lisp_Object harg), |
1598 Lisp_Object harg) | 1631 Lisp_Object harg) |
1599 { | 1632 { |
1600 int speccount = specpdl_depth(); | 1633 int speccount = specpdl_depth(); |
1601 struct catchtag c; | 1634 struct catchtag c; |
1602 struct gcpro gcpro1; | 1635 struct gcpro gcpro1, gcpro2, gcpro3; |
1603 | 1636 |
1604 #if 0 /* FSFmacs */ | 1637 #if 0 /* FSFmacs */ |
1605 c.tag = Qnil; | 1638 c.tag = Qnil; |
1606 #else | 1639 #else |
1607 /* Do consing now so out-of-memory error happens up front */ | 1640 /* Do consing now so out-of-memory error happens up front */ |
1608 /* (unbound . stuff) is a special condition-case kludge marker | 1641 /* (unbound . stuff) is a special condition-case kludge marker |
1609 which is known specially by Fsignal. | 1642 which is known specially by Fsignal. |
1610 This is an abomination, but to fix it would require either | 1643 [[ This is an abomination, but to fix it would require either |
1611 making condition_case cons (a union of the conditions of the clauses) | 1644 making condition_case cons (a union of the conditions of the clauses) |
1612 or changing the byte-compiler output (no thanks). */ | 1645 or changing the byte-compiler output (no thanks).]] |
1646 | |
1647 The above comment is clearly wrong. FSF does not do it this way | |
1648 and did not change the byte-compiler output. Instead they use a | |
1649 `struct handler' to hold the various values (in place of our | |
1650 Vcondition_handlers) and chain them together, with pointers from | |
1651 the `struct catchtag' to the `struct handler'. We should perhaps | |
1652 consider moving to something similar, but not before I merge my | |
1653 stderr-proc workspace, which contains changes to these | |
1654 functions. --ben */ | |
1613 c.tag = noseeum_cons (noseeum_cons (Qunbound, handlers), | 1655 c.tag = noseeum_cons (noseeum_cons (Qunbound, handlers), |
1614 Vcondition_handlers); | 1656 Vcondition_handlers); |
1615 #endif | 1657 #endif |
1616 c.val = Qnil; | 1658 c.val = Qnil; |
1617 c.backlist = backtrace_list; | 1659 c.backlist = backtrace_list; |
1645 handlerlist = &h; | 1687 handlerlist = &h; |
1646 #else | 1688 #else |
1647 Vcondition_handlers = c.tag; | 1689 Vcondition_handlers = c.tag; |
1648 #endif | 1690 #endif |
1649 GCPRO1 (harg); /* Somebody has to gc-protect */ | 1691 GCPRO1 (harg); /* Somebody has to gc-protect */ |
1650 | |
1651 c.val = ((*bfun) (barg)); | 1692 c.val = ((*bfun) (barg)); |
1652 | |
1653 /* The following is *not* true: (ben) | |
1654 | |
1655 ungcpro, restoring catchlist and condition_handlers are actually | |
1656 redundant since unbind_to now restores them. But it looks funny not to | |
1657 have this code here, and it doesn't cost anything, so I'm leaving it.*/ | |
1658 UNGCPRO; | 1693 UNGCPRO; |
1694 | |
1695 /* Once we change `catchlist' below, the stuff in c will not be GCPRO'd. */ | |
1696 GCPRO3 (harg, c.val, c.tag); | |
1697 | |
1659 catchlist = c.next; | 1698 catchlist = c.next; |
1660 #ifdef ERROR_CHECK_TYPECHECK | 1699 #ifdef ERROR_CHECK_TYPECHECK |
1661 check_error_state_sanity (); | 1700 check_error_state_sanity (); |
1662 #endif | 1701 #endif |
1702 /* Note: The unbind also resets Vcondition_handlers. Maybe we should | |
1703 delete this here. */ | |
1663 Vcondition_handlers = XCDR (c.tag); | 1704 Vcondition_handlers = XCDR (c.tag); |
1664 | 1705 unbind_to (speccount, Qnil); |
1665 return unbind_to (speccount, c.val); | 1706 |
1707 UNGCPRO; | |
1708 /* free the conses *after* the unbind, because the unbind will run | |
1709 condition_case_unwind above. */ | |
1710 free_cons (XCONS (XCAR (c.tag))); | |
1711 free_cons (XCONS (c.tag)); | |
1712 return c.val; | |
1666 } | 1713 } |
1667 | 1714 |
1668 static Lisp_Object | 1715 static Lisp_Object |
1669 run_condition_case_handlers (Lisp_Object val, Lisp_Object var) | 1716 run_condition_case_handlers (Lisp_Object val, Lisp_Object var) |
1670 { | 1717 { |
3601 return make_int (argcount); | 3648 return make_int (argcount); |
3602 } | 3649 } |
3603 } | 3650 } |
3604 | 3651 |
3605 DEFUN ("function-min-args", Ffunction_min_args, 1, 1, 0, /* | 3652 DEFUN ("function-min-args", Ffunction_min_args, 1, 1, 0, /* |
3606 Return the number of arguments a function may be called with. | 3653 Return the minimum number of arguments a function may be called with. |
3607 The function may be any form that can be passed to `funcall', | 3654 The function may be any form that can be passed to `funcall', |
3608 any special form, or any macro. | 3655 any special form, or any macro. |
3609 */ | 3656 */ |
3610 (function)) | 3657 (function)) |
3611 { | 3658 { |
3612 return function_argcount (function, 1); | 3659 return function_argcount (function, 1); |
3613 } | 3660 } |
3614 | 3661 |
3615 DEFUN ("function-max-args", Ffunction_max_args, 1, 1, 0, /* | 3662 DEFUN ("function-max-args", Ffunction_max_args, 1, 1, 0, /* |
3616 Return the number of arguments a function may be called with. | 3663 Return the maximum number of arguments a function may be called with. |
3617 The function may be any form that can be passed to `funcall', | 3664 The function may be any form that can be passed to `funcall', |
3618 any special form, or any macro. | 3665 any special form, or any macro. |
3619 If the function takes an arbitrary number of arguments or is | 3666 If the function takes an arbitrary number of arguments or is |
3620 a built-in special form, nil is returned. | 3667 a built-in special form, nil is returned. |
3621 */ | 3668 */ |