File tree 5 files changed +54
-0
lines changed
5 files changed +54
-0
lines changed Original file line number Diff line number Diff line change @@ -306,6 +306,10 @@ fn main() {
306
306
"cargo:rustc-cfg=feature=\" {}.{}.{}\" " ,
307
307
version. major, version. minor, version. patch
308
308
) ;
309
+ println ! (
310
+ "cargo:version_\" {}.{}.{}\" =1" ,
311
+ version. major, version. minor, version. patch
312
+ ) ;
309
313
}
310
314
}
311
315
metaheader. emit_feature_flags ( ) ;
Original file line number Diff line number Diff line change @@ -23,6 +23,7 @@ static = ["netcdf-sys/static"]
23
23
ndarray = { version = " 0.15" , optional = true }
24
24
netcdf-sys = { workspace = true }
25
25
bitflags = " 2.4.2"
26
+ libc = " 0.2.154"
26
27
27
28
[dev-dependencies ]
28
29
clap = { version = " 4.5.1" , features = [" derive" ] }
Original file line number Diff line number Diff line change @@ -2,4 +2,9 @@ fn main() {
2
2
if std:: env:: var ( "DEP_NETCDF_HAS_MMAP" ) . is_ok ( ) {
3
3
println ! ( "cargo:rustc-cfg=feature=\" has-mmap\" " ) ;
4
4
}
5
+ for ( env, _value) in std:: env:: vars ( ) {
6
+ if let Some ( version) = env. strip_prefix ( "DEP_NETCDF_VERSION_" ) {
7
+ println ! ( "cargo:rustc-cfg=feature={version}" ) ;
8
+ }
9
+ }
5
10
}
Original file line number Diff line number Diff line change @@ -110,6 +110,8 @@ pub(crate) mod error;
110
110
pub ( crate ) mod extent;
111
111
pub ( crate ) mod file;
112
112
pub ( crate ) mod group;
113
+ #[ cfg( feature = "4.9.2" ) ]
114
+ pub mod rc;
113
115
pub mod types;
114
116
pub ( crate ) mod variable;
115
117
Original file line number Diff line number Diff line change
1
+ use std:: ffi:: { c_char, CStr , CString } ;
2
+ use std:: ops:: Deref ;
3
+ use std:: ptr:: NonNull ;
4
+
5
+ pub fn set ( key : & str , value : & str ) -> crate :: error:: Result < ( ) > {
6
+ let key = CString :: new ( key) ?;
7
+ let value = CString :: new ( value) ?;
8
+ crate :: error:: checked ( crate :: with_lock ( || unsafe {
9
+ netcdf_sys:: nc_rc_set ( key. as_ptr ( ) , value. as_ptr ( ) )
10
+ } ) )
11
+ }
12
+
13
+ #[ derive( Debug ) ]
14
+ pub struct OwnedString {
15
+ inner : NonNull < c_char > ,
16
+ }
17
+
18
+ impl Deref for OwnedString {
19
+ type Target = CStr ;
20
+ fn deref ( & self ) -> & Self :: Target {
21
+ unsafe { CStr :: from_ptr ( self . inner . as_ptr ( ) ) }
22
+ }
23
+ }
24
+
25
+ impl Drop for OwnedString {
26
+ fn drop ( & mut self ) {
27
+ unsafe {
28
+ libc:: free ( self . inner . as_ptr ( ) . cast ( ) ) ;
29
+ }
30
+ }
31
+ }
32
+
33
+ pub fn get ( key : & str ) -> Option < OwnedString > {
34
+ let key = if let Ok ( key) = CString :: new ( key) {
35
+ key
36
+ } else {
37
+ return None ;
38
+ } ;
39
+ let _lock = netcdf_sys:: libnetcdf_lock. lock ( ) . unwrap ( ) ;
40
+ let value = unsafe { netcdf_sys:: nc_rc_get ( key. as_ptr ( ) ) } ;
41
+ NonNull :: new ( value) . map ( |inner| OwnedString { inner } )
42
+ }
You can’t perform that action at this time.
0 commit comments