MCPcopy Create free account
hub / github.com/pybind/pybind11 / NoisyAlloc

Class NoisyAlloc

tests/test_factory_constructors.cpp:365–388  ·  view source on GitHub ↗

test_reallocations Class that has verbose operator_new/operator_delete calls

Source from the content-addressed store, hash-verified

363 // test_reallocations
364 // Class that has verbose operator_new/operator_delete calls
365 struct NoisyAlloc {
366 NoisyAlloc(const NoisyAlloc &) = default;
367 explicit NoisyAlloc(int i) { py::print(py::str("NoisyAlloc(int {})").format(i)); }
368 explicit NoisyAlloc(double d) { py::print(py::str("NoisyAlloc(double {})").format(d)); }
369 ~NoisyAlloc() { py::print("~NoisyAlloc()"); }
370
371 static void *operator new(size_t s) {
372 py::print("noisy new");
373 return ::operator new(s);
374 }
375 static void *operator new(size_t, void *p) {
376 py::print("noisy placement new");
377 return p;
378 }
379 static void operator delete(void *p) noexcept {
380 py::print("noisy delete");
381 ::operator delete(p);
382 }
383 static void operator delete(void *p, size_t) {
384 py::print("noisy delete size");
385 ::operator delete(p);
386 }
387 static void operator delete(void *, void *) { py::print("noisy placement delete"); }
388 };
389
390 py::class_<NoisyAlloc> pyNoisyAlloc(m, "NoisyAlloc");
391 // Since these overloads have the same number of arguments, the dispatcher will try each of

Callers 1

PYBIND11_OVERRIDEFunction · 0.85

Calls

no outgoing calls

Tested by 1

PYBIND11_OVERRIDEFunction · 0.68