Skip to content

Commit

Permalink
Merge pull request #144 from mulimoen/fix-capath
Browse files Browse the repository at this point in the history
Allow user to set CAPATH/CAINFO
  • Loading branch information
mulimoen authored May 5, 2024
2 parents 323558d + df96db5 commit 9ffb968
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[submodule "netcdf-src/source"]
path = netcdf-src/source
url = https://github.com/gigainfosystems/netcdf-c
url = https://github.com/mulimoen/netcdf-c
2 changes: 1 addition & 1 deletion netcdf-src/source
5 changes: 5 additions & 0 deletions netcdf-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ fn main() {
Version::new(4, 8, 1),
Version::new(4, 9, 0),
Version::new(4, 9, 1),
Version::new(4, 9, 2),
];

if !versions.contains(&metaheader.version) {
Expand All @@ -305,6 +306,10 @@ fn main() {
"cargo:rustc-cfg=feature=\"{}.{}.{}\"",
version.major, version.minor, version.patch
);
println!(
"cargo:version_\"{}.{}.{}\"=1",
version.major, version.minor, version.patch
);
}
}
metaheader.emit_feature_flags();
Expand Down
5 changes: 5 additions & 0 deletions netcdf-sys/src/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1728,6 +1728,11 @@ mod netcdf_2 {
#[cfg(feature = "4.6.2")]
pub fn nc_initialize() -> c_int;
pub fn nc_finalize() -> c_int;

#[cfg(feature = "4.9.2")]
pub fn nc_rc_get(key: *const c_char) -> *mut c_char;
#[cfg(feature = "4.9.2")]
pub fn nc_rc_set(key: *const c_char, value: *const c_char) -> c_int;
}
}
pub use netcdf_2::*;
1 change: 1 addition & 0 deletions netcdf/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ static = ["netcdf-sys/static"]
ndarray = { version = "0.15", optional = true }
netcdf-sys = { workspace = true }
bitflags = "2.4.2"
libc = "0.2.154"

[dev-dependencies]
clap = { version = "4.5.1", features = ["derive"] }
Expand Down
5 changes: 5 additions & 0 deletions netcdf/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,9 @@ fn main() {
if std::env::var("DEP_NETCDF_HAS_MMAP").is_ok() {
println!("cargo:rustc-cfg=feature=\"has-mmap\"");
}
for (env, _value) in std::env::vars() {
if let Some(version) = env.strip_prefix("DEP_NETCDF_VERSION_") {
println!("cargo:rustc-cfg=feature={version}");
}
}
}
2 changes: 2 additions & 0 deletions netcdf/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ pub(crate) mod error;
pub(crate) mod extent;
pub(crate) mod file;
pub(crate) mod group;
#[cfg(feature = "4.9.2")]
pub mod rc;
pub mod types;
pub(crate) mod variable;

Expand Down
42 changes: 42 additions & 0 deletions netcdf/src/rc.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
use std::ffi::{c_char, CStr, CString};
use std::ops::Deref;
use std::ptr::NonNull;

pub fn set(key: &str, value: &str) -> crate::error::Result<()> {
let key = CString::new(key)?;
let value = CString::new(value)?;
crate::error::checked(crate::with_lock(|| unsafe {
netcdf_sys::nc_rc_set(key.as_ptr(), value.as_ptr())
}))
}

#[derive(Debug)]
pub struct OwnedString {
inner: NonNull<c_char>,
}

impl Deref for OwnedString {
type Target = CStr;
fn deref(&self) -> &Self::Target {
unsafe { CStr::from_ptr(self.inner.as_ptr()) }
}
}

impl Drop for OwnedString {
fn drop(&mut self) {
unsafe {
libc::free(self.inner.as_ptr().cast());
}
}
}

pub fn get(key: &str) -> Option<OwnedString> {
let key = if let Ok(key) = CString::new(key) {
key
} else {
return None;
};
let _lock = netcdf_sys::libnetcdf_lock.lock().unwrap();
let value = unsafe { netcdf_sys::nc_rc_get(key.as_ptr()) };
NonNull::new(value).map(|inner| OwnedString { inner })
}

0 comments on commit 9ffb968

Please sign in to comment.