Merge pull request #3226 from youknowone/thread-lock-new

Forbid calls to _thread.LockType.__new__
This commit is contained in:
Jim Fasarakis-Hilliard
2021-10-05 15:58:08 +03:00
committed by GitHub

View File

@@ -5,7 +5,7 @@ use crate::{
exceptions::{self, IntoPyException},
function::{ArgCallable, FuncArgs, KwArgs, OptionalArg},
py_io,
slots::{SlotGetattro, SlotSetattro},
slots::{SlotConstructor, SlotGetattro, SlotSetattro},
utils::Either,
IdProtocol, ItemProtocol, PyClassImpl, PyObjectRef, PyRef, PyResult, PyValue, TypeProtocol,
VirtualMachine,
@@ -103,7 +103,7 @@ impl fmt::Debug for PyLock {
}
}
#[pyimpl]
#[pyimpl(with(SlotConstructor))]
impl PyLock {
#[pymethod]
#[pymethod(name = "acquire_lock")]
@@ -138,6 +138,13 @@ impl PyLock {
}
}
impl SlotConstructor for PyLock {
type Args = FuncArgs;
fn py_new(_cls: PyTypeRef, _args: Self::Args, vm: &VirtualMachine) -> PyResult {
Err(vm.new_type_error("cannot create '_thread.lock' instances".to_owned()))
}
}
pub type RawRMutex = RawReentrantMutex<RawMutex, RawThreadId>;
#[pyclass(module = "thread", name = "RLock")]
#[derive(PyValue)]