[Rd] Different behavior of the "showArgs" example (R extension manual) between gcc and Visual C++ compiled code

From: <Jean-Michel.Perraud_at_csiro.au>
Date: Mon, 10 Sep 2012 09:51:54 +1000


Hi,

I am trying to implement on a Win7 box the showArgs example of section 5.10.2 "Calling .External" of the R extension manual. I am using interchangeably gcc (RTools) and Visual C++ (via Makefile.win) to build a package. I get a couple of runtime oddities when the dll compiled with Visual C++. I'd value comments, observations and tips from interested readers. I tried my best to find proper compilation settings for VCPP, from a variety of source incl. Duncan Murdoch's advice.

Cheers,
J-M

OBSERVATIONS



1/ The for() loop does not hit the termination condition on args being R_NilValue, and ends up stuck on pointers as shown below, equality never reached.
		args	0x020e24a0	SEXPREC *
		R_NilValue	0x835425ff	SEXPREC *
2/ If I force it out of the endless loop, after the function returns, I get a nasty "Unhandled exception at 0x6c799419 in Rgui: 0xC0000005: Access violation writing location 0x0009eee9." with a call stack as follow. I did check that the cdecl calling convention is used.
	R.dll!6c799419() 	
 	[Frames below may be incorrect and/or missing, no symbols loaded for R.dll]	
 	R.dll!6c797736() 	
 	user32.dll!7633cd90() 	
 	user32.dll!7636c1c2() 	
 	Rgraphapp.dll!63551cba() 	

CODE



// R code

library(showArgs)
blah = as.Date('2000-01-01')
printArgs(a=1:3, b=LETTERS[1:3], blah=blah)
// END R code

// C/Cpp code:

extern "C" { // because I compile the code 'as C++' for Visual C++, for in-code variable declaration

        SEXP __cdecl showArgs_ext(SEXP args);
}

SEXP __cdecl showArgs_ext(SEXP args)
{
// snip

	args = CDR(args); /* skip 'name' */
	for(int i = 0; args != R_NilValue; i++, args = CDR(args)) {
		// verbatim from the manual
	}
	return R_NilValue;

}
// END C/Cpp code

Vcc Compilation settings:
/I"C:\bin\R\R\include" /ZI /nologo /W3 /WX- /Od /Oy- /D "_WINDLL" /D "_MBCS" /Gm /EHsc /RTC1 /GS /fp:precise /Za /Zc:wchar_t /Zc:forScope /Fp"Debug\showArgs.pch" /Fa"Debug\" /Fo"Debug\" /Fd"Debug\vc100.pdb" /Gd /TP /analyze- /errorReport:queue

/OUT:"C:\XXXX\Debug\showArgs.dll" /NOLOGO /LIBPATH:"C:\bin\R\R\bin\i386" /DLL "Rdll.lib" "kernel32.lib" "user32.lib" "gdi32.lib" "winspool.lib" "comdlg32.lib" "advapi32.lib" "shell32.lib" "ole32.lib" "oleaut32.lib" "uuid.lib" "odbc32.lib" "odbccp32.lib" /DEF:"showArgs-win.def" /MANIFEST /ManifestFile:"Debug\showArgs.dll.intermediate.manifest" /ALLOWISOLATION /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /DEBUG /PDB:"C:\XXXX\Debug\showArgs.pdb" /PGD:"C:\XXXX\Debug\showArgs.pgd" /TLBID:1 /DYNAMICBASE /NXCOMPAT /MACHINE:X86 /ERRORREPORT:QUEUE

ENVIRONMENT



R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Tue 11 Sep 2012 - 08:08:25 GMT

This quarter's messages: by month, or sorted: [ by date ] [ by thread ] [ by subject ] [ by author ]

All messages

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 11 Sep 2012 - 14:10:42 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.

list of date sections of archive