resonance 1.0.1
Loading...
Searching...
No Matches
Py::Object Class Reference

Reference-counted handle on any Python object, and the root of the PyCXX object hierarchy. More...

#include <object.h>

Inheritance diagram for Py::Object:

Public Member Functions

 Object (PyObject *pyob=Py_None)
 Take a borrowed reference and add a count of its own.
 Object (const Object &other)
 Copy another handle and add a count of its own.
virtual ~Object ()
 Release the reference.
Object & operator= (const Object &other)
 Replace the reference with another handle's.
virtual bool accepts (PyObject *pyob) const
 Whether a reference is acceptable for this handle's type.
Object getAttr (const HxStr &name) const
 Read one attribute.
String str () const
 Produce the text of str() applied to the object.
HxStr as_string () const
 Produce the text of str() applied to the object, as a game string.
Type type () const
 Produce the object's type.
bool isType (const Type &type) const
 Report whether the object's type is a given type.
bool isTuple () const
 Report whether the object is a tuple.
bool isList () const
 Report whether the object is a list.

Public Attributes

PyObject * mPtr
 Wrapped reference, null only between release() and the next assignment.

Protected Member Functions

void release ()
 Release the reference and empty the handle.
void set (PyObject *pyob)
 Replace the reference with a borrowed one and add a count of its own.
void validate ()
 Enforce this type's accepts() test on the stored reference.

Detailed Description

Reference-counted handle on any Python object, and the root of the PyCXX object hierarchy.

Its RTTI descriptor is at 0x0086f6f8. It has no base. The object is eight bytes, the reference at +0x00 and the vptr after it at +0x04. This compiler places the vptr of a class with no base after the data.

The vtable at 0x007cdd00 has three entries, and several translation units emit a private copy of the same three.

Slot Member Address
0 compiler-generated type function 0x0010ee30
1 ~Object 0x0010ee70
2 accepts 0x0010eee8

Every derived class in the hierarchy inherits those three slots and appends its own, so a slot index above 2 always belongs to a derived class.

Two differences from released PyCXX are established rather than assumed. The port has no owned constructor flag, and the constructor below always adds a reference; an owned reference arrives through Py::FromAPI instead. The port also replaced std::string with HxStr throughout.

Constructor & Destructor Documentation

◆ Object() [1/2]

Py::Object::Object ( PyObject * pyob = Py_None)
inlineexplicit

Take a borrowed reference and add a count of its own.

The default produces a handle on None, which is what a member of this type gets when its owner supplies no initialiser.

Parameters
pyobThe reference to wrap.

◆ Object() [2/2]

Py::Object::Object ( const Object & other)
inline

Copy another handle and add a count of its own.

No out-of-line copy survives, because this compiler builds every returned Object directly in the caller's slot. The body comes instead from the inlined copy inside PyShell::ReportError() at 0x005082e0, where a Py::Callable is built from a temporary Py::Object and the three steps are all visible.

Parameters
otherThe handle to copy.

◆ ~Object()

virtual Py::Object::~Object ( )
inlinevirtual

Release the reference.

Ghidra address:
NTSC-U/C: 0x0010ee70
Ghidra address:
PAL: 0x0010f2d0

Member Function Documentation

◆ operator=()

Object & Py::Object::operator= ( const Object & other)
inline

Replace the reference with another handle's.

Parameters
otherThe handle to copy.
Returns
This handle.

◆ accepts()

virtual bool Py::Object::accepts ( PyObject * pyob) const
inlinevirtual

Whether a reference is acceptable for this handle's type.

The base test accepts any non-null reference, so a bare Object wraps anything. A derived class narrows it, and validate() enforces the narrowed test.

Parameters
pyobThe reference to test.
Returns
True when the reference suits this type.
Ghidra address:
NTSC-U/C: 0x0010eee8
Ghidra address:
PAL: 0x0010f348

Reimplemented in Py::Callable, Py::Char, Py::Dict, Py::Float, Py::Int, Py::List, Py::MapBase< T >, Py::MapBase< Object >, Py::SeqBase< T >, Py::SeqBase< Char >, Py::SeqBase< Object >, Py::String, Py::Tuple, and Py::Type.

◆ getAttr()

Object Py::Object::getAttr ( const HxStr & name) const

Read one attribute.

Only the signature is recovered, from the call in PyShell::ReportError() that fetches traceback_str out of the hxutl module. The body is not worked out, so none is written.

Parameters
nameThe attribute name.
Returns
A handle on the attribute.
Ghidra address:
NTSC-U/C: 0x004c3f80
Ghidra address:
PAL: 0x00502100

◆ str()

String Py::Object::str ( ) const

Produce the text of str() applied to the object.

Returns
A new handle on the string object.
Ghidra address:
NTSC-U/C: 0x0055c980
Ghidra address:
PAL: 0x0059dba0

◆ as_string()

HxStr Py::Object::as_string ( ) const

Produce the text of str() applied to the object, as a game string.

Returns
The text.
Ghidra address:
NTSC-U/C: 0x0055cb30
Ghidra address:
PAL: 0x0059dd50

◆ type()

Type Py::Object::type ( ) const

Produce the object's type.

Returns
A new handle on the type object.
Ghidra address:
NTSC-U/C: 0x0055c818
Ghidra address:
PAL: 0x0059da38

◆ isType()

bool Py::Object::isType ( const Type & type) const

Report whether the object's type is a given type.

Parameters
typeThe type to compare with.
Returns
True when the two type objects are the same object.
Ghidra address:
NTSC-U/C: 0x0055ceb0
Ghidra address:
PAL: 0x0059e0f8

◆ isTuple()

bool Py::Object::isTuple ( ) const
inline

Report whether the object is a tuple.

Inline. The type word is compared with PyTuple_Type without a null test, which is how MetHelpScreen::FillTexts() at 0x00313208 expands it.

Returns
True for a tuple.

◆ isList()

bool Py::Object::isList ( ) const
inline

Report whether the object is a list.

Inline, expanded the same way as isTuple().

Returns
True for a list.

◆ release()

void Py::Object::release ( )
inlineprotected

Release the reference and empty the handle.

No address of its own survives. The body appears inlined in the destructor, and released PyCXX declares the member, so it is reconstructed here as the shared form.

◆ set()

void Py::Object::set ( PyObject * pyob)
inlineprotected

Replace the reference with a borrowed one and add a count of its own.

The old reference is released before the new one is stored, and the handle is never left empty in between, which is why the body does not use release().

Parameters
pyobThe reference to wrap.
Ghidra address:
NTSC-U/C: 0x004c6a30
Ghidra address:
PAL: 0x00504cb8

◆ validate()

void Py::Object::validate ( )
inlineprotected

Enforce this type's accepts() test on the stored reference.

A reference the type rejects is released first. A Python error already posted is then rethrown as a bare Py::Exception, because the interpreter already holds the detail; otherwise a Py::TypeError posts CXX: type error. and is thrown instead.

The message form settles the build configuration of the binding. Released PyCXX writes the failing type name into the message when run-time type information is available and falls back on this fixed text otherwise, and the image has the fixed text, so the binding was built with neither _CPPRTTI nor __GNUG__ reaching that block.

Ghidra address:
NTSC-U/C: 0x004c3d10
Ghidra address:
PAL: 0x00501e50

Member Data Documentation

◆ mPtr

PyObject* Py::Object::mPtr

Wrapped reference, null only between release() and the next assignment.

Public because new_reference_to() and several call sites across the script layer read it directly and the image has no accessor for it. A trivial accessor and a public member compile to the same single load, so the evidence cannot distinguish them, and the public member adds no function that no address can be attached to.

+0x00


The documentation for this class was generated from the following file: