◐ Shell
clean mode source ↗

PyObject in rustpython_vm::object - Rust

pub struct PyObject(/* private fields */);
Source§
Source§

Source
Source

Source§

Source

Source§
Source

Atomically try to create a strong reference. Returns None if the strong count is already 0 (object being destroyed). Uses CAS to prevent the TOCTOU race between checking strong_count and incrementing it.

Source

Like try_to_owned, but from a raw pointer.

Uses addr_of! to access ref_count without forming &PyObject, minimizing the borrow scope when the pointer may be stale (e.g. cache-hit paths protected by version guards).

§Safety

ptr must point to a live (not yet deallocated) PyObject, or to memory whose ref_count field is still atomically readable (same guarantee as _Py_TryIncRefShared).

Source§
Source
Source
Source

👎Deprecated:

use downcastable instead

Source

👎Deprecated:

use downcast_unchecked_ref instead

Force to return payload as T.

§Safety

The actual payload type must be T.

Source

👎Deprecated:

use downcast_ref instead

Source
Source
Source

👎Deprecated:

use downcast_ref_if_exact instead

Source
Source

Set the dict field. Returns Err(dict) if this object does not have a dict field in the first place.

Source

👎Deprecated:

use downcast_ref instead

Source

Check if this object can be downcast to T.

Source

Attempt to downcast this reference to a subclass.

Source

Attempt to downcast this reference to a subclass.

Source
Source
§Safety

T must be the exact payload type

Source
Source
Source
Source

_PyObject_GC_IS_TRACKED

Source

Get the referents (objects directly referenced) of this object. Uses the full traverse including dict and slots.

Source

Call del if present, without triggering object deallocation. Used by GC to call finalizers before breaking cycles. This allows proper resurrection detection. PyObject_CallFinalizerFromDealloc

Source

Clear weakrefs but collect callbacks instead of calling them. This is used by GC to ensure ALL weakrefs are cleared BEFORE any callbacks run. Returns collected callbacks as (PyRef, callback) pairs.

Source

Get raw pointers to referents without incrementing reference counts. This is used during GC to avoid reference count manipulation. tp_traverse visits objects without incref

§Safety

The returned pointers are only valid as long as the object is alive and its contents haven’t been modified.

Source

Pop edges from this object for cycle breaking. Returns extracted child references that were removed from this object (tp_clear). This is used during garbage collection to break circular references.

§Safety
  • ptr must be a valid pointer to a PyObject
  • The caller must have exclusive access (no other references exist)
  • This is only safe during GC when the object is unreachable
Source

Clear this object for cycle breaking (tp_clear). This version takes &self but should only be called during GC when exclusive access is guaranteed.

§Safety
  • The caller must guarantee exclusive access (no other references exist)
  • This is only safe during GC when the object is unreachable
Source

Check if this object has clear capability (tp_clear)

Source§
Source
Source
Source

PyObject_CallArg series

Source

PyObject_Call

Source

Vectorcall: call with owned positional args + optional kwnames. Falls back to FuncArgs-based call if no vectorcall slot.

Source§

Source
Source

Source§

Source
Source
Source
Source
Source
Source

Source§
Source

Takes an object and returns an iterator for it. This is typically a new iterator but if the argument is an iterator, this returns itself.

Source
Source
Source

Get an attribute by name. attr_name can be a &str, String, or PyStrRef.

Source
Source
Source
Source
Source

CPython _PyObject_GenericGetAttrWithDict

Source
Source
Source
Source
Source
Source
Source
Source

Real issubclass check without going through subclasscheck This is equivalent to CPython’s _PyObject_RealIsSubclass which just calls recursive_issubclass

Source

Determines if self is a subclass of cls, either directly, indirectly or virtually via the subclasscheck magic method. PyObject_IsSubclass/object_issubclass

Source

Determines if self is an instance of cls, either directly, indirectly or virtually via the instancecheck magic method.

Source
Source
Source
Source
Source
Source
Source
Source
Source

Equivalent to CPython’s _PyObject_LookupSpecial Looks up a special method in the type’s MRO without checking instance dict. Returns None if not found (masking AttributeError like CPython).

Source§

Source
Source

Source§
Source§

Converts this type into a shared reference of the (usually inferred) input type.

Source§
Source§

Converts this type into a shared reference of the (usually inferred) input type.

Source§
Source§

Converts this type into a shared reference of the (usually inferred) input type.

Source§
Source§

Converts this type into a shared reference of the (usually inferred) input type.

Source§
Source§

Converts this type into a shared reference of the (usually inferred) input type.

Source§
Source§

Converts this type into a shared reference of the (usually inferred) input type.

Source§
Source§

Converts this type into a shared reference of the (usually inferred) input type.

Source§
Source§

Converts this type into a shared reference of the (usually inferred) input type.

Source§
Source§

Converts this type into a shared reference of the (usually inferred) input type.

Source§
Source§

Converts this type into a shared reference of the (usually inferred) input type.

Source§
Source§
Source§
Source§
Source§
Source§
Source§
Source§
Source§
Source§
Source§
Source§
Source§

Converts to this type from the input type.

Source§
Source§

The resulting type after obtaining ownership.

Source§

Creates owned data from borrowed data, usually by cloning. Read more

1.63.0 · Source§

Uses borrowed data to replace owned data, usually by cloning. Read more

Source§

Source§

Source§
Source§

DO notice that call trace on PyObject means apply tracer_fn on PyObject’s children, not like call trace on PyObjectRef which apply tracer_fn on PyObjectRef itself

Source§

Extract all owned child PyObjectRefs for circular reference resolution (tp_clear). Called just before object deallocation to break circular references. Default implementation does nothing.

§
§
§
§
§
§
§

Source§
Source§
Source§
Source§
Source§
Source§
Source§
Source§

Determines if obj actually an instance of cls, this doesn’t call instancecheck, so only use this if cls is known to have not overridden the base instancecheck magic method.

Source§
Source§
Source§

Source§

Source§

Source§

Source§
Source§

Returns the argument unchanged.

Source§
Source§

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§
Source§

Source§

Source§

Source§

Source§

Source§

Source§
Source§

Returns the String produced by Ts Debug implementation.

§Examples
use malachite_base::strings::ToDebugString;

assert_eq!([1, 2, 3].to_debug_string(), "[1, 2, 3]");
assert_eq!(
    [vec![2, 3], vec![], vec![4]].to_debug_string(),
    "[[2, 3], [], [4]]"
);
assert_eq!(Some(5).to_debug_string(), "Some(5)");
Source§
Source§

The type returned in the event of a conversion error.

Source§

Performs the conversion.

Source§
Source§

The type returned in the event of a conversion error.

Source§

Performs the conversion.

Source§

Source§

Source§