File tree Expand file tree Collapse file tree 3 files changed +22
-51
lines changed Expand file tree Collapse file tree 3 files changed +22
-51
lines changed Original file line number Diff line number Diff line change @@ -8,6 +8,28 @@ use harp::utils::r_str_to_owned_utf8_unchecked;
8
8
use crate :: interface:: RMain ;
9
9
use crate :: interface:: CAPTURE_CONSOLE_OUTPUT ;
10
10
11
+ // Ensure the compiler includes the C entry points in `debug.c` in the binary.
12
+ // We store function pointers in global variables that are declared "used". The
13
+ // compiler is able to follow the chain of dependency from these variables to
14
+ // the C functions and ultimately their Rust implementations defined below.
15
+
16
+ extern "C" {
17
+ fn ark_print ( x : libr:: SEXP ) -> * const ffi:: c_char ;
18
+ fn ark_inspect ( x : libr:: SEXP ) -> * const ffi:: c_char ;
19
+ fn ark_trace_back ( ) -> * const ffi:: c_char ;
20
+ fn ark_display_value ( x : libr:: SEXP ) -> * const ffi:: c_char ;
21
+ }
22
+
23
+ #[ used]
24
+ static _ARK_PRINT: unsafe extern "C" fn ( x : libr:: SEXP ) -> * const ffi:: c_char = ark_print;
25
+ #[ used]
26
+ static _ARK_INSPECT: unsafe extern "C" fn ( x : libr:: SEXP ) -> * const ffi:: c_char = ark_inspect;
27
+ #[ used]
28
+ static _ARK_TRACE_BACK: unsafe extern "C" fn ( ) -> * const ffi:: c_char = ark_trace_back;
29
+ #[ used]
30
+ static _ARK_DISPLAY_VALUE: unsafe extern "C" fn ( x : libr:: SEXP ) -> * const ffi:: c_char =
31
+ ark_display_value;
32
+
11
33
// Implementations for entry points in `debug.c`.
12
34
13
35
#[ no_mangle]
Original file line number Diff line number Diff line change @@ -10,7 +10,6 @@ use quote::format_ident;
10
10
use quote:: quote;
11
11
use quote:: ToTokens ;
12
12
use syn:: parse_macro_input;
13
- use syn:: ItemFn ;
14
13
use syn:: ItemStruct ;
15
14
16
15
extern crate proc_macro;
@@ -214,32 +213,3 @@ pub fn register(_attr: TokenStream, item: TokenStream) -> TokenStream {
214
213
let all = quote ! { #function #registration } ;
215
214
all. into ( )
216
215
}
217
-
218
- #[ proc_macro_attribute]
219
- pub fn ensure_used ( _attr : TokenStream , item : TokenStream ) -> TokenStream {
220
- let input = parse_macro_input ! ( item as ItemFn ) ;
221
-
222
- let fn_name = & input. sig . ident ;
223
- let static_name = format_ident ! ( "_{fn_name}" ) ;
224
-
225
- let inputs = & input. sig . inputs ;
226
- let output = & input. sig . output ;
227
- let abi = & input. sig . abi ;
228
- let fn_type = quote ! {
229
- #abi fn ( #inputs) #output
230
- } ;
231
-
232
- let out = quote ! {
233
- #[ no_mangle]
234
- #input
235
-
236
- // Generate a static variable that hold the function pointer to force the
237
- // function to be compiled in
238
- #[ used]
239
- #[ no_mangle]
240
- #[ doc( hidden) ]
241
- static #static_name: #fn_type = #fn_name;
242
- } ;
243
-
244
- TokenStream :: from ( out)
245
- }
Original file line number Diff line number Diff line change 5
5
//
6
6
//
7
7
8
- use std:: ffi;
9
8
use std:: ffi:: CStr ;
10
9
use std:: ffi:: CString ;
11
10
12
- use harp_macros:: ensure_used;
13
11
use itertools:: Itertools ;
14
12
use libr:: * ;
15
13
use once_cell:: sync:: Lazy ;
@@ -763,25 +761,6 @@ pub fn r_subset_vec(x: SEXP, indices: Vec<i64>) -> Result<SEXP> {
763
761
Ok ( out. sexp )
764
762
}
765
763
766
- // Ensure the compiler includes the C entry points in `debug.c` in the binary.
767
- // This must be in a module that is used by other parts of the program, i.e. not
768
- // in debug.rs. Otherwise the compiler will still omit the whole thing.
769
-
770
- extern "C" {
771
- fn ark_print ( x : libr:: SEXP ) -> * const ffi:: c_char ;
772
- fn ark_inspect ( x : libr:: SEXP ) -> * const ffi:: c_char ;
773
- fn ark_trace_back ( ) -> * const ffi:: c_char ;
774
- fn ark_display_value ( x : libr:: SEXP ) -> * const ffi:: c_char ;
775
- }
776
-
777
- #[ ensure_used]
778
- pub extern "C" fn _placeholder ( ) {
779
- unsafe { ark_print ( libr:: R_NilValue ) } ;
780
- unsafe { ark_inspect ( libr:: R_NilValue ) } ;
781
- unsafe { ark_trace_back ( ) } ;
782
- unsafe { ark_display_value ( libr:: R_NilValue ) } ;
783
- }
784
-
785
764
#[ cfg( test) ]
786
765
mod tests {
787
766
use libr:: STRING_ELT ;
You can’t perform that action at this time.
0 commit comments