发送自魅族手机

-------- 原始邮件 --------
发件人:cplusplus-sig-requ...@python.org
时间:周日 8月31日 18:03
收件人:cplusplus-sig@python.org
主题:Cplusplus-sig Digest, Vol 70, Issue 5

>Send Cplusplus-sig mailing list submissions to
>       cplusplus-sig@python.org
>
>To subscribe or unsubscribe via the World Wide Web, visit
>       https://mail.python.org/mailman/listinfo/cplusplus-sig
>or, via email, send a message with subject or body 'help' to
>       cplusplus-sig-requ...@python.org
>
>You can reach the person managing the list at
>       cplusplus-sig-ow...@python.org
>
>When replying, please edit your Subject line so it is more specific
>than "Re: Contents of Cplusplus-sig digest..."
>
>
>Today's Topics:
>
>   1. Boost python extract on Mac OS Mavericks - seg fault
>      (Brian Bruggeman)
>   2. Re: Boost python extract on Mac OS Mavericks - seg fault
>      (Stefan Seefeld)
>
>
>----------------------------------------------------------------------
>
>Message: 1
>Date: Thu, 28 Aug 2014 17:19:07 -0500
>From: Brian Bruggeman <brian.m.brugge...@gmail.com>
>To: cplusplus-sig@python.org
>Subject: [C++-sig] Boost python extract on Mac OS Mavericks - seg
>       fault
>Message-ID: <67dfd8de-af5f-4f17-ad71-093eea66c...@gmail.com>
>Content-Type: text/plain; charset="windows-1252"
>
>Hi all,
>
>I am having trouble with a really simple example, and I am hoping someone on 
>this list can help me.
>
>I have created a github repo for code in question:
>
>    git clone g...@github.com:brianbruggeman/boost_python_hello_world.git
>
>I have also created a stack overflow question:
>
>    http://stackoverflow.com/q/25533329/631199
>
>The basic problem is as follows:
>
>    Currently, I am able to compile cleanly, but when executing the code, I 
> receive a segmentation fault. I've narrowed the seg-fault down to the line 
> which actually uses boost::python::extract.
>
>Code:
>
>    #include <boost/python.hpp>
>    #include <iostream>
>
>    namespace bp = boost::python;
>
>    // Embedding python
>    int main(int argc, char** argv) {
>        int data = 0;
>        Py_Initialize();
>        PyRun_SimpleString("data = 1");
>        bp::object 
> module(bp::handle<>(bp::borrowed(PyImport_AddModule("__main__"))));
>        bp::object dictionary = module.attr("__dict__");
>        bp::object data_obj = dictionary["data"];
>        // Error: The following line has the segmentation fault...
>        data = bp::extract<int>(data_obj);
>        std::cout << "data = " << data << std::endl;
>        Py_Finalize();
>        return 0;
>    }
>
>CMakeLists.txt:
>
>    project(hello)
>    cmake_minimum_required(VERSION 2.8)
>
>    FIND_PACKAGE(PythonInterp)
>    FIND_PACKAGE(PythonLibs)
>    FIND_PACKAGE(Boost COMPONENTS python)
>
>    include_directories(${PYTHON_INCLUDE_DIRS} ${Boost_INCLUD_DIRS})
>    link_directories(${PYTHON_LIBRARY_DIRS} ${Boost_LIBRARY_DIRS})
>
>    add_executable(hello say_hello.cpp)
>    target_link_libraries(hello
>      ${Boost_LIBRARIES}
>      ${PYTHON_LIBRARIES})
>
>Also for completeness?
>
>I installed Python and Boost::Python using the following?
>
>    brew install python
>    brew install boost ?with-python
>
>Thanks so much in advance!
>
>Brian
>-------------- next part --------------
>An HTML attachment was scrubbed...
>URL: 
><http://mail.python.org/pipermail/cplusplus-sig/attachments/20140828/806de42f/attachment-0001.html>
>
>------------------------------
>
>Message: 2
>Date: Sat, 30 Aug 2014 09:38:06 -0400
>From: Stefan Seefeld <ste...@seefeld.name>
>To: cplusplus-sig@python.org
>Subject: Re: [C++-sig] Boost python extract on Mac OS Mavericks - seg
>       fault
>Message-ID: <5401d3be.9030...@seefeld.name>
>Content-Type: text/plain; charset=windows-1252
>
>On 08/28/2014 06:19 PM, Brian Bruggeman wrote:
>> Hi all,
>>
>> I am having trouble with a really simple example, and I am hoping
>> someone on this list can help me.
>>
>> I have created a github repo for code in question:
>>
>> git clone g...@github.com:brianbruggeman/boost_python_hello_world.git
>>
>> I have also created a stack overflow question:
>>
>> http://stackoverflow.com/q/25533329/631199
>>
>> The basic problem is as follows:
>>
>> Currently, I am able to compile cleanly, but when executing the code,
>> I receive a segmentation fault. I've narrowed the seg-fault down to
>> the line which actually uses boost::python::extract.
>
>As a first step I suggest wrapping the code in a try-block, to catch
>Python exceptions. You may also try extract::check() to verify whether
>the object can in fact be converted to the specified type. (In your
>version a conversion failure would result in an exception.)
>I would also rewrite the code to use more of the Boost.Python API
>(import, exec, etc.)
>
>All that being said, the code compiles and runs fine for me (Fedora 20),
>and I don't see anything wrong.
>
>Regards,
>Stefan
>
>
>
>
>
>>
>> Code:
>>
>> #include <boost/python.hpp>
>> #include <iostream>
>>
>> namespace bp = boost::python;
>>
>> // Embedding python
>> int main(int argc, char** argv) {
>> int data = 0;
>> Py_Initialize();
>> PyRun_SimpleString("data = 1");
>> bp::object
>> module(bp::handle<>(bp::borrowed(PyImport_AddModule("__main__"))));
>> bp::object dictionary = module.attr("__dict__");
>> bp::object data_obj = dictionary["data"];
>> // Error: The following line has the segmentation fault...
>> data = bp::extract<int>(data_obj);
>> std::cout << "data = " << data << std::endl;
>> Py_Finalize();
>> return 0;
>> }
>>
>> CMakeLists.txt:
>>
>> project(hello)
>> cmake_minimum_required(VERSION 2.8)
>>
>> FIND_PACKAGE(PythonInterp)
>> FIND_PACKAGE(PythonLibs)
>> FIND_PACKAGE(Boost COMPONENTS python)
>>
>> include_directories(${PYTHON_INCLUDE_DIRS} ${Boost_INCLUD_DIRS})
>> link_directories(${PYTHON_LIBRARY_DIRS} ${Boost_LIBRARY_DIRS})
>>
>> add_executable(hello say_hello.cpp)
>> target_link_libraries(hello
>> ${Boost_LIBRARIES}
>> ${PYTHON_LIBRARIES})
>>
>> Also for completeness?
>>
>> I installed Python and Boost::Python using the following?
>>
>> brew install python
>> brew install boost ?with-python
>>
>> Thanks so much in advance!
>>
>> Brian
>>
>>
>> _______________________________________________
>> Cplusplus-sig mailing list
>> Cplusplus-sig@python.org
>> https://mail.python.org/mailman/listinfo/cplusplus-sig
>
>
>-- 
>
>      ...ich hab' noch einen Koffer in Berlin...
>
>
>
>------------------------------
>
>Subject: Digest Footer
>
>_______________________________________________
>Cplusplus-sig mailing list
>Cplusplus-sig@python.org
>https://mail.python.org/mailman/listinfo/cplusplus-sig
>
>------------------------------
>
>End of Cplusplus-sig Digest, Vol 70, Issue 5
>********************************************
_______________________________________________
Cplusplus-sig mailing list
Cplusplus-sig@python.org
https://mail.python.org/mailman/listinfo/cplusplus-sig

Reply via email to