diff --git a/src/Magnum/Python.h b/src/Magnum/Python.h index 7f685ad..ba2b44d 100644 --- a/src/Magnum/Python.h +++ b/src/Magnum/Python.h @@ -48,6 +48,17 @@ template PyImageViewHolder pyImageViewHolder(const T& view, pybind11 return PyImageViewHolder{new T{view}, owner}; } +/* This is a variant of https://github.com/pybind/pybind11/issues/1178, + implemented on the client side instead of patching pybind itself */ +template struct PyNonDestructibleBaseDeleter; +template struct PyNonDestructibleBaseDeleter { + void operator()(T*) { CORRADE_ASSERT_UNREACHABLE(); /* LCOV_EXCL_LINE */ } +}; +template struct PyNonDestructibleBaseDeleter { + void operator()(T* ptr) { delete ptr; } +}; +template using PyNonDestructibleClass = pybind11::class_::value>>>; + } PYBIND11_DECLARE_HOLDER_TYPE(T, Magnum::PyImageViewHolder) diff --git a/src/python/magnum/CMakeLists.txt b/src/python/magnum/CMakeLists.txt index c570b16..548c466 100644 --- a/src/python/magnum/CMakeLists.txt +++ b/src/python/magnum/CMakeLists.txt @@ -118,7 +118,9 @@ if(NOT MAGNUM_BUILD_STATIC) if(Magnum_Shaders_FOUND) pybind11_add_module(magnum_shaders SYSTEM ${magnum_shaders_SRCS}) - target_include_directories(magnum_shaders PRIVATE ${PROJECT_SOURCE_DIR}/src/python) + target_include_directories(magnum_shaders PRIVATE + ${PROJECT_SOURCE_DIR}/src + ${PROJECT_SOURCE_DIR}/src/python) target_link_libraries(magnum_shaders PRIVATE Magnum::Shaders) set_target_properties(magnum_shaders PROPERTIES FOLDER "python" diff --git a/src/python/magnum/NonDestructible.h b/src/python/magnum/NonDestructible.h deleted file mode 100644 index 2e5d1e0..0000000 --- a/src/python/magnum/NonDestructible.h +++ /dev/null @@ -1,55 +0,0 @@ -#ifndef magnum_NonDestructible_h -#define magnum_NonDestructible_h -/* - This file is part of Magnum. - - Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019 - Vladimír Vondruš - - Permission is hereby granted, free of charge, to any person obtaining a - copy of this software and associated documentation files (the "Software"), - to deal in the Software without restriction, including without limitation - the rights to use, copy, modify, merge, publish, distribute, sublicense, - and/or sell copies of the Software, and to permit persons to whom the - Software is furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included - in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - DEALINGS IN THE SOFTWARE. -*/ - -#include -#include - -#include "magnum/bootstrap.h" - -namespace pybind11 { - template class class_; -} - -/* This is a variant of https://github.com/pybind/pybind11/issues/1178, - implemented on the client side instead of patching pybind itself */ -namespace magnum { - -template struct NonDestructibleBaseDeleter; -template struct NonDestructibleBaseDeleter { - void operator()(T*) { CORRADE_ASSERT_UNREACHABLE(); /* LCOV_EXCL_LINE */ } -}; -template struct NonDestructibleBaseDeleter { - void operator()(T* ptr) { delete ptr; } -}; - -template using NonDestructible = py::class_::value>>>; - -template using NonDestructibleBase = py::class_::value>>>; - -} - -#endif diff --git a/src/python/magnum/gl.cpp b/src/python/magnum/gl.cpp index 55cded7..a46b5df 100644 --- a/src/python/magnum/gl.cpp +++ b/src/python/magnum/gl.cpp @@ -44,7 +44,6 @@ #include "corrade/EnumOperators.h" #include "magnum/bootstrap.h" -#include "magnum/NonDestructible.h" #include "magnum/PyGL.h" namespace magnum { @@ -60,7 +59,7 @@ void gl(py::module& m) { m.doc() = "OpenGL wrapping layer"; /* Abstract shader program */ - NonDestructible{m, + PyNonDestructibleClass{m, "AbstractShaderProgram", "Base for shader program implementations"}; /** @todo more */ @@ -291,7 +290,7 @@ void gl(py::module& m) { .value("STENCIL", GL::FramebufferClear::Stencil); corrade::enumOperators(framebufferClear); - NonDestructible abstractFramebuffer{m, + PyNonDestructibleClass abstractFramebuffer{m, "AbstractFramebuffer", "Base for default and named framebuffers"}; abstractFramebuffer @@ -302,10 +301,10 @@ void gl(py::module& m) { .def("read", static_cast(&GL::AbstractFramebuffer::read), "Read block of pixels from the framebuffer to an image view"); - NonDestructibleBase defaultFramebuffer{m, + PyNonDestructibleClass defaultFramebuffer{m, "DefaultFramebuffer", "Default framebuffer"}; - NonDestructibleBase framebuffer{m, + PyNonDestructibleClass framebuffer{m, "Framebuffer", "Framebuffer"}; py::class_{framebuffer, "ColorAttachment", "Color attachment"} diff --git a/src/python/magnum/shaders.cpp b/src/python/magnum/shaders.cpp index d664b6d..07dd605 100644 --- a/src/python/magnum/shaders.cpp +++ b/src/python/magnum/shaders.cpp @@ -29,15 +29,16 @@ #include #include +#include "Magnum/Python.h" + #include "corrade/EnumOperators.h" #include "magnum/bootstrap.h" -#include "magnum/NonDestructible.h" namespace magnum { namespace { -template void vertexColor(NonDestructibleBase, GL::AbstractShaderProgram>& c) { +template void vertexColor(PyNonDestructibleClass, GL::AbstractShaderProgram>& c) { /* Attributes */ c.attr("COLOR3") = GL::DynamicAttribute{ GL::DynamicAttribute::Kind::Generic, 3, @@ -71,9 +72,9 @@ void shaders(py::module& m) { /* 2D/3D vertex color shader */ { - NonDestructibleBase vertexColor2D{m, + PyNonDestructibleClass vertexColor2D{m, "VertexColor2D", "2D vertex color shader"}; - NonDestructibleBase vertexColor3D{m, + PyNonDestructibleClass vertexColor3D{m, "VertexColor3D", "3D vertex color shader"}; vertexColor2D.attr("POSITION") = GL::DynamicAttribute{ GL::DynamicAttribute::Kind::Generic, 0, @@ -89,7 +90,7 @@ void shaders(py::module& m) { /* Phong shader */ { - NonDestructibleBase phong{m, + PyNonDestructibleClass phong{m, "Phong", "Phong shader"}; phong.attr("POSITION") = GL::DynamicAttribute{ GL::DynamicAttribute::Kind::Generic, 0,