1
- use std:: {
2
- os:: raw:: { c_int, c_uint} ,
3
- path:: PathBuf ,
4
- } ;
1
+ use std:: { os:: raw:: c_int, path:: PathBuf } ;
5
2
6
3
use wstp:: { self , Link } ;
7
4
@@ -22,19 +19,19 @@ use crate::{
22
19
// TODO: Make this module public somewhere and document these error code in #[export(..)]
23
20
// and Overview.md.
24
21
mod error_code {
25
- use std:: os:: raw:: c_uint ;
22
+ use std:: os:: raw:: c_int ;
26
23
27
24
// Chosen arbitrarily. Avoids clashing with `LIBRARY_FUNCTION_ERROR` and related
28
25
// error codes.
29
- const OFFSET : c_uint = 1000 ;
26
+ const OFFSET : c_int = 1000 ;
30
27
31
28
/// A call to [initialize()][crate::initialize] failed.
32
- pub const FAILED_TO_INIT : c_uint = OFFSET + 1 ;
29
+ pub const FAILED_TO_INIT : c_int = OFFSET + 1 ;
33
30
34
31
/// The library code panicked.
35
32
//
36
33
// TODO: Wherever this code is set, also set a $LastError-like variable.
37
- pub const FAILED_WITH_PANIC : c_uint = OFFSET + 2 ;
34
+ pub const FAILED_WITH_PANIC : c_int = OFFSET + 2 ;
38
35
}
39
36
40
37
//==================
@@ -47,7 +44,7 @@ unsafe fn call_wstp_link_wolfram_library_function<
47
44
libdata : sys:: WolframLibraryData ,
48
45
mut unsafe_link : wstp:: sys:: WSLINK ,
49
46
function : F ,
50
- ) -> c_uint {
47
+ ) -> c_int {
51
48
// Initialize the library.
52
49
if crate :: initialize ( libdata) . is_err ( ) {
53
50
return error_code:: FAILED_TO_INIT ;
@@ -61,14 +58,14 @@ unsafe fn call_wstp_link_wolfram_library_function<
61
58
} ) ) ;
62
59
63
60
match result {
64
- Ok ( ( ) ) => LIBRARY_NO_ERROR ,
61
+ Ok ( ( ) ) => LIBRARY_NO_ERROR as c_int ,
65
62
// Try to fail gracefully by writing the panic message as a Failure[..] object to
66
63
// be returned, but if that fails, just return LIBRARY_FUNCTION_ERROR.
67
64
Err ( panic) => match write_panic_failure_to_link ( link, panic) {
68
- Ok ( ( ) ) => LIBRARY_NO_ERROR ,
65
+ Ok ( ( ) ) => LIBRARY_NO_ERROR as c_int ,
69
66
Err ( _wstp_err) => {
70
67
// println!("PANIC ERROR: {}", _wstp_err);
71
- sys:: LIBRARY_FUNCTION_ERROR // +1
68
+ sys:: LIBRARY_FUNCTION_ERROR as c_int // +1
72
69
} ,
73
70
} ,
74
71
}
@@ -114,7 +111,7 @@ pub unsafe fn call_native_wolfram_library_function<'a, F: NativeFunction<'a>>(
114
111
argc : sys:: mint ,
115
112
res : MArgument ,
116
113
func : F ,
117
- ) -> c_uint {
114
+ ) -> c_int {
118
115
use std:: panic:: AssertUnwindSafe ;
119
116
120
117
// Initialize the library.
@@ -124,7 +121,7 @@ pub unsafe fn call_native_wolfram_library_function<'a, F: NativeFunction<'a>>(
124
121
125
122
let argc = match usize:: try_from ( argc) {
126
123
Ok ( argc) => argc,
127
- Err ( _) => return sys:: LIBRARY_FUNCTION_ERROR ,
124
+ Err ( _) => return sys:: LIBRARY_FUNCTION_ERROR as c_int ,
128
125
} ;
129
126
130
127
// FIXME: This isn't safe! 'a could be 'static, and then the user could store the
@@ -138,7 +135,7 @@ pub unsafe fn call_native_wolfram_library_function<'a, F: NativeFunction<'a>>(
138
135
return error_code:: FAILED_WITH_PANIC ;
139
136
} ;
140
137
141
- sys:: LIBRARY_NO_ERROR
138
+ sys:: LIBRARY_NO_ERROR as c_int
142
139
}
143
140
144
141
pub unsafe fn call_wstp_wolfram_library_function <
@@ -147,7 +144,7 @@ pub unsafe fn call_wstp_wolfram_library_function<
147
144
libdata : sys:: WolframLibraryData ,
148
145
unsafe_link : wstp:: sys:: WSLINK ,
149
146
func : F ,
150
- ) -> c_uint {
147
+ ) -> c_int {
151
148
call_wstp_link_wolfram_library_function (
152
149
libdata,
153
150
unsafe_link,
@@ -204,7 +201,7 @@ inventory::collect!(LibraryLinkFunction);
204
201
pub unsafe fn load_library_functions_impl (
205
202
lib_data : sys:: WolframLibraryData ,
206
203
raw_link : wstp:: sys:: WSLINK ,
207
- ) -> c_uint {
204
+ ) -> c_int {
208
205
call_wstp_link_wolfram_library_function ( lib_data, raw_link, |link : & mut Link | {
209
206
let arg_count: usize =
210
207
link. test_head ( "List" ) . expect ( "expected 'List' expression" ) ;
0 commit comments