@@ -1956,26 +1956,51 @@ namespace attributes {
19561956
19571957 // write native routines
19581958 if (!hasPackageInit && !nativeRoutines_.empty ()) {
1959+
1960+ // build list of routines we will register
1961+ std::vector<std::string> routineNames;
1962+ std::vector<std::size_t > routineArgs;
1963+ for (std::size_t i=0 ;i<nativeRoutines_.size (); i++) {
1964+ const Attribute& attr = nativeRoutines_[i];
1965+ routineNames.push_back (package () + " _" + attr.exportedName ());
1966+ routineArgs.push_back (attr.function ().arguments ().size ());
1967+ }
1968+ if (hasCppInterface ()) {
1969+ routineNames.push_back (registerCCallableExportedName ());
1970+ routineArgs.push_back (0 );
1971+ }
1972+
1973+ // see if there are additional registrations to perform
1974+ Rcpp::Function extraRoutinesFunc = Environment::namespace_env (" Rcpp" )[" .extraRoutineRegistrations" ];
1975+ List extraRoutines = extraRoutinesFunc (routineNames);
1976+ std::vector<std::string> declarations = extraRoutines[" declarations" ];
1977+ std::vector<std::string> callEntries = extraRoutines[" call_entries" ];
1978+
1979+ // generate declarations
1980+ if (declarations.size () > 0 ) {
1981+ ostr () << std::endl;
1982+ for (int i = 0 ; i<declarations.size (); i++)
1983+ ostr () << declarations[i] << std::endl;
1984+ }
1985+
1986+ // generate registration code
19591987 ostr () << std::endl;
19601988 ostr () << " static const R_CallMethodDef CallEntries[] = {" << std::endl;
1961- if ( hasCppInterface () ) {
1962- ostr () << " {\" " << registerCCallableExportedName () << " \" , " <<
1963- " (DL_FUNC) &" << registerCCallableExportedName () << " , " <<
1964- 0 << " }," << std::endl;
1989+ for (std:: size_t i= 0 ;i<routineNames. size (); i++ ) {
1990+ ostr () << " {\" " << routineNames[i] << " \" , " <<
1991+ " (DL_FUNC) &" << routineNames[i] << " , " <<
1992+ routineArgs[i] << " }," << std::endl;
19651993 }
1966- for (std::size_t i=0 ;i<nativeRoutines_.size (); i++) {
1967- const Attribute& attr = nativeRoutines_[i];
1968- std::string routine = package () + " _" + attr.exportedName ();
1969- ostr () << " {\" " << routine << " \" , " <<
1970- " (DL_FUNC) &" << routine << " , " <<
1971- attr.function ().arguments ().size () << " }," << std::endl;
1994+ if (callEntries.size () > 0 ) {
1995+ for (int i = 0 ; i<callEntries.size (); i++)
1996+ ostr () << callEntries[i] << std::endl;
19721997 }
19731998 ostr () << " {NULL, NULL, 0}" << std::endl;
19741999 ostr () << " };" << std::endl;
19752000
19762001 ostr () << std::endl;
19772002
1978- ostr () << " extern \" C \" void R_init_" << package () << " (DllInfo *dll) {" << std::endl;
2003+ ostr () << " RcppExport void R_init_" << package () << " (DllInfo *dll) {" << std::endl;
19792004 ostr () << " R_registerRoutines(dll, NULL, CallEntries, NULL, NULL);" << std::endl;
19802005 ostr () << " R_useDynamicSymbols(dll, FALSE);" << std::endl;
19812006 ostr () << " }" << std::endl;
0 commit comments