[Rd] Calling erf function in package NORMT3 produce a R crash on Linux/AMD opteron (PR#9683)
Full_Name: Benjamin Leblanc Version: 2.4.1 and 2.5.0 OS: Ubuntu Linux 7.04 AMD64 Submission from: (NULL) (195.83.84.213) Here is an example script that may crash under R with Linux AMD 64 bit platforms library('NORMT3') a <- 1:1000/1000 erf(a) I did several tests: - opensuse 10.2 x86_64 with R 2.4.1 and R 2.5.0, produce systematically a frozen R session - ubuntu 7.04 AMD64, R 2.4.1 and R version 2.5.0 (2007-04-23), produce a memory corruption Here is an example with core dump on ubuntu 7.04 AMD64, R version 2.5.0 (2007-04-23): > a <- 1:100/200 > erf(a) *** glibc detected *** /usr/lib/R/bin/exec/R: malloc(): memory corruption: 0x01308500 *** === Backtrace: = /lib/libc.so.6[0x2b0cc3b9f1d1] /lib/libc.so.6(__libc_malloc+0x7d)[0x2b0cc3ba098d] /usr/lib/R/lib/libR.so(Rf_allocVector+0x4cc)[0x2b0cc36e9c3c] /usr/lib/R/lib/libR.so[0x2b0cc368d42b] /usr/lib/R/lib/libR.so(Rf_eval+0x6ea)[0x2b0cc36bfb6a] /usr/lib/R/lib/libR.so[0x2b0cc36c2370] /usr/lib/R/lib/libR.so(Rf_eval+0x48b)[0x2b0cc36bf90b] /usr/lib/R/lib/libR.so[0x2b0cc36c0ca2] /usr/lib/R/lib/libR.so(Rf_eval+0x48b)[0x2b0cc36bf90b] /usr/lib/R/lib/libR.so(Rf_applyClosure+0x286)[0x2b0cc36c2be6] /usr/lib/R/lib/libR.so(Rf_eval+0x2f4)[0x2b0cc36bf774] /usr/lib/R/lib/libR.so[0x2b0cc36c0618] /usr/lib/R/lib/libR.so(Rf_eval+0x552)[0x2b0cc36bf9d2] /usr/lib/R/lib/libR.so(Rf_applyClosure+0x286)[0x2b0cc36c2be6] /usr/lib/R/lib/libR.so(Rf_eval+0x2f4)[0x2b0cc36bf774] /usr/lib/R/lib/libR.so(Rf_ReplIteration+0x2de)[0x2b0cc36e2f4e] /usr/lib/R/lib/libR.so(run_Rmainloop+0xc2)[0x2b0cc36e3112] /usr/lib/R/bin/exec/R(main+0x1b)[0x40088b] /lib/libc.so.6(__libc_start_main+0xf4)[0x2b0cc3b4c8e4] /usr/lib/R/bin/exec/R[0x4007aa] === Memory map: 0040-00401000 r-xp 08:02 8669401 /usr/lib/R/bin/exec/R 0050-00501000 rw-p 08:02 8669401 /usr/lib/R/bin/exec/R 00501000-01b4b000 rw-p 00501000 00:00 0 [heap] 2b0cc33e2000-2b0cc33fe000 r-xp 08:02 14549011 /lib/ld-2.5.so 2b0cc33fe000-2b0cc3401000 rw-p 2b0cc33fe000 00:00 0 2b0cc35fd000-2b0cc35ff000 rw-p 0001b000 08:02 14549011 /lib/ld-2.5.so 2b0cc35ff000-2b0cc384b000 r-xp 08:02 8669405 /usr/lib/R/lib/libR.so 2b0cc384b000-2b0cc394b000 ---p 0024c000 08:02 8669405 /usr/lib/R/lib/libR.so 2b0cc394b000-2b0cc395e000 rw-p 0024c000 08:02 8669405 /usr/lib/R/lib/libR.so 2b0cc395e000-2b0cc39f8000 rw-p 2b0cc395e000 00:00 0 2b0cc39f8000-2b0cc3a23000 r-xp 08:02 8669404 /usr/lib/R/lib/libRblas.so 2b0cc3a23000-2b0cc3b22000 ---p 0002b000 08:02 8669404 /usr/lib/R/lib/libRblas.so 2b0cc3b22000-2b0cc3b23000 rw-p 0002a000 08:02 8669404 /usr/lib/R/lib/libRblas.so 2b0cc3b23000-2b0cc3b24000 r--p 08:02 8028234 /usr/lib/locale/fr_FR.utf8/LC_MESSAGES/SYS_LC_MESSAGES 2b0cc3b24000-2b0cc3b2b000 r--s 08:02 9273579 /usr/lib/gconv/gconv-modules.cache 2b0cc3b2f000-2b0cc3c76000 r-xp 08:02 14549029 /lib/libc-2.5.so 2b0cc3c76000-2b0cc3e76000 ---p 00147000 08:02 14549029 /lib/libc-2.5.so 2b0cc3e76000-2b0cc3e79000 r--p 00147000 08:02 14549029 /lib/libc-2.5.so 2b0cc3e79000-2b0cc3e7b000 rw-p 0014a000 08:02 14549029 /lib/libc-2.5.so 2b0cc3e7b000-2b0cc3e8 rw-p 2b0cc3e7b000 00:00 0 2b0cc3e8-2b0cc3f19000 r-xp 08:02 11288626 /usr/lib/libgfortran.so.1.0.0 2b0cc3f19000-2b0cc4118000 ---p 00099000 08:02 11288626 /usr/lib/libgfortran.so.1.0.0 2b0cc4118000-2b0cc411a000 rw-p 00098000 08:02 11288626 /usr/lib/libgfortran.so.1.0.0 2b0cc411a000-2b0cc411b000 rw-p 2b0cc411a000 00:00 0 2b0cc411b000-2b0cc419c000 r-xp 08:02 14549060 /lib/libm-2.5.so 2b0cc419c000-2b0cc439b000 ---p 00081000 08:02 14549060 /lib/libm-2.5.so 2b0cc439b000-2b0cc439d000 rw-p 0008 08:02 14549060 /lib/libm-2.5.so 2b0cc439d000-2b0cc43aa000 r-xp 08:02 14549054 /lib/libgcc_s.so.1 2b0cc43aa000-2b0cc45aa000 ---p d000 08:02 14549054 /lib/libgcc_s.so.1 2b0cc45aa000-2b0cc45ab000 rw-p d000 08:02 14549054 /lib/libgcc_s.so.1 2b0cc45ab000-2b0cc45e1000 r-xp 08:02 14549102 /lib/libreadline.so.5.2 2b0cc45e1000-2b0cc47e1000 ---p 00036000 08:02 14549102 /lib/libreadline.soAbandon (core dumped) __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
[Rd] File and console output does not work in C code
Hello all, I am getting into trouble when trying to do standard I/O from a C function called within R environment. This function is written in a small C library that is loaded whith dyn.load() and called in R via the .C() interface. I need to debug the C code using a text file for some logs, and also to speed up its result visualization by creating images on the fly using the GD library. Both of these outputs require to write into files from this C function. Allthough everything goes smoothly from compilation and linking to execution into R without errors, no file is created. I have also tried to do some simple printf(), Rprintf() and REprintf() but even that didn't gave me any visible output. Am I missing something trivial? Could anyone give me a hint on why it does not work? Best regards, Benjamin -- Chromatin and Cell Biology Lab. Institute for Human Genetics 141, rue de la Cardonille F-34396 Montpellier France Phone +33-(0)4 99 61 99 51 FAX +33-(0)4 99 61 99 01 __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] File and console output does not work in C code
Here are more specific details: I use GNU/Linux Ubuntu 8.04 on an x86_64 workstation. R environnement was compiled from 2.8.0 sources. Below is a part of my C code to test the file I/O. When compiled as a standalone executable it prints "Test1" on the console and generates "test.txt" and "test.png" file outputs as expected. When compiled as a shared library and invoked from R environment via .C() interface, it does nothing (to avoid any file access issue, file permissions were set to 777 in the "/test" output folder). Am I missing a configuration option? Thanks for your help, #include #include #include #include // -- void c_bricks(double *x, int *nx, int *nw, double *gamma, double *Piw, double *V, double *W) { fflush(stdout); printf("Test %10d\n", 1); Rprintf("Test %10d\n", 2); REprintf("Test %10d\n", 3); FILE *txtlog; txtlog = fopen("/test/test.txt", "w"); fprintf(txtlog, "Test %10d\n", 1); fclose(txtlog); // *** Code imported from the GD2 tutorial, http://www.libgd.org/Manual *** // Declare the image gdImagePtr im; // Declare output files FILE *pngout; // Declare color indexes int black; int white; // Allocate the image: 64 pixels across by 64 pixels tall im = gdImageCreate(64, 64); /* Allocate the color black (red, green and blue all minimum). Since this is the first color in a new image, it will be the background color. */ black = gdImageColorAllocate(im, 0, 0, 0); /* Allocate the color white (red, green and blue all maximum). */ white = gdImageColorAllocate(im, 255, 255, 255); /* Draw a line from the upper left to the lower right, using white color index. */ gdImageLine(im, 0, 0, 63, 63, white); /* Open a file for writing. "wb" means "write binary", important under MSDOS, harmless under Unix. */ pngout = fopen("/test/test.png", "wb"); /* Output the image to the disk file in PNG format. */ gdImagePng(im, pngout); /* Close the files. */ fclose(pngout); /* Destroy the image in memory. */ gdImageDestroy(im); } Prof Brian Ripley a écrit : On Wed, 28 Jan 2009, Benjamin Leblanc wrote: Hello all, I am getting into trouble when trying to do standard I/O from a C function called within R environment. This function is written in a small C library that is loaded whith dyn.load() and called in R via the .C() interface. I need to debug the C code using a text file for some logs, and also to speed up its result visualization by creating images on the fly using the GD library. Both of these outputs require to write into files from this C function. Allthough everything goes smoothly from compilation and linking to execution into R without errors, no file is created. I have also tried to do some simple printf(), Rprintf() and REprintf() but even that didn't gave me any visible output. Am I missing something trivial? Could anyone give me a hint on why it does not work? It works in many other packages. What OS are you using? (There known issues with using stdout and stderr from GUIs, but those are documented in the R-exts manual.) Best regards, Benjamin -- Chromatin and Cell Biology Lab. Institute for Human Genetics 141, rue de la Cardonille F-34396 Montpellier France Phone +33-(0)4 99 61 99 51 FAX +33-(0)4 99 61 99 01 __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] File and console output does not work in C code
Hi Simon, Yes, absolutely right, I just did this (...) mistake using copy/paste and forgetting to rename the called function. Thank you for the help and the reference to graphic packages. Benjamin Simon Urbanek a écrit : Ben, just FYI - GDD package uses libgd to create R graphics images so you can have a look at that -- and even better you can use Cairo which has much better rendering than libgd ... You can look at the sources if you want to customize that ... Cheers, S PS: I don't think your c_bricks code gets called at all - that's probably why you don't see any output. On Jan 28, 2009, at 13:44 , Benjamin Leblanc wrote: Here are more specific details: I use GNU/Linux Ubuntu 8.04 on an x86_64 workstation. R environnement was compiled from 2.8.0 sources. Below is a part of my C code to test the file I/O. When compiled as a standalone executable it prints "Test1" on the console and generates "test.txt" and "test.png" file outputs as expected. When compiled as a shared library and invoked from R environment via .C() interface, it does nothing (to avoid any file access issue, file permissions were set to 777 in the "/test" output folder). Am I missing a configuration option? Thanks for your help, #include #include #include #include // -- void c_bricks(double *x, int *nx, int *nw, double *gamma, double *Piw, double *V, double *W) { fflush(stdout); printf("Test %10d\n", 1); Rprintf("Test %10d\n", 2); REprintf("Test %10d\n", 3); FILE *txtlog; txtlog = fopen("/test/test.txt", "w"); fprintf(txtlog, "Test %10d\n", 1); fclose(txtlog); // *** Code imported from the GD2 tutorial, http://www.libgd.org/Manual *** // Declare the image gdImagePtr im; // Declare output files FILE *pngout; // Declare color indexes int black; int white; // Allocate the image: 64 pixels across by 64 pixels tall im = gdImageCreate(64, 64); /* Allocate the color black (red, green and blue all minimum). Since this is the first color in a new image, it will be the background color. */ black = gdImageColorAllocate(im, 0, 0, 0); /* Allocate the color white (red, green and blue all maximum). */ white = gdImageColorAllocate(im, 255, 255, 255); /* Draw a line from the upper left to the lower right, using white color index. */ gdImageLine(im, 0, 0, 63, 63, white); /* Open a file for writing. "wb" means "write binary", important under MSDOS, harmless under Unix. */ pngout = fopen("/test/test.png", "wb"); /* Output the image to the disk file in PNG format. */ gdImagePng(im, pngout); /* Close the files. */ fclose(pngout); /* Destroy the image in memory. */ gdImageDestroy(im); } Prof Brian Ripley a écrit : On Wed, 28 Jan 2009, Benjamin Leblanc wrote: Hello all, I am getting into trouble when trying to do standard I/O from a C function called within R environment. This function is written in a small C library that is loaded whith dyn.load() and called in R via the .C() interface. I need to debug the C code using a text file for some logs, and also to speed up its result visualization by creating images on the fly using the GD library. Both of these outputs require to write into files from this C function. Allthough everything goes smoothly from compilation and linking to execution into R without errors, no file is created. I have also tried to do some simple printf(), Rprintf() and REprintf() but even that didn't gave me any visible output. Am I missing something trivial? Could anyone give me a hint on why it does not work? It works in many other packages. What OS are you using? (There known issues with using stdout and stderr from GUIs, but those are documented in the R-exts manual.) Best regards, Benjamin -- Chromatin and Cell Biology Lab. Institute for Human Genetics 141, rue de la Cardonille F-34396 Montpellier France Phone +33-(0)4 99 61 99 51 FAX +33-(0)4 99 61 99 01 __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel