Bug 14367 - Suspect code in do_gettext()
Summary: Suspect code in do_gettext()
Status: CLOSED INVALID
Alias: None
Product: R
Classification: Unclassified
Component: Misc (show other bugs)
Version: R 2.11.1
Hardware: All All
: P5 minor
Assignee: R-core
URL:
Depends on:
Blocks:
 
Reported: 2010-08-25 13:40 UTC by Andrew Runnalls
Modified: 2010-08-31 12:03 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Andrew Runnalls 2010-08-25 13:40:14 UTC
The function do_gettext() in errors.c uses the following loop in the course of determining the default translation domain:

836	RCNTXT *cptr;
837	SEXP rho = R_BaseEnv;
838	for (cptr = R_GlobalContext->nextcontext;
839	     cptr != NULL && cptr->callflag != CTXT_TOPLEVEL;
840	     cptr = cptr->nextcontext)
841	    if (cptr->callflag & CTXT_FUNCTION) {
842		/* stop() etc have internal call to .makeMessage */
843		cfn = CHAR(STRING_ELT(deparse1s(CAR(cptr->call)), 0));
844		if(streql(cfn, "stop") || streql(cfn, "warning")
845		   || streql(cfn, "message")) continue;
846		rho = cptr->cloenv;
847	    }

(Line numbers are from the latest svn revision, 52104)

Note that execution continues round the for-loop even after rho has been assigned at line 846.  Is this really the intention?  I note that the corresponding code in do_ngettext() breaks out of the loop at this point.

Apologies if this is a red herring.

Andrew Runnalls
Comment 1 Brian Ripley 2010-08-31 12:03:50 UTC
Yes, it was intentional.

The comment explains why: it needs to get the outermost call
(and ngettext() does not get used where there is likely to be more than one).