Use non-env-var methods from openssl_probe

This commit is contained in:
Noa
2025-02-20 22:47:26 -06:00
parent 4881f61be6
commit 085ac88438
4 changed files with 103 additions and 62 deletions

View File

@@ -1,6 +1,7 @@
use crate::{
builtins::PyStr,
convert::{ToPyException, ToPyObject},
exceptions::cstring_error,
PyObjectRef, PyResult, VirtualMachine,
};
@@ -17,22 +18,22 @@ impl ToPyObject for std::convert::Infallible {
}
}
pub trait ToCString {
fn to_cstring(&self, vm: &VirtualMachine) -> PyResult<std::ffi::CString>;
}
impl ToCString for &str {
fn to_cstring(&self, vm: &VirtualMachine) -> PyResult<std::ffi::CString> {
std::ffi::CString::new(*self).map_err(|err| err.to_pyexception(vm))
}
}
impl ToCString for PyStr {
pub trait ToCString: AsRef<str> {
fn to_cstring(&self, vm: &VirtualMachine) -> PyResult<std::ffi::CString> {
std::ffi::CString::new(self.as_ref()).map_err(|err| err.to_pyexception(vm))
}
fn ensure_no_nul(&self, vm: &VirtualMachine) -> PyResult<()> {
if self.as_ref().as_bytes().contains(&b'\0') {
Err(cstring_error(vm))
} else {
Ok(())
}
}
}
impl ToCString for &str {}
impl ToCString for PyStr {}
pub(crate) fn collection_repr<'a, I>(
class_name: Option<&str>,
prefix: &str,