Embed presentation
Downloaded 70 times













![Convert from Python: implement template<> void* type_from_python<buffer>::convertible( PyObject* obj){ return PyBytes_Check(obj) ? obj : nullptr; } template<> void type_from_python<buffer>::construct( PyObject* obj, converter::rvalue_from_python_stage1_data* data){ auto storage = reinterpret_cast< converter::rvalue_from_python_storage<buffer>* >( data )->storage.bytes; int size = PyBytes_Size(obj); buffer::data_ptr_t buffer_data = buffer::data_ptr_t(new char[size]); memcpy(buffer_data.get(), PyBytes_AsString(obj), size); new(storage) buffer(buffer_data, size); data->convertible = storage; }](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fboost-140925091223-phpapp01%2f75%2fBoost-Python-C-and-Python-Integration-14-2048.jpg&f=jpg&w=240)










The document outlines the integration of C++ and Python using Boost.Python, highlighting the advantages of both languages. It discusses the setup of Boost, the creation of Python wrappers for C functions, and details on managing data types and conversions between C++ and Python. The document also covers the implementation of custom classes, exception handling, and operator overloading for a seamless API experience.













![Convert from Python: implement template<> void* type_from_python<buffer>::convertible( PyObject* obj){ return PyBytes_Check(obj) ? obj : nullptr; } template<> void type_from_python<buffer>::construct( PyObject* obj, converter::rvalue_from_python_stage1_data* data){ auto storage = reinterpret_cast< converter::rvalue_from_python_storage<buffer>* >( data )->storage.bytes; int size = PyBytes_Size(obj); buffer::data_ptr_t buffer_data = buffer::data_ptr_t(new char[size]); memcpy(buffer_data.get(), PyBytes_AsString(obj), size); new(storage) buffer(buffer_data, size); data->convertible = storage; }](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fboost-140925091223-phpapp01%2f75%2fBoost-Python-C-and-Python-Integration-14-2048.jpg&f=jpg&w=240)








