Skip to content

Add header to declare C level API #4645

Merged
mattdowle merged 1 commit intoRdatatable:masterfrom
eddelbuettel:feature/api_header
Aug 4, 2020
Merged

Add header to declare C level API #4645
mattdowle merged 1 commit intoRdatatable:masterfrom
eddelbuettel:feature/api_header

Conversation

@eddelbuettel
Copy link
Copy Markdown
Contributor

@eddelbuettel eddelbuettel commented Jul 26, 2020

Closes #4643.
This PR follows the discussion in #4643 and adds a (very simply and short) file declaring a C level function to access the registered-as-callable function subsetDT. But providing a function which shields the somewhat unwieldy C function pointer setup, wider use is facilitated. It also offers a benefit for maintenance as it provides another user facing layer allowing the data.table team to redefine or rename the internal function registers as C callable and called here.

At present the function can called three ways

  • "as is": DT_subsetDT() with an explicit prefix (and we could consider dropping the suffix...)
  • "with an additional define": subsetDT() which is a little cleaner but may clash, this is an opt-in
  • "from C++": dt::subsetDT() where we put a simple C++ namespace around it

Please free to rename or realign as you see fit. I have tested all three access mechanisms (in a simple Rcpp-based test). Doing a proper unit test is likely more work but maybe something we should do. I can help...

@mattdowle mattdowle added this to the 1.13.1 milestone Aug 4, 2020
@mattdowle
Copy link
Copy Markdown
Member

Thanks, @eddelbuettel! I'll invite you to be a project member so you can create branches directly in the main project in future if you wish, and I'll add you to DESCRIPTION in a follow up commit to master (slightly quicker for me than adding that to your PR).

Comment on lines +25 to +27
static SEXP(*fun)(SEXP, SEXP, SEXP) =
(SEXP(*)(SEXP,SEXP,SEXP)) R_GetCCallable("data.table", "CsubsetDT");
return fun(x,rows,cols);
Copy link
Copy Markdown
Member

@jangorecki jangorecki Oct 12, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@eddelbuettel is it necessary to create fun object here? couldn't this be a one liner to returning R_GetCCallable() call?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes: fun is what is invoked when you call. The static makes the assignment stick, and the R_GetCCallable() ges the identifier from the other package.

hongyuanjia pushed a commit to hongyuanjia/data.table that referenced this pull request Dec 29, 2023
hongyuanjia pushed a commit to hongyuanjia/data.table that referenced this pull request Dec 29, 2023
@eddelbuettel eddelbuettel deleted the feature/api_header branch January 30, 2024 13:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add a API definining header hiding the function pointer as commonly done

3 participants