Are R ALTREP objects memory mapped
Get Outlook for iOS<https://aka.ms/o0ukef> ________________________________ From: R-package-devel <r-package-devel-boun...@r-project.org> on behalf of David Cortes <david.cortes.riv...@gmail.com> Sent: Wednesday, May 15, 2024 12:54:37 PM To: r-package-devel@r-project.org <r-package-devel@r-project.org> Subject: [R-pkg-devel] Altrep header, MSVC, and STRUCT_SUBTYPES macro I'm seeing some issues using R Altrep classes when compiling a package with the MSVC compiler on windows. While CRAN doesn't build windows binaries with this compiler, some packages such as Arrow and LightGBM have had some success in building their R packages with MSVC outside of CRAN, in order to enable functionalities that MinGW doesn't support. Some R headers do not work out-of-the-box with MSVC, but can be made to work by using alternative declarations of data structures which the headers provide. For example, defining the macro 'R_LEGACY_RCOMPLEX' switches to an alternate declaration of R's complex type, which compiles just fine under msvc, while the regular declaration doesn't compile. I am now trying to use Altrep classes in a package. The code compiles without errors under MSVC, but executing code that involves returning Altrep objects leads to segfaults and memory corruptions, even though it works fine under other compilers. I see the R Altrep header has this section: #define STRUCT_SUBTYPES #ifdef STRUCT_SUBTYPES # define R_SEXP(x) (x).ptr # define R_SUBTYPE_INIT(x) { x } typedef struct { SEXP ptr; } R_altrep_class_t; #else # define R_SEXP(x) ((SEXP) (x)) # define R_SUBTYPE_INIT(x) (void *) (x) typedef struct R_altcls *R_altrep_class_t; #endif Link: https://urldefense.com/v3/__https://github.com/wch/r-source/blob/531d0fd05d3bdc0f8a0350e3ecd3e101d315ab59/src/include/R_ext/Altrep.h*L33__;Iw!!OToaGQ!sO-S2sqzEKxviRHAbRPwKMl4JgRCoBJIOsL5KIIERL8DuU4I4R_JUOIagZqVcH54jScJLr5u6WJWlmymhkOuF-R4wQ$ If I manually edit the R header to remove the definition of 'STRUCT_SUBTYPES', leading to the second definition of 'R_altrep_class_t' being used, then things work as expected when the package is compiled with MSVC (no segfaults and no memory corruptions). Unfortunately, the Altrep header forcibly defines the macro right there before the #ifdef. I am guessing that the alternative defintion was offered there in order for users to try it out with problematic compilers, but it doesn't seem to be configurable like 'R_LEGACY_RCOMPLEX'. Is there some way that I can get an R package to use the alternative declaration of 'R_altrep_class_t' when including that header, or otherwise some other solution for using Altrep classes under MSVC? ______________________________________________ R-package-devel@r-project.org mailing list https://urldefense.com/v3/__https://stat.ethz.ch/mailman/listinfo/r-package-devel__;!!OToaGQ!sO-S2sqzEKxviRHAbRPwKMl4JgRCoBJIOsL5KIIERL8DuU4I4R_JUOIagZqVcH54jScJLr5u6WJWlmymhkMDdZo2_A$ [[alternative HTML version deleted]] ______________________________________________ R-package-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-package-devel