-
-
Notifications
You must be signed in to change notification settings - Fork 219
Automatically register init functions for RcppModules (closes #704) #705
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Nicely done. |
Shame on me for not escalating this in March when I adjusted the example we unit test. |
Codecov Report
@@ Coverage Diff @@
## master #705 +/- ##
==========================================
+ Coverage 89.54% 89.57% +0.03%
==========================================
Files 66 66
Lines 3587 3588 +1
==========================================
+ Hits 3212 3214 +2
+ Misses 375 374 -1
Continue to review full report at Codecov.
|
Not quite there yet. After fresh install from this branch: /tmp$ Rscript -e "Rcpp::Rcpp.package.skeleton('foo', module = TRUE)"
Creating directories ...
Creating DESCRIPTION ...
Creating NAMESPACE ...
Creating Read-and-delete-me ...
Saving functions and data ...
Making help files ...
Done.
Further steps are described in './foo/Read-and-delete-me'.
Adding Rcpp settings
>> added Imports: Rcpp
>> added LinkingTo: Rcpp
>> added useDynLib directive to NAMESPACE
>> added import(methods, Rcpp) directive to NAMESPACE
>> added example src file using Rcpp attributes
>> compiled Rcpp attributes
>> do NOT modify by hand either RcppExports.cpp or RcppExports.R
>> added Rd file for rcpp_hello_world
>> copied the example module file
/tmp$ R CMD INSTALL foo
* installing to library ‘/usr/local/lib/R/site-library’
* installing *source* package ‘foo’ ...
** libs
ccache g++ -I/usr/share/R/include -DNDEBUG -I"/usr/local/lib/R/site-library/Rcpp/include" -fpic -g -O3 -Wall -pipe -pedantic -Wextra -Wno-empty-body -Wno-unused -c Num.cpp -o Num.o
ccache g++ -I/usr/share/R/include -DNDEBUG -I"/usr/local/lib/R/site-library/Rcpp/include" -fpic -g -O3 -Wall -pipe -pedantic -Wextra -Wno-empty-body -Wno-unused -c RcppExports.cpp -o RcppExports.o
ccache g++ -I/usr/share/R/include -DNDEBUG -I"/usr/local/lib/R/site-library/Rcpp/include" -fpic -g -O3 -Wall -pipe -pedantic -Wextra -Wno-empty-body -Wno-unused -c rcpp_hello_world.cpp -o rcpp_hello_world.o
ccache g++ -I/usr/share/R/include -DNDEBUG -I"/usr/local/lib/R/site-library/Rcpp/include" -fpic -g -O3 -Wall -pipe -pedantic -Wextra -Wno-empty-body -Wno-unused -c rcpp_module.cpp -o rcpp_module.o
ccache g++ -I/usr/share/R/include -DNDEBUG -I"/usr/local/lib/R/site-library/Rcpp/include" -fpic -g -O3 -Wall -pipe -pedantic -Wextra -Wno-empty-body -Wno-unused -c stdVector.cpp -o stdVector.o
g++ -shared -L/usr/lib/R/lib -Wl,-Bsymbolic-functions -Wl,-z,relro -o foo.so Num.o RcppExports.o rcpp_hello_world.o rcpp_module.o stdVector.o -L/usr/lib/R/lib -lR
installing to /usr/local/lib/R/site-library/foo/libs
** R
** preparing package for lazy loading
** help
*** installing help indices
** building package indices
** testing if installed package can be loaded
Error: package or namespace load failed for ‘foo’ in .doLoadActions(where, attach):
error in load action .__A__.1 for package foo: loadModule(module = "NumEx", what = TRUE, env = ns, loadNow = TRUE): Unable to load module "NumEx": Failed to initialize module pointer: Error in FUN(X[[i]], ...): no such symbol _rcpp_module_boot_NumEx in package foo
Error: loading failed
Execution halted
ERROR: loading failed
* removing ‘/usr/local/lib/R/site-library/foo’
/tmp$ |
I think the problem is that compileAttributes is called within
Rcpp::package.skeleton *before* the module code is added. I'll change the
order and it should resolve things.
…On Fri, Jun 2, 2017 at 12:17 PM, Dirk Eddelbuettel ***@***.*** > wrote:
Not *quite* there yet.
After fresh install from this branch:
/tmp$ Rscript -e "Rcpp::Rcpp.package.skeleton('foo', module = TRUE)" Creating directories ...
Creating DESCRIPTION ...
Creating NAMESPACE ...
Creating Read-and-delete-me ...
Saving functions and data ...
Making help files ...
Done.
Further steps are described in './foo/Read-and-delete-me'.
Adding Rcpp settings
>> added Imports: Rcpp
>> added LinkingTo: Rcpp
>> added useDynLib directive to NAMESPACE
>> added import(methods, Rcpp) directive to NAMESPACE
>> added example src file using Rcpp attributes
>> compiled Rcpp attributes
>> do NOT modify by hand either RcppExports.cpp or RcppExports.R
>> added Rd file for rcpp_hello_world
>> copied the example module file
/tmp$ R CMD INSTALL foo* installing to library ‘/usr/local/lib/R/site-library’* installing *source* package ‘foo’ ...** libs
ccache g++ -I/usr/share/R/include -DNDEBUG -I"/usr/local/lib/R/site-library/Rcpp/include" -fpic -g -O3 -Wall -pipe -pedantic -Wextra -Wno-empty-body -Wno-unused -c Num.cpp -o Num.o
ccache g++ -I/usr/share/R/include -DNDEBUG -I"/usr/local/lib/R/site-library/Rcpp/include" -fpic -g -O3 -Wall -pipe -pedantic -Wextra -Wno-empty-body -Wno-unused -c RcppExports.cpp -o RcppExports.o
ccache g++ -I/usr/share/R/include -DNDEBUG -I"/usr/local/lib/R/site-library/Rcpp/include" -fpic -g -O3 -Wall -pipe -pedantic -Wextra -Wno-empty-body -Wno-unused -c rcpp_hello_world.cpp -o rcpp_hello_world.o
ccache g++ -I/usr/share/R/include -DNDEBUG -I"/usr/local/lib/R/site-library/Rcpp/include" -fpic -g -O3 -Wall -pipe -pedantic -Wextra -Wno-empty-body -Wno-unused -c rcpp_module.cpp -o rcpp_module.o
ccache g++ -I/usr/share/R/include -DNDEBUG -I"/usr/local/lib/R/site-library/Rcpp/include" -fpic -g -O3 -Wall -pipe -pedantic -Wextra -Wno-empty-body -Wno-unused -c stdVector.cpp -o stdVector.o
g++ -shared -L/usr/lib/R/lib -Wl,-Bsymbolic-functions -Wl,-z,relro -o foo.so Num.o RcppExports.o rcpp_hello_world.o rcpp_module.o stdVector.o -L/usr/lib/R/lib -lR
installing to /usr/local/lib/R/site-library/foo/libs** R** preparing package for lazy loading** help*** installing help indices** building package indices** testing if installed package can be loaded
Error: package or namespace load failed for ‘foo’ in .doLoadActions(where, attach):
error in load action .__A__.1 for package foo: loadModule(module = "NumEx", what = TRUE, env = ns, loadNow = TRUE): Unable to load module "NumEx": Failed to initialize module pointer: Error in FUN(X[[i]], ...): no such symbol _rcpp_module_boot_NumEx in package foo
Error: loading failed
Execution halted
ERROR: loading failed* removing ‘/usr/local/lib/R/site-library/foo’
/tmp$
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#705 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AAGXx0vLz4Cagygyt4M5_uiBGskIPcnDks5sADWbgaJpZM4NudVA>
.
|
Okay, just pushed a fix
…On Fri, Jun 2, 2017 at 1:20 PM, JJ Allaire ***@***.***> wrote:
I think the problem is that compileAttributes is called within
Rcpp::package.skeleton *before* the module code is added. I'll change the
order and it should resolve things.
On Fri, Jun 2, 2017 at 12:17 PM, Dirk Eddelbuettel <
***@***.***> wrote:
> Not *quite* there yet.
>
> After fresh install from this branch:
>
> /tmp$ Rscript -e "Rcpp::Rcpp.package.skeleton('foo', module = TRUE)" Creating directories ...
> Creating DESCRIPTION ...
> Creating NAMESPACE ...
> Creating Read-and-delete-me ...
> Saving functions and data ...
> Making help files ...
> Done.
> Further steps are described in './foo/Read-and-delete-me'.
>
> Adding Rcpp settings
> >> added Imports: Rcpp
> >> added LinkingTo: Rcpp
> >> added useDynLib directive to NAMESPACE
> >> added import(methods, Rcpp) directive to NAMESPACE
> >> added example src file using Rcpp attributes
> >> compiled Rcpp attributes
> >> do NOT modify by hand either RcppExports.cpp or RcppExports.R
> >> added Rd file for rcpp_hello_world
> >> copied the example module file
> /tmp$ R CMD INSTALL foo* installing to library ‘/usr/local/lib/R/site-library’* installing *source* package ‘foo’ ...** libs
> ccache g++ -I/usr/share/R/include -DNDEBUG -I"/usr/local/lib/R/site-library/Rcpp/include" -fpic -g -O3 -Wall -pipe -pedantic -Wextra -Wno-empty-body -Wno-unused -c Num.cpp -o Num.o
> ccache g++ -I/usr/share/R/include -DNDEBUG -I"/usr/local/lib/R/site-library/Rcpp/include" -fpic -g -O3 -Wall -pipe -pedantic -Wextra -Wno-empty-body -Wno-unused -c RcppExports.cpp -o RcppExports.o
> ccache g++ -I/usr/share/R/include -DNDEBUG -I"/usr/local/lib/R/site-library/Rcpp/include" -fpic -g -O3 -Wall -pipe -pedantic -Wextra -Wno-empty-body -Wno-unused -c rcpp_hello_world.cpp -o rcpp_hello_world.o
> ccache g++ -I/usr/share/R/include -DNDEBUG -I"/usr/local/lib/R/site-library/Rcpp/include" -fpic -g -O3 -Wall -pipe -pedantic -Wextra -Wno-empty-body -Wno-unused -c rcpp_module.cpp -o rcpp_module.o
> ccache g++ -I/usr/share/R/include -DNDEBUG -I"/usr/local/lib/R/site-library/Rcpp/include" -fpic -g -O3 -Wall -pipe -pedantic -Wextra -Wno-empty-body -Wno-unused -c stdVector.cpp -o stdVector.o
> g++ -shared -L/usr/lib/R/lib -Wl,-Bsymbolic-functions -Wl,-z,relro -o foo.so Num.o RcppExports.o rcpp_hello_world.o rcpp_module.o stdVector.o -L/usr/lib/R/lib -lR
> installing to /usr/local/lib/R/site-library/foo/libs** R** preparing package for lazy loading** help*** installing help indices** building package indices** testing if installed package can be loaded
> Error: package or namespace load failed for ‘foo’ in .doLoadActions(where, attach):
> error in load action .__A__.1 for package foo: loadModule(module = "NumEx", what = TRUE, env = ns, loadNow = TRUE): Unable to load module "NumEx": Failed to initialize module pointer: Error in FUN(X[[i]], ...): no such symbol _rcpp_module_boot_NumEx in package foo
>
> Error: loading failed
> Execution halted
> ERROR: loading failed* removing ‘/usr/local/lib/R/site-library/foo’
> /tmp$
>
> —
> You are receiving this because you authored the thread.
> Reply to this email directly, view it on GitHub
> <#705 (comment)>, or mute
> the thread
> <https://github.com/notifications/unsubscribe-auth/AAGXx0vLz4Cagygyt4M5_uiBGskIPcnDks5sADWbgaJpZM4NudVA>
> .
>
|
Works like a charm now. |
compileAttributes(root) | ||
message(" >> compiled Rcpp attributes ") | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe I am short of coffee but if (attributes) {
relies on attributes==TRUE
. We could have a case of modules=TRUE
(as in #704) and also attributes=FALSE
, no? Needless complication?
I think it's a little more involved than first appears, if we do this: Rcpp::Rcpp.package.skeleton('foo', module = TRUE, attributes = FALSE) Then the I'd say if the user asks for modules and no attributes then they mean no auto-generation behavior and they'll futz with init.c manually themselves. |
Agreed. Let's go with this now and clean up spillage should it occur. |
Thanks for the fix! Do you know when you will release it? I wanted to know if I should use master or wait for the release. |
@BenoitLondon See my recent post to the rcpp-devel list with pointers to the drat repo. You can install Rcpp 0.12.11.2 from there. (Master works too but the git repo could be unstable.) |
Thanks |
Addresses #704
RcppModules include a native routine "boot" function of the form
_rcpp_module_boot_*
. These functions are not discovered bytools::package_native_routine_registration_skeleton
so generally need to be hand-added toinit.c
.This also implies that our current auto-generation of native routine registrations for
RcppExports.cpp
won't register these functions and will therefore fail to create a loadable package. 2 alternatives here:When we see an Rcpp module simply don't attempt to generate native routine registrations (sort of like we do now when we see
init.c
).Generate native routine registrations for the Rcpp modules.
Happily, we already parse for Rcpp module declarations (since
sourceCpp
supports exporting modules) so it's a very straightforward change to generate the_rcpp_module_boot_*
functions, which is what we do in this PR.