Hi everybody, Section 5.4 of WRE suggests to use `R_useDynamicSymbols(dll, FALSE);` when registering C/C++ routines in R packages, and Rcpp does so automatically. ?Random.user describes a way to hook a user- defined RNG into R. However, it looks like these two things are not compatible, i.e. `user_unif_rand` et al. are not found, if dynamic symbols are not allowed. Or can one register these routines somehow even though they are not following one of the standard calling conventions? Thanks Ralf
[R-pkg-devel] User defined RNG and code registration.
5 messages · Duncan Murdoch, Ivan Krylov, Ralf Stubner
On 23/09/2023 4:42 a.m., Ralf Stubner wrote:
Hi everybody, Section 5.4 of WRE suggests to use `R_useDynamicSymbols(dll, FALSE);` when registering C/C++ routines in R packages, and Rcpp does so automatically. ?Random.user describes a way to hook a user- defined RNG into R. However, it looks like these two things are not compatible, i.e. `user_unif_rand` et al. are not found, if dynamic symbols are not allowed. Or can one register these routines somehow even though they are not following one of the standard calling conventions?
I don't know the answer here, but section 6.16 of WRE suggests that you could explicitly make your functions visible even if they default to invisible. Duncan Murdoch
? Sat, 23 Sep 2023 08:42:25 +0000 Ralf Stubner <ralf.stubner at gmail.com> ?????:
?Random.user describes a way to hook a user- defined RNG into R. However, it looks like these two things are not compatible, i.e. `user_unif_rand` et al. are not found, if dynamic symbols are not allowed.
You're right! Looking at the code, if R_useDynamicSymbols(dll, FALSE) has been called for a DLL, the branch that calls dlsym() or GetProcAddress() to find symbols from that library by their shared object symbol names gets completely disabled; only the registered function names known to R matter at this point.
Or can one register these routines somehow even though they are not following one of the standard calling conventions?
It sounds unsatisfying, but if you register your user_unif_rand function with the right name and any of the ABIs supported by R, it sounds like it should work as long as you never call it using the .Call/.C/.Fortran ABI it's registered for.
Best regards, Ivan
On Sat, Sep 23, 2023 at 10:00?AM Duncan Murdoch
<murdoch.duncan at gmail.com> wrote:
I don't know the answer here, but section 6.16 of WRE suggests that you could explicitly make your functions visible even if they default to invisible.
Thanks Duncan. Unfortunately at least in my tests the visibility settings did not alter whether R could find these routines. Ralf
On Sat, Sep 23, 2023 at 7:30?PM Ivan Krylov <krylov.r00t at gmail.com> wrote:
You're right! Looking at the code, if R_useDynamicSymbols(dll, FALSE) has been called for a DLL, the branch that calls dlsym() or GetProcAddress() to find symbols from that library by their shared object symbol names gets completely disabled; only the registered function names known to R matter at this point.
Thanks Ivan for the investigations! That explains my experiences.
It sounds unsatisfying, but if you register your user_unif_rand function with the right name and any of the ABIs supported by R, it sounds like it should work as long as you never call it using the .Call/.C/.Fortran ABI it's registered for.
That is indeed unsatisfying, but looks like the best workaround for now. Ralf