mirror of
https://github.com/pybind/pybind11.git
synced 2024-11-26 15:12:01 +00:00
3f589379ec
This commit rewrites the examples that look for constructor/destructor calls to do so via static variable tracking rather than output parsing. The added ConstructorStats class provides methods to keep track of constructors and destructors, number of default/copy/move constructors, and number of copy/move assignments. It also provides a mechanism for storing values (e.g. for value construction), and then allows all of this to be checked at the end of a test by getting the statistics for a C++ (or python mapping) class. By not relying on the precise pattern of constructions/destructions, but rather simply ensuring that every construction is matched with a destruction on the same object, we ensure that everything that gets created also gets destroyed as expected. This replaces all of the various "std::cout << whatever" code in constructors/destructors with `print_created(this)`/`print_destroyed(this)`/etc. functions which provide similar output, but now has a unified format across the different examples, including a new ### prefix that makes mixed example output and lifecycle events easier to distinguish. With this change, relaxed mode is no longer needed, which enables testing for proper destruction under MSVC, and under any other compiler that generates code calling extra constructors, or optimizes away any constructors. GCC/clang are used as the baseline for move constructors; the tests are adapted to allow more move constructors to be evoked (but other types are constructors much have matching counts). This commit also disables output buffering of tests, as the buffering sometimes results in C++ output ending up in the middle of python output (or vice versa), depending on the OS/python version.
271 lines
12 KiB
Plaintext
271 lines
12 KiB
Plaintext
### Object @ 0xdeffd0 created via default constructor
|
|
### MyObject1 @ 0xdeffd0 created MyObject1[1]
|
|
### ref<MyObject1> @ 0x7f6a2e03c4a8 created from pointer 0xdeffd0
|
|
### Object @ 0xe43f50 created via default constructor
|
|
### MyObject1 @ 0xe43f50 created MyObject1[2]
|
|
### ref<Object> @ 0x7fff136845d0 created from pointer 0xe43f50
|
|
### ref<MyObject1> @ 0x7f6a2c32aad8 created via copy constructor with pointer 0xe43f50
|
|
### ref<Object> @ 0x7fff136845d0 destroyed
|
|
### Object @ 0xee8cf0 created via default constructor
|
|
### MyObject1 @ 0xee8cf0 created MyObject1[3]
|
|
### ref<MyObject1> @ 0x7f6a2c32ab08 created from pointer 0xee8cf0
|
|
Reference count = 1
|
|
MyObject1[1]
|
|
### ref<Object> @ 0x7fff136845c8 created via default constructor
|
|
### ref<Object> @ 0x7fff136845c8 assigned via copy assignment pointer 0xdeffd0
|
|
### ref<Object> @ 0x7fff136845a8 created via copy constructor with pointer 0xdeffd0
|
|
MyObject1[1]
|
|
### ref<Object> @ 0x7fff136845a8 destroyed
|
|
### ref<Object> @ 0x7fff136845c8 destroyed
|
|
### ref<Object> @ 0x7fff136845c8 created via default constructor
|
|
### ref<Object> @ 0x7fff136845c8 assigned via copy assignment pointer 0xdeffd0
|
|
MyObject1[1]
|
|
### ref<Object> @ 0x7fff136845c8 destroyed
|
|
### ref<Object> @ 0x7fff136845c8 created via default constructor
|
|
### ref<Object> @ 0x7fff136845c8 assigned via copy assignment pointer 0xdeffd0
|
|
MyObject1[1]
|
|
### ref<Object> @ 0x7fff136845c8 destroyed
|
|
Reference count = 1
|
|
MyObject1[2]
|
|
### ref<Object> @ 0x7fff136845c8 created via default constructor
|
|
### ref<Object> @ 0x7fff136845c8 assigned via copy assignment pointer 0xe43f50
|
|
### ref<Object> @ 0x7fff136845a8 created via copy constructor with pointer 0xe43f50
|
|
MyObject1[2]
|
|
### ref<Object> @ 0x7fff136845a8 destroyed
|
|
### ref<Object> @ 0x7fff136845c8 destroyed
|
|
### ref<Object> @ 0x7fff136845c8 created via default constructor
|
|
### ref<Object> @ 0x7fff136845c8 assigned via copy assignment pointer 0xe43f50
|
|
MyObject1[2]
|
|
### ref<Object> @ 0x7fff136845c8 destroyed
|
|
### ref<Object> @ 0x7fff136845c8 created via default constructor
|
|
### ref<Object> @ 0x7fff136845c8 assigned via copy assignment pointer 0xe43f50
|
|
MyObject1[2]
|
|
### ref<Object> @ 0x7fff136845c8 destroyed
|
|
Reference count = 1
|
|
MyObject1[3]
|
|
### ref<Object> @ 0x7fff136845c8 created via default constructor
|
|
### ref<Object> @ 0x7fff136845c8 assigned via copy assignment pointer 0xee8cf0
|
|
### ref<Object> @ 0x7fff136845a8 created via copy constructor with pointer 0xee8cf0
|
|
MyObject1[3]
|
|
### ref<Object> @ 0x7fff136845a8 destroyed
|
|
### ref<Object> @ 0x7fff136845c8 destroyed
|
|
### ref<Object> @ 0x7fff136845c8 created via default constructor
|
|
### ref<Object> @ 0x7fff136845c8 assigned via copy assignment pointer 0xee8cf0
|
|
MyObject1[3]
|
|
### ref<Object> @ 0x7fff136845c8 destroyed
|
|
### ref<Object> @ 0x7fff136845c8 created via default constructor
|
|
### ref<Object> @ 0x7fff136845c8 assigned via copy assignment pointer 0xee8cf0
|
|
MyObject1[3]
|
|
### ref<Object> @ 0x7fff136845c8 destroyed
|
|
### MyObject1 @ 0xe43f50 destroyed
|
|
### Object @ 0xe43f50 destroyed
|
|
### ref<MyObject1> @ 0x7f6a2c32aad8 destroyed
|
|
### MyObject1 @ 0xdeffd0 destroyed
|
|
### Object @ 0xdeffd0 destroyed
|
|
### ref<MyObject1> @ 0x7f6a2e03c4a8 destroyed
|
|
### Object @ 0xee8310 created via default constructor
|
|
### MyObject1 @ 0xee8310 created MyObject1[4]
|
|
### ref<MyObject1> @ 0x7f6a2e03c4a8 created from pointer 0xee8310
|
|
### Object @ 0xee8470 created via default constructor
|
|
### MyObject1 @ 0xee8470 created MyObject1[5]
|
|
### ref<MyObject1> @ 0x7fff136845d0 created from pointer 0xee8470
|
|
### ref<MyObject1> @ 0x7f6a2c32aad8 created via copy constructor with pointer 0xee8470
|
|
### ref<MyObject1> @ 0x7fff136845d0 destroyed
|
|
### Object @ 0xee95a0 created via default constructor
|
|
### MyObject1 @ 0xee95a0 created MyObject1[6]
|
|
### ref<MyObject1> @ 0x7f6a2c32ab38 created from pointer 0xee95a0
|
|
### MyObject1 @ 0xee8cf0 destroyed
|
|
### Object @ 0xee8cf0 destroyed
|
|
### ref<MyObject1> @ 0x7f6a2c32ab08 destroyed
|
|
<example.MyObject1 object at 0x7f6a2e03c480>
|
|
MyObject1[4]
|
|
### ref<Object> @ 0x7fff136845c8 created via default constructor
|
|
### ref<Object> @ 0x7fff136845c8 assigned via copy assignment pointer 0xee8310
|
|
### ref<Object> @ 0x7fff136845a8 created via copy constructor with pointer 0xee8310
|
|
MyObject1[4]
|
|
### ref<Object> @ 0x7fff136845a8 destroyed
|
|
### ref<Object> @ 0x7fff136845c8 destroyed
|
|
### ref<Object> @ 0x7fff136845c8 created via default constructor
|
|
### ref<Object> @ 0x7fff136845c8 assigned via copy assignment pointer 0xee8310
|
|
MyObject1[4]
|
|
### ref<Object> @ 0x7fff136845c8 destroyed
|
|
### ref<Object> @ 0x7fff136845c8 created via default constructor
|
|
### ref<Object> @ 0x7fff136845c8 assigned via copy assignment pointer 0xee8310
|
|
MyObject1[4]
|
|
### ref<Object> @ 0x7fff136845c8 destroyed
|
|
MyObject1[4]
|
|
### ref<MyObject1> @ 0x7fff136845c8 created via default constructor
|
|
### ref<MyObject1> @ 0x7fff136845c8 assigned via copy assignment pointer 0xee8310
|
|
### ref<MyObject1> @ 0x7fff136845a8 created via copy constructor with pointer 0xee8310
|
|
MyObject1[4]
|
|
### ref<MyObject1> @ 0x7fff136845a8 destroyed
|
|
### ref<MyObject1> @ 0x7fff136845c8 destroyed
|
|
### ref<MyObject1> @ 0x7fff136845c8 created via default constructor
|
|
### ref<MyObject1> @ 0x7fff136845c8 assigned via copy assignment pointer 0xee8310
|
|
MyObject1[4]
|
|
### ref<MyObject1> @ 0x7fff136845c8 destroyed
|
|
### ref<MyObject1> @ 0x7fff136845c8 created via default constructor
|
|
### ref<MyObject1> @ 0x7fff136845c8 assigned via copy assignment pointer 0xee8310
|
|
MyObject1[4]
|
|
### ref<MyObject1> @ 0x7fff136845c8 destroyed
|
|
<example.MyObject1 object at 0x7f6a2c32aab0>
|
|
MyObject1[5]
|
|
### ref<Object> @ 0x7fff136845c8 created via default constructor
|
|
### ref<Object> @ 0x7fff136845c8 assigned via copy assignment pointer 0xee8470
|
|
### ref<Object> @ 0x7fff136845a8 created via copy constructor with pointer 0xee8470
|
|
MyObject1[5]
|
|
### ref<Object> @ 0x7fff136845a8 destroyed
|
|
### ref<Object> @ 0x7fff136845c8 destroyed
|
|
### ref<Object> @ 0x7fff136845c8 created via default constructor
|
|
### ref<Object> @ 0x7fff136845c8 assigned via copy assignment pointer 0xee8470
|
|
MyObject1[5]
|
|
### ref<Object> @ 0x7fff136845c8 destroyed
|
|
### ref<Object> @ 0x7fff136845c8 created via default constructor
|
|
### ref<Object> @ 0x7fff136845c8 assigned via copy assignment pointer 0xee8470
|
|
MyObject1[5]
|
|
### ref<Object> @ 0x7fff136845c8 destroyed
|
|
MyObject1[5]
|
|
### ref<MyObject1> @ 0x7fff136845c8 created via default constructor
|
|
### ref<MyObject1> @ 0x7fff136845c8 assigned via copy assignment pointer 0xee8470
|
|
### ref<MyObject1> @ 0x7fff136845a8 created via copy constructor with pointer 0xee8470
|
|
MyObject1[5]
|
|
### ref<MyObject1> @ 0x7fff136845a8 destroyed
|
|
### ref<MyObject1> @ 0x7fff136845c8 destroyed
|
|
### ref<MyObject1> @ 0x7fff136845c8 created via default constructor
|
|
### ref<MyObject1> @ 0x7fff136845c8 assigned via copy assignment pointer 0xee8470
|
|
MyObject1[5]
|
|
### ref<MyObject1> @ 0x7fff136845c8 destroyed
|
|
### ref<MyObject1> @ 0x7fff136845c8 created via default constructor
|
|
### ref<MyObject1> @ 0x7fff136845c8 assigned via copy assignment pointer 0xee8470
|
|
MyObject1[5]
|
|
### ref<MyObject1> @ 0x7fff136845c8 destroyed
|
|
<example.MyObject1 object at 0x7f6a2c32ab10>
|
|
MyObject1[6]
|
|
### ref<Object> @ 0x7fff136845c8 created via default constructor
|
|
### ref<Object> @ 0x7fff136845c8 assigned via copy assignment pointer 0xee95a0
|
|
### ref<Object> @ 0x7fff136845a8 created via copy constructor with pointer 0xee95a0
|
|
MyObject1[6]
|
|
### ref<Object> @ 0x7fff136845a8 destroyed
|
|
### ref<Object> @ 0x7fff136845c8 destroyed
|
|
### ref<Object> @ 0x7fff136845c8 created via default constructor
|
|
### ref<Object> @ 0x7fff136845c8 assigned via copy assignment pointer 0xee95a0
|
|
MyObject1[6]
|
|
### ref<Object> @ 0x7fff136845c8 destroyed
|
|
### ref<Object> @ 0x7fff136845c8 created via default constructor
|
|
### ref<Object> @ 0x7fff136845c8 assigned via copy assignment pointer 0xee95a0
|
|
MyObject1[6]
|
|
### ref<Object> @ 0x7fff136845c8 destroyed
|
|
MyObject1[6]
|
|
### ref<MyObject1> @ 0x7fff136845c8 created via default constructor
|
|
### ref<MyObject1> @ 0x7fff136845c8 assigned via copy assignment pointer 0xee95a0
|
|
### ref<MyObject1> @ 0x7fff136845a8 created via copy constructor with pointer 0xee95a0
|
|
MyObject1[6]
|
|
### ref<MyObject1> @ 0x7fff136845a8 destroyed
|
|
### ref<MyObject1> @ 0x7fff136845c8 destroyed
|
|
### ref<MyObject1> @ 0x7fff136845c8 created via default constructor
|
|
### ref<MyObject1> @ 0x7fff136845c8 assigned via copy assignment pointer 0xee95a0
|
|
MyObject1[6]
|
|
### ref<MyObject1> @ 0x7fff136845c8 destroyed
|
|
### ref<MyObject1> @ 0x7fff136845c8 created via default constructor
|
|
### ref<MyObject1> @ 0x7fff136845c8 assigned via copy assignment pointer 0xee95a0
|
|
MyObject1[6]
|
|
### ref<MyObject1> @ 0x7fff136845c8 destroyed
|
|
7
|
|
### Object @ 0xee97f0 created via default constructor
|
|
### MyObject1 @ 0xee97f0 created MyObject1[7]
|
|
### ref<MyObject1> @ 0x7f6a2c32ab08 created from pointer 0xee97f0
|
|
MyObject1[7]
|
|
### MyObject1 @ 0xee97f0 destroyed
|
|
### Object @ 0xee97f0 destroyed
|
|
### ref<MyObject1> @ 0x7f6a2c32ab08 destroyed
|
|
### ref<MyObject1> @ 0x7fff136845c8 created via default constructor
|
|
### Object @ 0xee99e0 created via default constructor
|
|
### MyObject1 @ 0xee99e0 created MyObject1[7]
|
|
### ref<MyObject1> @ 0x7f6a2c32ab08 created from pointer 0xee99e0
|
|
### ref<MyObject1> @ 0x7fff136845c8 assigned via copy assignment pointer 0xee99e0
|
|
### ref<MyObject1> @ 0x7fff136845a8 created via copy constructor with pointer 0xee99e0
|
|
MyObject1[7]
|
|
### ref<MyObject1> @ 0x7fff136845a8 destroyed
|
|
### ref<MyObject1> @ 0x7fff136845c8 destroyed
|
|
### MyObject1 @ 0xee99e0 destroyed
|
|
### Object @ 0xee99e0 destroyed
|
|
### ref<MyObject1> @ 0x7f6a2c32ab08 destroyed
|
|
### ref<MyObject1> @ 0x7fff136845c8 created via default constructor
|
|
### Object @ 0xee97f0 created via default constructor
|
|
### MyObject1 @ 0xee97f0 created MyObject1[7]
|
|
### ref<MyObject1> @ 0x7f6a2c32ab08 created from pointer 0xee97f0
|
|
### ref<MyObject1> @ 0x7fff136845c8 assigned via copy assignment pointer 0xee97f0
|
|
MyObject1[7]
|
|
### ref<MyObject1> @ 0x7fff136845c8 destroyed
|
|
### MyObject1 @ 0xee97f0 destroyed
|
|
### Object @ 0xee97f0 destroyed
|
|
### ref<MyObject1> @ 0x7f6a2c32ab08 destroyed
|
|
### ref<MyObject1> @ 0x7fff136845c8 created via default constructor
|
|
### Object @ 0xee99e0 created via default constructor
|
|
### MyObject1 @ 0xee99e0 created MyObject1[7]
|
|
### ref<MyObject1> @ 0x7f6a2c32ab08 created from pointer 0xee99e0
|
|
### ref<MyObject1> @ 0x7fff136845c8 assigned via copy assignment pointer 0xee99e0
|
|
MyObject1[7]
|
|
### ref<MyObject1> @ 0x7fff136845c8 destroyed
|
|
### MyObject1 @ 0xee99e0 destroyed
|
|
### Object @ 0xee99e0 destroyed
|
|
### ref<MyObject1> @ 0x7f6a2c32ab08 destroyed
|
|
### MyObject1 @ 0xee95a0 destroyed
|
|
### Object @ 0xee95a0 destroyed
|
|
### ref<MyObject1> @ 0x7f6a2c32ab38 destroyed
|
|
### MyObject1 @ 0xee8470 destroyed
|
|
### Object @ 0xee8470 destroyed
|
|
### ref<MyObject1> @ 0x7f6a2c32aad8 destroyed
|
|
### MyObject1 @ 0xee8310 destroyed
|
|
### Object @ 0xee8310 destroyed
|
|
### ref<MyObject1> @ 0x7f6a2e03c4a8 destroyed
|
|
### MyObject2 @ 0xe43f50 created MyObject2[8]
|
|
### MyObject2 @ 0xee95a0 created MyObject2[6]
|
|
### MyObject2 @ 0xee95d0 created MyObject2[7]
|
|
<example.MyObject2 object at 0x7f6a2dfc8768>
|
|
MyObject2[8]
|
|
MyObject2[8]
|
|
MyObject2[8]
|
|
MyObject2[8]
|
|
<example.MyObject2 object at 0x7f6a2dfc86c0>
|
|
MyObject2[6]
|
|
MyObject2[6]
|
|
MyObject2[6]
|
|
MyObject2[6]
|
|
<example.MyObject2 object at 0x7f6a2c32d030>
|
|
MyObject2[7]
|
|
MyObject2[7]
|
|
MyObject2[7]
|
|
MyObject2[7]
|
|
### MyObject2 @ 0xee95a0 destroyed
|
|
### MyObject2 @ 0xe43f50 destroyed
|
|
### MyObject3 @ 0xee9ac0 created MyObject3[9]
|
|
### MyObject3 @ 0xe43f90 created MyObject3[8]
|
|
### MyObject3 @ 0xeea7d0 created MyObject3[9]
|
|
### MyObject2 @ 0xee95d0 destroyed
|
|
<example.MyObject3 object at 0x7f6a2dfc8768>
|
|
MyObject3[9]
|
|
MyObject3[9]
|
|
MyObject3[9]
|
|
MyObject3[9]
|
|
<example.MyObject3 object at 0x7f6a2dfc86c0>
|
|
MyObject3[8]
|
|
MyObject3[8]
|
|
MyObject3[8]
|
|
MyObject3[8]
|
|
<example.MyObject3 object at 0x7f6a2c32d068>
|
|
MyObject3[9]
|
|
MyObject3[9]
|
|
MyObject3[9]
|
|
MyObject3[9]
|
|
### MyObject3 @ 0xe43f90 destroyed
|
|
### MyObject3 @ 0xee9ac0 destroyed
|
|
Instances not destroyed: [0, 0, 0, 1, 0]
|
|
### MyObject3 @ 0xeea7d0 destroyed
|
|
Instances not destroyed: [0, 0, 0, 0, 0]
|
|
Object value constructions: [[], ['MyObject1[1]', 'MyObject1[2]', 'MyObject1[3]', 'MyObject1[4]', 'MyObject1[5]', 'MyObject1[6]', 'MyObject1[7]', 'MyObject1[7]', 'MyObject1[7]', 'MyObject1[7]'], ['MyObject2[8]', 'MyObject2[6]', 'MyObject2[7]'], ['MyObject3[9]', 'MyObject3[8]', 'MyObject3[9]'], ['from pointer', 'from pointer', 'from pointer', 'from pointer', 'from pointer', 'from pointer', 'from pointer', 'from pointer', 'from pointer', 'from pointer']]
|
|
Default constructions: [10, 0, 0, 0, 30]
|
|
Copy constructions: [0, 0, 0, 0, 12]
|
|
Copy assignments: [0, 0, 0, 0, 30]
|
|
Move assignments: [0, 0, 0, 0, 0]
|