Skip to content

Commit 9914530

Browse files
repro original issue
1 parent 08bca37 commit 9914530

File tree

3 files changed

+126
-37
lines changed

3 files changed

+126
-37
lines changed

tests/CMakeLists.txt

Lines changed: 39 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -94,43 +94,45 @@ endif()
9494

9595
# Full set of test files (you can override these; see below)
9696
set(PYBIND11_TEST_FILES
97-
test_async.cpp
98-
test_buffers.cpp
99-
test_builtin_casters.cpp
100-
test_call_policies.cpp
101-
test_callbacks.cpp
102-
test_chrono.cpp
103-
test_class.cpp
104-
test_constants_and_functions.cpp
105-
test_copy_move.cpp
106-
test_custom_type_casters.cpp
107-
test_docstring_options.cpp
108-
test_eigen.cpp
109-
test_enum.cpp
110-
test_eval.cpp
111-
test_exceptions.cpp
112-
test_factory_constructors.cpp
113-
test_gil_scoped.cpp
114-
test_iostream.cpp
115-
test_kwargs_and_defaults.cpp
116-
test_local_bindings.cpp
117-
test_methods_and_attributes.cpp
118-
test_modules.cpp
119-
test_multiple_inheritance.cpp
120-
test_numpy_array.cpp
121-
test_numpy_dtypes.cpp
122-
test_numpy_vectorize.cpp
123-
test_opaque_types.cpp
124-
test_operator_overloading.cpp
125-
test_pickling.cpp
126-
test_pytypes.cpp
127-
test_sequences_and_iterators.cpp
128-
test_smart_ptr.cpp
129-
test_stl.cpp
130-
test_stl_binders.cpp
131-
test_tagbased_polymorphic.cpp
132-
test_union.cpp
133-
test_virtual_functions.cpp)
97+
test_issue1552.cpp
98+
# test_async.cpp
99+
# test_buffers.cpp
100+
# test_builtin_casters.cpp
101+
# test_call_policies.cpp
102+
# test_callbacks.cpp
103+
# test_chrono.cpp
104+
# test_class.cpp
105+
# test_constants_and_functions.cpp
106+
# test_copy_move.cpp
107+
# test_custom_type_casters.cpp
108+
# test_docstring_options.cpp
109+
# test_eigen.cpp
110+
# test_enum.cpp
111+
# test_eval.cpp
112+
# test_exceptions.cpp
113+
# test_factory_constructors.cpp
114+
# test_gil_scoped.cpp
115+
# test_iostream.cpp
116+
# test_kwargs_and_defaults.cpp
117+
# test_local_bindings.cpp
118+
# test_methods_and_attributes.cpp
119+
# test_modules.cpp
120+
# test_multiple_inheritance.cpp
121+
# test_numpy_array.cpp
122+
# test_numpy_dtypes.cpp
123+
# test_numpy_vectorize.cpp
124+
# test_opaque_types.cpp
125+
# test_operator_overloading.cpp
126+
# test_pickling.cpp
127+
# test_pytypes.cpp
128+
# test_sequences_and_iterators.cpp
129+
# test_smart_ptr.cpp
130+
# test_stl.cpp
131+
# test_stl_binders.cpp
132+
# test_tagbased_polymorphic.cpp
133+
# test_union.cpp
134+
# test_virtual_functions.cpp)
135+
)
134136

135137
# Invoking cmake with something like:
136138
# cmake -DPYBIND11_TEST_OVERRIDE="test_callbacks.cpp;test_pickling.cpp" ..

tests/test_issue1552.cpp

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
// https://github.com/pybind/pybind11/issues/1552
2+
#include <iostream>
3+
4+
#include "pybind11_tests.h"
5+
6+
class Dispatcher;
7+
8+
class Client
9+
{
10+
public:
11+
Client(Dispatcher* disp): PtrD(disp)
12+
{
13+
std::cout << "In Client::Client\n";
14+
}
15+
virtual ~Client(){};
16+
virtual void ProcessEvent()
17+
{
18+
std::cout << "THIS SHOULDN'T HAPPEN --In Client::ProcessEvent\n";
19+
}
20+
Dispatcher* PtrD;
21+
};
22+
23+
class Dispatcher
24+
{
25+
public:
26+
Dispatcher()
27+
{
28+
std::cout << "In Dispatcher::Dispatcher\n";
29+
}
30+
virtual ~Dispatcher(){};
31+
32+
void Dispatch(Client* client)
33+
{
34+
std::cout << "Dispatcher::Dispatch called by " << client << std::endl;
35+
client->ProcessEvent();
36+
}
37+
};
38+
39+
class DispatcherTrampoline : public Dispatcher
40+
{
41+
public:
42+
using Dispatcher::Dispatcher;
43+
};
44+
45+
class ClientTrampoline : public Client
46+
{
47+
public:
48+
using Client::Client;
49+
50+
void ProcessEvent() override
51+
{
52+
PYBIND11_OVERLOAD(void,Client,ProcessEvent,);
53+
}
54+
};
55+
56+
TEST_SUBMODULE(issue1552, m)
57+
{
58+
py::class_<Client,ClientTrampoline> cli(m,"Client");
59+
cli.def(py::init<Dispatcher* >());
60+
cli.def("ProcessEvent",&Client::ProcessEvent);
61+
cli.def_readwrite("PtrD",&Client::PtrD);
62+
63+
py::class_<Dispatcher,DispatcherTrampoline> dsp(m,"Dispatcher");
64+
dsp.def(py::init< >());
65+
dsp.def("Dispatch",&Dispatcher::Dispatch);
66+
}

tests/test_issue1552.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# -*- coding: utf-8 -*-
2+
import pytest
3+
4+
from pybind11_tests import issue1552 as m
5+
6+
7+
class SomeClient(m.Client):
8+
def __init__(self,d):
9+
print("In SomeClient::__init__")
10+
super().__init__(d);
11+
12+
def ProcessEvent(self):
13+
print("in SomeClient::ProcessEvent,about to call self.ProcessEvent")
14+
self.PtrD.Dispatch(self);
15+
16+
17+
def test_main():
18+
# https://github.com/pybind/pybind11/issues/1552
19+
dd = m.Dispatcher()
20+
cl = SomeClient(dd)
21+
dd.Dispatch(cl)

0 commit comments

Comments
 (0)