Skip to content
Open
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
7 changes: 3 additions & 4 deletions src/cpyrt/CPPInstance.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ static PyObject* op_destruct(CPPInstance* self) {

//= cpyrt object dispatch support =========================================
static PyObject* op_dispatch(PyObject* self, PyObject* args,
PyObject* /* kdws */) {
PyObject* /* kwds */) {
// User-side __dispatch__ method to allow selection of a specific overloaded
// method. The actual selection is in the __overload__() method of
// CPPOverload.
Expand Down Expand Up @@ -554,8 +554,7 @@ static inline void* cast_actual(void* obj) {
return address;

interop::TCppScope_t klass = ((CPPClass*)Py_TYPE((PyObject*)obj))->fCppType;
interop::TCppScope_t clActual =
klass /* XXX: interop::GetActualClass(klass, address) */;
interop::TCppScope_t clActual = interop::GetActualClass(klass, address);
if (clActual && clActual != klass) {
intptr_t offset = interop::GetBaseOffset(
clActual, klass, address, -1 /* down-cast */, true /* report errors */);
Expand Down Expand Up @@ -827,7 +826,7 @@ static PyObject* op_str(CPPInstance* self) {
interop::TCppScope_t rnsID =
interop::GetScope(TypeManip::extract_namespace(rcname));
PyCallable* pyfunc =
Utility::FindBinaryOperator("std::ostream&", rcname, "<<", rnsID);
Utility::FindBinaryOperator("std::ostream", rcname, "<<", rnsID);
if (!pyfunc)
continue;

Expand Down
2 changes: 1 addition & 1 deletion src/cpyrt/CPPMethod.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ void cpyrt::CPPMethod::SetPyError_(PyObject* msg) {
// C++ method to give some context.
// 2. A C++ exception has occured:
// Augment the exception message with the docstring of this method
// 3. A Python exception has occured with a traceback:
// 3. A Python exception has occurred with a traceback:
// Do nothing, Python exceptions are already informative enough
// 4. If the Python exception has no traceback hinting to an internally set
// error stack,
Expand Down
29 changes: 29 additions & 0 deletions test/test_pythonify.py
Original file line number Diff line number Diff line change
Expand Up @@ -617,3 +617,32 @@ def test03_write_access_to_globals(self):
assert proxy.__get__(proxy, None) == 3

cppjit.gbl.ns_example01.gMyGlobalInt = oldval


class TestPINNEDCOMPARISON:
def test01_pinned_base_compares_equal(self):
"""Comparison downcasts to the actual class before comparing addresses"""

import cppjit
from cppjit._pythonization import pin_type

cppjit.cppdef("""\
namespace PinnedCmp {
struct B1 { virtual ~B1() {} int a = 1; };
struct B2 { virtual ~B2() {} int b = 2; };
struct D : B1, B2 {};
D g_d;
D* get_d() { return &g_d; }
B2* get_b2() { return static_cast<B2*>(&g_d); }
}""")

ns = cppjit.gbl.PinnedCmp

# pinning keeps the B2 proxy from being downcast on creation, so the
# B2 subobject address is what reaches the comparison
pin_type(ns.B2)
d, b2 = ns.get_d(), ns.get_b2()
assert type(b2).__cpp_name__ == "PinnedCmp::B2"

assert d == b2
assert not (d != b2)
Loading