Skip to content

Commit 3613edf

Browse files
committed
Fix unary function to take PyNumber
Signed-off-by: snowapril <sinjihng@gmail.com>
1 parent b06c0f8 commit 3613edf

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

vm/src/protocol/number.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use crate::{
1111
VirtualMachine,
1212
};
1313

14-
pub type PyNumberUnaryFunc = fn(&PyObject, &VirtualMachine) -> PyResult;
14+
pub type PyNumberUnaryFunc<R = PyObjectRef> = fn(PyNumber, &VirtualMachine) -> PyResult<R>;
1515
pub type PyNumberBinaryFunc = fn(&PyObject, &PyObject, &VirtualMachine) -> PyResult;
1616
pub type PyNumberTernaryFunc = fn(&PyObject, &PyObject, &PyObject, &VirtualMachine) -> PyResult;
1717

@@ -458,7 +458,7 @@ impl PyNumber<'_> {
458458
#[inline]
459459
pub fn int(self, vm: &VirtualMachine) -> Option<PyResult<PyIntRef>> {
460460
self.class().slots.as_number.int.load().map(|f| {
461-
let ret = f(self.obj(), vm)?;
461+
let ret = f(self, vm)?;
462462
let value: PyRef<PyInt> = if !ret.class().is(PyInt::class(&vm.ctx)) {
463463
if !ret.class().fast_issubclass(vm.ctx.types.int_type) {
464464
return Err(vm.new_type_error(format!(
@@ -492,7 +492,7 @@ impl PyNumber<'_> {
492492
#[inline]
493493
pub fn index(self, vm: &VirtualMachine) -> Option<PyResult<PyIntRef>> {
494494
self.class().slots.as_number.index.load().map(|f| {
495-
let ret = f(self.obj(), vm)?;
495+
let ret = f(self, vm)?;
496496
let value: PyRef<PyInt> = if !ret.class().is(PyInt::class(&vm.ctx)) {
497497
if !ret.class().fast_issubclass(vm.ctx.types.int_type) {
498498
return Err(vm.new_type_error(format!(
@@ -526,7 +526,7 @@ impl PyNumber<'_> {
526526
#[inline]
527527
pub fn float(self, vm: &VirtualMachine) -> Option<PyResult<PyRef<PyFloat>>> {
528528
self.class().slots.as_number.float.load().map(|f| {
529-
let ret = f(self.obj(), vm)?;
529+
let ret = f(self, vm)?;
530530
let value: PyRef<PyFloat> = if !ret.class().is(PyFloat::class(&vm.ctx)) {
531531
if !ret.class().fast_issubclass(vm.ctx.types.float_type) {
532532
return Err(vm.new_type_error(format!(

vm/src/types/slot.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ pub(crate) fn len_wrapper(obj: &PyObject, vm: &VirtualMachine) -> PyResult<usize
199199

200200
macro_rules! number_unary_op_wrapper {
201201
($name:ident) => {
202-
|a, vm| vm.call_special_method(a, identifier!(vm, $name), ())
202+
|a, vm| vm.call_special_method(a.deref(), identifier!(vm, $name), ())
203203
};
204204
}
205205
macro_rules! number_binary_op_wrapper {

0 commit comments

Comments
 (0)