Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Lib/test/test_os.py
Original file line number Diff line number Diff line change
Expand Up @@ -3491,6 +3491,7 @@ def test_spawnl(self):
self.assertEqual(exitcode, self.exitcode)

@requires_os_func('spawnle')
@unittest.skipIf(sys.platform == 'win32', "TODO: RUSTPYTHON; fix spawnve on Windows")
def test_spawnle(self):
program, args = self.create_args(with_env=True)
exitcode = os.spawnle(os.P_WAIT, program, *args, self.env)
Expand Down Expand Up @@ -3519,6 +3520,7 @@ def test_spawnv(self):
self.assertEqual(exitcode, self.exitcode)

@requires_os_func('spawnve')
@unittest.skipIf(sys.platform == 'win32', "TODO: RUSTPYTHON; fix spawnve on Windows")
def test_spawnve(self):
program, args = self.create_args(with_env=True)
exitcode = os.spawnve(os.P_WAIT, program, args, self.env)
Expand Down Expand Up @@ -3627,6 +3629,7 @@ def _test_invalid_env(self, spawn):
self.assertEqual(exitcode, 0)

@requires_os_func('spawnve')
@unittest.skipIf(sys.platform == 'win32', "TODO: RUSTPYTHON; fix spawnve on Windows")
def test_spawnve_invalid_env(self):
self._test_invalid_env(os.spawnve)

Expand Down
1 change: 0 additions & 1 deletion Lib/test/test_sysconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,6 @@ def test_main(self):
_main()
self.assertTrue(len(output.getvalue().split('\n')) > 0)

@unittest.expectedFailure # TODO: RUSTPYTHON
@unittest.skipIf(sys.platform == "win32", "Does not apply to Windows")
def test_ldshared_value(self):
ldflags = sysconfig.get_config_var('LDFLAGS')
Expand Down
2 changes: 2 additions & 0 deletions Lib/test/test_threading.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ def f(mutex):

# PyThreadState_SetAsyncExc() is a CPython-only gimmick, not (currently)
# exposed at the Python level. This test relies on ctypes to get at it.
@unittest.skip("TODO: RUSTPYTHON; expects @cpython_only")
def test_PyThreadState_SetAsyncExc(self):
ctypes = import_module("ctypes")

Expand Down Expand Up @@ -332,6 +333,7 @@ def fail_new_thread(*args):
finally:
threading._start_new_thread = _start_new_thread

@unittest.skip("TODO: RUSTPYTHON; ctypes.pythonapi is not supported")
def test_finalize_running_thread(self):
# Issue 1402: the PyGILState_Ensure / _Release functions may be called
# very late on python exit: on deallocation of a running thread for
Expand Down
14 changes: 10 additions & 4 deletions crates/stdlib/src/openssl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1543,10 +1543,10 @@ mod _ssl {
#[pymethod]
fn get_ca_certs(
&self,
binary_form: OptionalArg<bool>,
args: GetCertArgs,
vm: &VirtualMachine,
) -> PyResult<Vec<PyObjectRef>> {
let binary_form = binary_form.unwrap_or(false);
let binary_form = args.binary_form.unwrap_or(false);
let ctx = self.ctx();
#[cfg(ossl300)]
let certs = ctx.cert_store().all_certificates();
Expand Down Expand Up @@ -2259,6 +2259,12 @@ mod _ssl {
password: Option<PyObjectRef>,
}

#[derive(FromArgs)]
struct GetCertArgs {
#[pyarg(any, optional)]
binary_form: OptionalArg<bool>,
}

// Err is true if the socket is blocking
type SocketDeadline = Result<Instant, bool>;

Expand Down Expand Up @@ -2516,10 +2522,10 @@ mod _ssl {
#[pymethod]
fn getpeercert(
&self,
binary: OptionalArg<bool>,
args: GetCertArgs,
vm: &VirtualMachine,
) -> PyResult<Option<PyObjectRef>> {
let binary = binary.unwrap_or(false);
let binary = args.binary_form.unwrap_or(false);
let stream = self.connection.read();
if !stream.ssl().is_init_finished() {
return Err(vm.new_value_error("handshake not done yet"));
Expand Down
18 changes: 10 additions & 8 deletions crates/stdlib/src/ssl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -841,6 +841,12 @@ mod _ssl {
password: OptionalArg<PyObjectRef>,
}

#[derive(FromArgs)]
struct GetCertArgs {
#[pyarg(any, optional)]
binary_form: OptionalArg<bool>,
}

#[pyclass(with(Constructor), flags(BASETYPE))]
impl PySSLContext {
// Helper method to convert DER certificate bytes to Python dict
Expand Down Expand Up @@ -1688,12 +1694,8 @@ mod _ssl {
}

#[pymethod]
fn get_ca_certs(
&self,
binary_form: OptionalArg<bool>,
vm: &VirtualMachine,
) -> PyResult<PyListRef> {
let binary_form = binary_form.unwrap_or(false);
fn get_ca_certs(&self, args: GetCertArgs, vm: &VirtualMachine) -> PyResult<PyListRef> {
let binary_form = args.binary_form.unwrap_or(false);
let ca_certs_der = self.ca_certs_der.read();

let mut certs = Vec::new();
Expand Down Expand Up @@ -3444,10 +3446,10 @@ mod _ssl {
#[pymethod]
fn getpeercert(
&self,
binary_form: OptionalArg<bool>,
args: GetCertArgs,
vm: &VirtualMachine,
) -> PyResult<Option<PyObjectRef>> {
let binary = binary_form.unwrap_or(false);
let binary = args.binary_form.unwrap_or(false);

// Check if handshake is complete
if !*self.handshake_done.lock() {
Expand Down
17 changes: 17 additions & 0 deletions crates/vm/src/stdlib/sysconfigdata.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// spell-checker: words LDSHARED ARFLAGS CPPFLAGS CCSHARED BASECFLAGS BLDSHARED

pub(crate) use _sysconfigdata::make_module;

#[pymodule]
Expand All @@ -18,6 +20,21 @@ pub(crate) mod _sysconfigdata {
"MULTIARCH" => MULTIARCH,
// enough for tests to stop expecting urandom() to fail after restricting file resources
"HAVE_GETRANDOM" => 1,
// Compiler configuration for native extension builds
"CC" => "cc",
"CXX" => "c++",
"CFLAGS" => "",
"CPPFLAGS" => "",
"LDFLAGS" => "",
"LDSHARED" => "cc -shared",
"CCSHARED" => "",
"SHLIB_SUFFIX" => ".so",
"SO" => ".so",
"AR" => "ar",
"ARFLAGS" => "rcs",
"OPT" => "",
"BASECFLAGS" => "",
"BLDSHARED" => "cc -shared",
Comment on lines +23 to +37
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Platform-specific hardcoded values will be incorrect on Windows.

The hardcoded values for SHLIB_SUFFIX, SO, LDSHARED, and BLDSHARED assume a Unix/Linux environment. On Windows, shared libraries use .dll instead of .so, and the linker commands differ significantly.

🔎 Consider using conditional compilation for platform-specific values
             // Compiler configuration for native extension builds
             "CC" => "cc",
             "CXX" => "c++",
             "CFLAGS" => "",
             "CPPFLAGS" => "",
             "LDFLAGS" => "",
-            "LDSHARED" => "cc -shared",
+            "LDSHARED" => if cfg!(windows) { "link.exe" } else { "cc -shared" },
             "CCSHARED" => "",
-            "SHLIB_SUFFIX" => ".so",
-            "SO" => ".so",
+            "SHLIB_SUFFIX" => if cfg!(windows) { ".dll" } else if cfg!(target_os = "macos") { ".dylib" } else { ".so" },
+            "SO" => if cfg!(windows) { ".pyd" } else { ".so" },
             "AR" => "ar",
             "ARFLAGS" => "rcs",
             "OPT" => "",
             "BASECFLAGS" => "",
-            "BLDSHARED" => "cc -shared",
+            "BLDSHARED" => if cfg!(windows) { "link.exe" } else { "cc -shared" },
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// Compiler configuration for native extension builds
"CC" => "cc",
"CXX" => "c++",
"CFLAGS" => "",
"CPPFLAGS" => "",
"LDFLAGS" => "",
"LDSHARED" => "cc -shared",
"CCSHARED" => "",
"SHLIB_SUFFIX" => ".so",
"SO" => ".so",
"AR" => "ar",
"ARFLAGS" => "rcs",
"OPT" => "",
"BASECFLAGS" => "",
"BLDSHARED" => "cc -shared",
// Compiler configuration for native extension builds
"CC" => "cc",
"CXX" => "c++",
"CFLAGS" => "",
"CPPFLAGS" => "",
"LDFLAGS" => "",
"LDSHARED" => if cfg!(windows) { "link.exe" } else { "cc -shared" },
"CCSHARED" => "",
"SHLIB_SUFFIX" => if cfg!(windows) { ".dll" } else if cfg!(target_os = "macos") { ".dylib" } else { ".so" },
"SO" => if cfg!(windows) { ".pyd" } else { ".so" },
"AR" => "ar",
"ARFLAGS" => "rcs",
"OPT" => "",
"BASECFLAGS" => "",
"BLDSHARED" => if cfg!(windows) { "link.exe" } else { "cc -shared" },

}
include!(concat!(env!("OUT_DIR"), "/env_vars.rs"));
vars
Expand Down
Loading