Re: [C++-sig] [c++-sig] python std::string assignment

2008-10-17 Thread Stefan Seefeld
Furkan Kuru wrote: Hello, I have exported a struct containing a std::string field and used it one of my py files. I used same py and pyd file in another operating system (vista). It just stuck without giving any errors. I figured out that the std::string field gets a limited space (as it shou

Re: [C++-sig] [c++-sig] python std::string assignment

2008-10-17 Thread Stefan Seefeld
Furkan Kuru wrote: By the way I tried "resize"ing and "reserve"ing of strings by name.resize(1024); or name.reserve(1024); but it did not fix the problem. It seems that it allows up to 15 chars + null character total 16chars. I think strings set longer than 15 chars corrupts the stack. I re

Re: [C++-sig] [c++-sig] python std::string assignment

2008-10-17 Thread Stefan Seefeld
Furkan Kuru wrote: b) I am using Visual Studio 2005 and Windows Xp as development environment. I do not know too much about configuration details. You should. Did you compile boost yourself or did you obtain a binary package from somewhere else ? As I said, you have to make sure boost (nota

Re: [C++-sig] [c++-sig] python std::string assignment

2008-10-17 Thread Stefan Seefeld
Furkan Kuru wrote: Do different configured PCs have different memory allocation routines? Because a friend of mine tested the application on a different computer running same os (vista) without anyproblems. I have no idea what you mean by 'differently configured PCs', but I'd suggest you t

Re: [C++-sig] [c++-sig] python std::string assignment

2008-10-17 Thread Stefan Seefeld
Furkan Kuru wrote: Apart from assinging a string passing a "longer" string to a function does not work either. "does not work" isn't an acceptable failure description. Please be specific. I think the second parameter "local://activation.html" can not be converted to std::string. What makes y

Re: [C++-sig] returning vector arrays and multiple values

2008-10-23 Thread Stefan Seefeld
Leonard Ritter wrote: i have a function which i wish to wrap, which returns a float buffer and an integer: std::vector get_recording_buffer(/* out */ size_t &write_ptr); alternatively, the function could also just return a pointer to a float array: const float *get_recording_buffer(/* out *

Re: [C++-sig] Help wrapping an unconventional setter

2008-10-23 Thread Stefan Seefeld
Craig Bosma wrote: Hi, I'm pretty new to Boost.Python, and am trying to wrap a simple class similar to: class Foo { public: float value() const { return value_; } float& value() { return value_; } private: float value_; }; I have no problem wrapping value() as a read-only propert

Re: [C++-sig] Calling import() multiple times for the same module

2008-10-24 Thread Stefan Seefeld
Robert Dailey wrote: Hi, What happens if I do the following? using namespace boost::python; import( "__main__" ).attr( "new_global" ) = 40.0f; import( "__main__" ).attr( "another_global" ) = 100.0f: My main concern here is performance. I'm wondering if each call to import() results in a disk

Re: [C++-sig] How to create embedded packages?

2008-10-24 Thread Stefan Seefeld
Robert Dailey wrote: my_package/ module1/ module2/ module3/ However, the Boost.Python documentation only explains one specific way of doing this, and that involves actually having PYD files for module1, module2, and module3. Since this is all done from C++, I need to be able to create

Re: [C++-sig] Private construction for python objects?

2008-10-24 Thread Stefan Seefeld
Robert Dailey wrote: Hi, I have a C++ class that I'm exposing to Python via the Boost.Python library. This specific class is only created from C++. In other words, it doesn't serve the user very much good to construct an instance of this class from Python. A typical use case for obtaining an

Re: [C++-sig] new to python; old to C++

2008-10-31 Thread Stefan Seefeld
Alan Baljeu wrote: Question: which python-calling-C++ tool should I try? Wow, quiet group. I guess I'll try pybindgen first. That may be because the question is not quite clear. First of all, you should realize that, despite the generic name of this list, this is mostly about boost.

Re: [C++-sig] new to python; old to C++

2008-10-31 Thread Stefan Seefeld
Gustavo Carneiro wrote: 2008/10/31 Stefan Seefeld <[EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]>> That may be because the question is not quite clear. First of all, you should realize that, despite the generic name of this list, this is mostly about boost.python

Re: [C++-sig] new to python; old to C++

2008-10-31 Thread Stefan Seefeld
Alan Baljeu wrote: Surprisingly, I haven't seen a boost recommendation. That's probably just as well since I don't care much for template syntax. boost.python is a C++ - Python language binding library. It allows a very concise definition of what you want to export, and how (with what poli

Re: [C++-sig] [pybindgen] references?

2008-11-03 Thread Stefan Seefeld
Alan Baljeu wrote: I just read the tutorial page on pybindgen, but it doesn't talk about reference types. 99% of my C++ code involves passing around things like foo&, so this is significant to me. How is it done? If you need fine-grained control about argument passing policies (as soo

Re: [C++-sig] PyEval_EvalCode

2008-11-11 Thread Stefan Seefeld
Alan Baljeu wrote: I was reading some legacy code we have here, and discovered an unexpected idiom. Starting from C++, we create a dictionary, store a few named constants in there, and then call PyEval_EvalCode passing in the dictionary. The code it calls is a bunch of python files generated

Re: [C++-sig] PyEval_EvalCode

2008-11-12 Thread Stefan Seefeld
Alan Baljeu wrote: My question probably derives from ignorance of the Python way. I kind of assumed people would advocate defining classes and methods, and then calling those methods. You apparently see things otherwise. Not really. I just see it as an orthogonal problem to the question you

Re: [C++-sig] PyEval_EvalCode

2008-11-12 Thread Stefan Seefeld
Alan Baljeu wrote: To solve this, I intend to write as much Python as possible, to drive C++ objects, so I won't have to recompile, or restart my environment. (Previous use of python had a slightly different goal: use Python minimally for a dynamic modeling problem) So Python code will consist

Re: [C++-sig] c++ object deleted

2008-11-12 Thread Stefan Seefeld
Renato Araujo wrote: Hi all, Is possible in boost::python create a exception when the c++ object is deleted internal, and you try use the python object. Because here I got a core when I try do this. I'm not sure whether it's technically possible, but I do believe this is a bad idea: Except

Re: [C++-sig] looking up functions

2008-11-13 Thread Stefan Seefeld
Alan Baljeu wrote: I'm reading the Python extension tutorial, and I cannot believe the embedding section. It tells me the only way to call a python function is to callout to python to pass back a function object which I then save so I can call it when I need to. This seems ridiculous. Surel

Re: [C++-sig] looking up functions

2008-11-13 Thread Stefan Seefeld
Alan Baljeu wrote: As best I could figure, I needed to write Python code, execute a script file, get that code to call a C function that I register, in order to have that function. At least the tutorial implied that was the way. I'm confused. In your last mail you asked for how to get hold

Re: [C++-sig] looking up functions

2008-11-13 Thread Stefan Seefeld
Alan Baljeu wrote: I misspoke. I want a Python function. I was confused by the lack of any PyModule_GetFunction or anything resembling that in the API. This is because there is nothing special about functions, as far as retrieving them from a module('s namespace) is concerned. You just

Re: [C++-sig] wrapper and shared_ptr - how to combine?

2008-11-15 Thread Stefan Seefeld
Leonard Ritter wrote: class_which I did, but that gives me a compiler error if Actor is abstract, and if I declare it non-abstract, calls to wrapping PyActor methods fail in Python. I guess that this approach does not work with wrapper classes, or the syntax is different. Please post specific

Re: [C++-sig] console I/O

2008-11-24 Thread Stefan Seefeld
Alan Baljeu wrote: I followed the directions there, but that is incomplete. I can printf from C to the console, but print from Python does nothing. Something in the Python API must be employed. But perhaps I should take this to the main Python list. Definitely. Regards, Stefan

Re: [C++-sig] Pyste,Py++: equivalent of swig typemaps?

2008-11-30 Thread Stefan Seefeld
Mihail Konstantinov wrote: Hello, due to limitations of swig I am currently learning Py++ and Pyste (because it seems currently to be better documented than Py++). Does Pyste or Py++ offer typemaps like swig (http://www.swig.org/Doc1.3/SWIGDocumentation.html#Python_nn53) that allow any seque

Re: [C++-sig] Pyste,Py++: equivalent of swig typemaps?

2008-11-30 Thread Stefan Seefeld
Mihail Konstantinov wrote: Thank you Stefan, the typemaps are required, when C++ functions are wrapped that expect arguments which have no direct corresponding type in python, or when standard types have to be interpreted differently. For example a function void parse_args(int argc, char **arg

Re: [C++-sig] boost.python: private copy constructor problem

2008-12-02 Thread Stefan Seefeld
Mihail Konstantinov wrote: Hello, I am still in the early process of learning boost.python. I have reduced my problem to the following code: #include using namespace boost::python; class A{ private: A(const A&){}; //no public copy constructor }; class B: public A{ public: B(){}; }; BOOST_PY

Re: [C++-sig] boost.python: private copy constructor problem

2008-12-02 Thread Stefan Seefeld
Mihail Konstantinov wrote: gcc.compile.c++ bin/gcc-4.1.2/debug/boost.o boost.cpp: In copy constructor ‘B::B(const B&)’: As this error message suggests: as B derives from A, it is (by default) non-copyable, too. That you have to tell python, too, thus: class_ a("A", init<>); class_, nonco

Re: [C++-sig] boost.python: private copy constructor problem

2008-12-02 Thread Stefan Seefeld
Mihail Konstantinov wrote: One more question about the syntax. You cited http://www.boost.org/doc/libs/1_37_0/libs/python/doc/v2/class.html#class_-spec which specifies the syntax as "class_" so that I thought I have to include all 4 template arguments. But when I used instead of the above (wor

Re: [C++-sig] gccxml

2008-12-02 Thread Stefan Seefeld
Alan Baljeu wrote: This is getting out of hand :-( I think I'd rather just do my own thing, except that C++ is so warty it's difficult to come up with anything reasonable that will serve the purpose. How many functions and objects do you want to export, anyway ? I have so far always

Re: [C++-sig] boost.python: implicit type conversion

2008-12-02 Thread Stefan Seefeld
Mihail Konstantinov wrote: Roman Yakovenko wrote: It is not a good idea. Python string is immutable. May be you should consider custom converter. http://www.boost.org/doc/libs/1_37_0/libs/python/doc/v2/faq.html#custom_string I don't see why it is not a good idea. I am nowhere ac

Re: [C++-sig] PyObject RefCount

2008-12-03 Thread Stefan Seefeld
Renato Araujo wrote: Hi all, I'm trying check if have someone using my object in python, but I got some problems I think I'm not doing this in the correct way: First of all, I'm not sure I understand what you are trying to achieve. Why do you want to manually delete reference-counted object

Re: [C++-sig] PyObject RefCount

2008-12-03 Thread Stefan Seefeld
Renato Araujo wrote: Thanks for your points, I will try explain my problem better: In my library I have a parent->child control then when the parent is deleted all children is deleted too. but in python I would like change this behavior, if there is some python object using my child I will not

Re: [C++-sig] Getting address of wrapped instance?

2008-12-08 Thread Stefan Seefeld
[EMAIL PROTECTED] wrote: Is there are way to get the address of the C++ instance pointed to by a given Boost.Python wrapper object? I don't need a real pointer, the address alone suffices. You may try using type const &ref = extract(object); HTH, Stefan -- ...ich hab' noch ei

Re: [C++-sig] Getting address of wrapped instance?

2008-12-08 Thread Stefan Seefeld
Hans Meine wrote: How about adding an id() method (returning this) to the C++ class and exporting that? Well, this 'id' isn't really a property of the wrapped type / object, but the wrapper. So, I think there is little sense in adding such a tautological 'id' function to the class itself.

Re: [C++-sig] preventing boost::python::throw_error_already_set

2008-12-11 Thread Stefan Seefeld
Leonard Ritter wrote: hi everyone, i'm having a problem where a boost::python::throw_error_already_set is being thrown and causes a segfault (linux). unfortunately the error happens from within python, when reaching the end of an iteration through a vector array, which was exported using the

Re: [C++-sig] preventing boost::python::throw_error_already_set

2008-12-15 Thread Stefan Seefeld
troy d. straszheim wrote: In short (i'm guessing this is more or less what you'll need): gdb --args /usr/bin/python /path/to/my/python/script.py run # it runs, throws an exception, but the stacktrace isn't helpful catch throw # this only works after the first run run # jackpot, yo

Re: [C++-sig] preventing boost::python::throw_error_already_set

2008-12-15 Thread Stefan Seefeld
Leonard Ritter wrote: searching for __cxa_allocate_exception segfault i got quite a few hits in different projects, of which this wiki entry devotes a whole page to the issue: http://wiki.fifengine.de/Segfault_in_cxa_allocate_exception The funny thing is: I never got the problem on a machin

Re: [C++-sig] Dynamic resolution of members and methods

2008-12-17 Thread Stefan Seefeld
Jérémie Delaitre wrote: Ok, I have find a way to resolve all of my problem. I simply declare a new custom type which is callable. This way, when the user type in python 'myObj.myFunc(...)', mytype_getattro is called with 'myObj' as self and 'myFunc' as arg. Then, I return a new instance of the

Re: [C++-sig] How to get items from a tuple

2009-01-16 Thread Stefan Seefeld
Ricardo Abreu wrote: Thank you, but I had tried that and it doesn't seem to work... look: http://codepad.org/kA61P8r0 What am I doing wrong? In the sake of understanding the code a little better you may write it a bit less compact. Then you will realize that the item extraction you were ask

Re: [C++-sig] How to get items from a tuple

2009-01-16 Thread Stefan Seefeld
Ricardo Abreu wrote: Well, thank you. The problem was really that I didn't notice I had to extract the int explicitly. About the code being too compact, I'm not sure I got what you mean, unless you would want me to have a variable in between the tuple and the print just to hold the result of

Re: [C++-sig] Exposing C++ class to Python

2009-03-04 Thread Stefan Seefeld
Vinaya Shrestha wrote: Hello, I need to be able to expose a C++ class to Python, say pass a C++ object reference to Python and make modifications on the object using Python scripting. I tried to use boost.python library for the same but without any success. Can anyone help me ? Please

Re: [C++-sig] boost::python without exceptions?

2009-03-10 Thread Stefan Seefeld
Murray Cumming wrote: Is there any version of the boost::python API that doesn't use exceptions? I have an environment that disables exceptions in the C++ compiler, but I'd like to use boost::python there. You may compile boost with exceptions disabled, and see how far you get. Regards,

Re: [C++-sig] [boost] [Python] GSoC and Python 3.0 Support

2009-03-13 Thread Stefan Seefeld
of my head, the following folks come to mind: - Dave Abrahams - Stefan Seefeld - Ralf Grosse-Kunstleve - Roman Yakovenko You might try contacting them off list or on c++-sig (cc'ed on this email). I'm willing to participate, in particular, if other folks such as David are

Re: [C++-sig] [boost] [Python] GSoC and Python 3.0 Support

2009-03-14 Thread Stefan Seefeld
David Abrahams wrote: On Mar 14, 2009, at 4:28 AM, Niall Douglas wrote: Would it make sense if Dave acted as second as in "person we fall back upon if the primaries can't figure it out?" That would make plenty of sense to me. I'd be very happy to have others leading the mentoring effort.

Re: [C++-sig] Some thoughts on py3k support

2009-03-18 Thread Stefan Seefeld
Ralf W. Grosse-Kunstleve wrote: C++ has wchar_t and std::wstring. Could these be leveraged to avoid ambiguities? E.g. char, std::string are mapped to py3 byte objects, wchar_t and std::wstring to py3 str objects. I don't quite agree with that suggestion. First, wchar_t doesn't imply Unicode

Re: [C++-sig] Some thoughts on py3k support

2009-03-18 Thread Stefan Seefeld
Haoyu Bai wrote: Yes of course we should allow users to set policy. So the problem is what the default behavior should be when there is no policy set by user explicitly. The candidates are: - raise an error - convert char* and std::string to/from Python bytes - convert char* and std::string to/

Re: [C++-sig] Some thoughts on py3k support

2009-03-19 Thread Stefan Seefeld
Haoyu Bai wrote: This naming style is a bit more clear but broken user's build scripts - not a big problem though. But when all the Python community evolved to py3k, and 2.x come into history, should we change the name back from libboost_python_py3.so to libboost_python.so? Can we postpone

Re: [C++-sig] embedded python ?

2009-04-03 Thread Stefan Seefeld
mad city wrote: Just starting out with boost-python. I have a python script that I want to call from C++ code. I have the quickstart example working. I'm running into a problem. The python script I'm calling includes import statements - for example 'import os', and these are causing an exceptio

Re: [C++-sig] embedded python ?

2009-04-03 Thread Stefan Seefeld
mad city wrote: Thanks. Good advice. From the quickstart project, the embedded.cpp file function void exec_file_test(std::string const &script) { std::cout << "running file " << script << "..." << std::endl; // Run a python script in an empty environment. python::dict global;

Re: [C++-sig] Recursion problem while testing inheritance

2009-04-09 Thread Stefan Seefeld
Hi Luciano, Luciano M. Wolf wrote: Hi, I'm doing some experiments calling methods from parent (or grandparent) class. I have a "Base" class defining a "test" virtual method. Class "Derived" inherits from "Base" but does not implement "test". At Python side (test.py) I redefine test and do a cal

Re: [C++-sig] Expanding embedded code

2009-04-21 Thread Stefan Seefeld
Robin Gilks wrote: A difficult question to put a title to so I'll paint a brief scenario... The application is written in c++ It receives a data message and instantiates a message decoder class. Based on the contends that are extracted into the class variables, a response is built by instantia

Re: [C++-sig] Expanding embedded code

2009-04-23 Thread Stefan Seefeld
Robin Gilks wrote: I'm still having a problem with the python side of things - the c++ side mostly makes sense. For example, the "class instances" section of the page at http://wiki.cacr.caltech.edu/danse/index.php/Lots_more_details_on_writing_wrappers I can follow with no problems but

Re: [C++-sig] wrapping objects which inherit from std::map

2009-05-06 Thread Stefan Seefeld
Jeremy Kie wrote: Hi, I have the following: class foo : public std::map { } You lack a semicolon here. (I also don't think it's a good idea to derive from standard containers, but that is an entirely different subject). BOOST_PYTHON_MODULE(foo_ext) { using namespace boost::python; cl

Re: [C++-sig] wrapping objects which inherit from std::map

2009-05-06 Thread Stefan Seefeld
Jeremy Kie wrote: With the addition of the "std::map" declaration, my compiler errors disappeared. That is very curious, as Python only discovers whether the base class has been exported or not at runtime. Thus it can't possibly result in a compiler error. Regards, Stefan --

Re: [C++-sig] wrapping operator=

2009-05-25 Thread Stefan Seefeld
Hans Roessler wrote: But still I am looking for a way to allow the simple "data=42." syntax with the same result, because it would best copy the C++ syntax. Would it, really ? I think it would be extremely confusing, if it would work. But it doesn't. "a = b" doesn't assign to an object, but

Re: [C++-sig] boost::python for Python 3.0

2009-06-02 Thread Stefan Seefeld
Alcides Viamontes Esquivel wrote: Dear all: I would like to know if there is any progress on the development of a version of boost::python for Python 3.0, the last activity that I can track on this is back to the first days of April; that includes mailing lists and the boost repository. Pytho

Re: [C++-sig] Py3k unicode to const char* conversion solved (Re: boost::python for Python 3.0)

2009-06-06 Thread Stefan Seefeld
Haoyu Bai wrote: Hi, After attempted all the hacks come from my mind, I solved the unicode string to const char* conversion problem by simply calling a Python C-API: _PyUnicode_AsString. Since it is start with an underscore, it is not a public API and not documented. But I wonder why it is not d

Re: [C++-sig] g++ compiler limitations other than -ftemplate-depth-n and -DBOOST_PYTHON_MAX_ARITY ?

2009-06-06 Thread Stefan Seefeld
What you describe sounds like GCC is getting confused. It may have run into wrong code, but the error message may be caused by a wrong interpretation of what you wanted to do. The fact that things work if you reduce the number of arguments, and the fact that you had to increase BOOST_PYTHON_MAX_

Re: [C++-sig] g++ compiler limitations other than -ftemplate-depth-n and -DBOOST_PYTHON_MAX_ARITY ?

2009-06-08 Thread Stefan Seefeld
Christopher A Mejia wrote: Stefan, Thanks for your response. The API that I am trying to wrap is the Data Client Server portion of the U.S. Naval Research Labs' SIMDIS Analysis & Display Tool (simdis.nrl.navy.mil). This is free software, but does require registration and there is a human in

Re: [C++-sig] Fw: g++ compiler limitations other than -ftemplate-depth-n and -DBOOST_PYTHON_MAX_ARITY ?

2009-06-15 Thread Stefan Seefeld
On 06/11/2009 08:13 PM, Christopher A Mejia wrote: Stefan / cplusplus-sig, Based on Stefan's encouragement, I developed a minimal complete test case Thanks ! Can you please submit that as an issue on https://svn.boost.org/trac/boost/ ? We may then follow-up there... Stefan --

Re: [C++-sig] bump.... boost::python and __declspec(align(16))

2009-06-23 Thread Stefan Seefeld
On 06/23/2009 02:05 PM, Simon Pickles wrote: Hello all, Sorry to bump this, but i am still unable to resolve my problem described below. The problem doesn't appear to be related to boost.python, or even boost. You may have better luck asking on a more suitable forum. Stefan --

Re: [C++-sig] Function handling with Boost

2009-06-23 Thread Stefan Seefeld
On 06/23/2009 02:32 PM, Christopher Schramm wrote: Mmmkay, looks like I found a dirty little workaround: I read your original mail, but I didn't understand what you are trying to achieve. You certainly can export functions to python: void foo(...); ... bpl::def("foo", foo); works jus

Re: [C++-sig] boost::python on Linux

2009-06-23 Thread Stefan Seefeld
On 06/23/2009 02:45 PM, Jim Treadway wrote: I'm having trouble getting a simple boost::python sample program to work properly on Linux. It compiles and seems to link properly, but the Python interpreter is unable to call my C++ function. On Mac OS X the program works as expected. Any help woul

Re: [C++-sig] Passing a c++ new'ed object back to python

2009-06-23 Thread Stefan Seefeld
On 06/23/2009 02:59 PM, Simon Pickles wrote: When I use code which parallels this structure, I see the Model destructor is called when the c++ object goes out of scope (fine) despite the object being passed to python as the argument of a function (not fine!) That is because by default argum

Re: [C++-sig] Function handling with Boost

2009-06-23 Thread Stefan Seefeld
On 06/23/2009 04:03 PM, Christopher Schramm wrote: Stefan Seefeld wrote: I read your original mail, but I didn't understand what you are trying to achieve. You certainly can export functions to python: void foo(...); ... bpl::def("foo", foo); works just fine. There s

Re: [C++-sig] Function handling with Boost

2009-06-23 Thread Stefan Seefeld
On 06/23/2009 04:43 PM, Christopher Schramm wrote: Stefan Seefeld wrote: You need a module into which to inject the symbols you export. That is true no matter the (meta)type of what you export, i.e. classes, functions, etc. Once you have that module set up (via BOOST_PYTHON_MODULE), you can

Re: [C++-sig] Uh-oh now I am trying boost python embedding

2009-06-25 Thread Stefan Seefeld
On 06/25/2009 04:52 PM, Simon Pickles wrote: However, what if I want to pass a c++ type to a python class? Is there some way to covnert my class, Logger in this case, to an bpy object, or some other way? Yes, and this conversion happens implicitly, by virtue of the converter that has been c

Re: [C++-sig] boost::python::str and Python's str and unicode types

2009-07-23 Thread Stefan Seefeld
On 07/23/2009 10:17 AM, Robert Smallshire wrote: Hello, I'm looking for some confirmation that my understanding of what boost.python is doing is correct. > From what I understand boost::python::str represents the str (PyStringObject) type in Python. Unless I'm missing something, here doesn't s

Re: [C++-sig] [Boost.Python] Request to merge some patches from trunk into 1.40 branch (was: Re: PySide has been released)

2009-08-21 Thread Stefan Seefeld
Anderson, let me forward that mail to the main boost list, and ping Beman (release manager) and David (boost.python maintainer). Beman, David, if it's not too late, I may help merge trunk to the release branch. Let me know... Stefan On 08/21/2009 08:08 AM, Anderson Lizardo wrote:

Re: [C++-sig] [Boost.Python] Request to merge some patches from trunk into 1.40 branch (was: Re: PySide has been released)

2009-08-21 Thread Stefan Seefeld
On 08/21/2009 05:49 PM, Ralf W. Grosse-Kunstleve wrote: Hi Stefan, I merged everything Mon Aug 17. Oh, great ! Since you are around, could you please review https://svn.boost.org/trac/boost/ticket/3356 ? I was working on a numpy.ndarray extension, and got hit by this bug when Python would

Re: [C++-sig] python extended object to native c++ pointer

2009-08-31 Thread Stefan Seefeld
On 08/31/2009 07:51 AM, Mark Chandler wrote: Im toying around with the idea to use python as an embedded scripting language for a project im working on and have got most things working. However i cant seem to be able to convert a python extended object back into a native c++ pointer. [...]

Re: [C++-sig] python extended object to native c++ pointer

2009-08-31 Thread Stefan Seefeld
On 08/31/2009 08:57 AM, Mark Chandler wrote: Stefan i spent so long on this thank you! I got another quick question, how do i define the class in the global namespace but still refer to it in functions? I want to do something like this but keep getting compile errors. The script itself l

Re: [C++-sig] Trouble optimizing Boost.python integration

2009-09-08 Thread Stefan Seefeld
On 09/08/2009 10:51 AM, Gustavo Carneiro wrote: 2009/8/25 Dan Sanduleac > Hi, I'm trying to compare different python-C wrapping techniques to see which would be faster and also more suited to game development. If your project does not use multiple i

Re: [C++-sig] Quick question about wrapping methods that have multiple versions

2009-09-08 Thread Stefan Seefeld
On 09/08/2009 11:30 PM, Jean-Sébastien Guay wrote: If I just add .def("getA", &B::getA, some_return_policy) to my class_ wrapper, on compile it will complain that it doesn't know which version of B::getA() I want. Up until now the way I wrapped this was to make a trivial wrapper function: A

[C++-sig] Python 3 support has landed on boost trunk

2009-09-19 Thread Stefan Seefeld
Hi there, as some of you may know, Haoyu Bai has worked over the summer on Python 3 support for Boost.Python. This work happened on a branch, which I merged back into trunk last night. Now we need to set up testers to run the testsuite with some Python 3 variant, as that is a new platform to

Re: [C++-sig] Conversion from Python to C++

2009-10-02 Thread Stefan Seefeld
On 10/02/2009 10:06 AM, Michele De Stefano wrote: For example, assume we have two C++ classes, A and B. A is exported to Python with class_<>, while B is not exported to Python. Assume also that, in C++, A is convertible to B (i.e. I can construct a B object from an existing A object). Assume I

Re: [C++-sig] "pass all args in list" syntax

2009-10-09 Thread Stefan Seefeld
On 10/09/2009 02:25 AM, Gennadiy Rozental wrote: Hi, In native Python I can do something like this: def goo(a,b,c): return a+b+c ll = [1,2,3] goo( *ll ) And it will pass all the arguments properly. I need similar functionality in C++: Given bp::object func; bp::lis

Re: [C++-sig] "pass all args in list" syntax

2009-10-09 Thread Stefan Seefeld
On 10/09/2009 04:19 PM, Gennadiy Rozental wrote: Stefan Seefeld sympatico.ca> writes: I added support for the above quite a while ago (and I'm assured that this time it even made it into the release branch in time ). Thus, you can construct a list and keyword, then pass to

Re: [C++-sig] Numpy ndarray as argument or return value using boost python

2009-10-12 Thread Stefan Seefeld
On 10/12/2009 11:36 AM, Pim Schellart wrote: Hi Everyone, I also posted this to the boost users list. I tried to find a good example for this but after spending two days on google and one day getting pyublas to compile I decided to call for help. I want to give a numpy ndarray as an argument to

Re: [C++-sig] using windows api functions

2009-11-07 Thread Stefan Seefeld
On 11/07/2009 08:43 AM, blackmet blackmet wrote: c:/boost_1_40_0/boost/python/make_function.hpp:103: error: invalid conversion from `int (*)(HINSTANCE__*, HINSTANCE__*, CHAR*, int)' to `int (*)(HINSTANCE__*, HINSTANCE__*, CHAR*, int)' c:/boost_1_40_0/boost/python/make_function.hpp:103: error:

Re: [C++-sig] using windows api functions

2009-11-07 Thread Stefan Seefeld
On 11/07/2009 09:58 AM, blackmet blackmet wrote: 2009/11/7 Stefan Seefeld <mailto:seef...@sympatico.ca>> On 11/07/2009 08:43 AM, blackmet blackmet wrote: c:/boost_1_40_0/boost/python/make_function.hpp:103: error: invalid conversion from `int (*)(HI

Re: [C++-sig] Efficient string passing

2009-11-19 Thread Stefan Seefeld
On 11/19/2009 07:30 AM, Mohan Ganesalingam wrote: Dear all, I recently sent an e-mail which (I think) didn't reach the list, about trying to return large strings from C++ into Python without copying them. I believe this is impossible: Python treats strings as immutable, which means you can't

Re: [C++-sig] Efficient string passing

2009-11-19 Thread Stefan Seefeld
On 11/19/2009 08:30 AM, Mohan Ganesalingam wrote: I believe this is impossible: Python treats strings as immutable, which means you can't manipulate them in-place, and there is no C API function There is apparently one exception to this, which I was utilising: char* PyString_AsString(PyObject

Re: [C++-sig] dynamic compile and "to-Python converter ... second conversion method ignored"

2009-11-20 Thread Stefan Seefeld
On 11/20/2009 05:50 AM, Eilif Mueller wrote: Hi, I'm using boost.python to interface with some dynamically generated C++ code, employing some scipy.weave facilities to cache the results. When I force a recompile and import, I get the following message: RuntimeWarning: to-Python converter for

Re: [C++-sig] dynamic compile and "to-Python converter ... second conversion method ignored"

2009-11-20 Thread Stefan Seefeld
On 11/20/2009 11:47 AM, troy d. straszheim wrote: Stefan Seefeld wrote: (It's a global symbol that is seen by all DSOs. Having two DSOs provide that symbol, but with different content, is illegal.) I'd like to fix this, now, it is starting to cause me pain. For instance, it also

Re: [C++-sig] dynamic compile and "to-Python converter ... second conversion method ignored"

2009-11-20 Thread Stefan Seefeld
On 11/20/2009 03:23 PM, troy d. straszheim wrote: For example, what does 'replaceable' mean ? Does it mean two bindings are identical or equivalent ? No it means only that the behavior in the situation above is modified. Does it merely mean the user allows the mapping to change? (This woul

Re: [C++-sig] boost.python: call python function with kwargs from c++

2009-12-03 Thread Stefan Seefeld
On 12/03/2009 07:11 AM, meiko rachimow wrote: Hi How can I call a function defined in a python module from c++, if I have to give **kwargs parameter... example.py: def hello(**kwargs): for key, value in kwargs.items(): print key, " - ", value c++: using namespace boost::python;

Re: [C++-sig] Boost Python Tuple - Find length of tuple?

2010-01-04 Thread Stefan Seefeld
On 01/04/2010 08:53 AM, Simon Pickles wrote: Hello, I have a simple question. How do I find out in c++ how many elements are contained within a boost::python::tuple? I tried this: using namespace boost::python; tuple a = make_tuple("hello", 42); object b = a.attr("length

Re: [C++-sig] Exposing C++ data with Boost.Python

2010-01-09 Thread Stefan Seefeld
On 01/09/2010 01:52 PM, devin kelly wrote: Hello, I'm trying to expose some data that I develop in C++ to python. Basically, the reverse of this sample code: #include #include #include #include int main(){ Py_Initialize(); object main_module = import("__main__");

Re: [C++-sig] Exposing C++ data with Boost.Python

2010-01-10 Thread Stefan Seefeld
On 01/10/2010 12:36 PM, devin kelly wrote: So I have to make something to do this conversion. This is where I'm stuck now, I think I have to do something like this BOOST_PYTHON_MODULE(vector_indexing_suite_ext){ boost::python::class_ >("PyVec") .def(boost::python::vector_index

Re: [C++-sig] OpenMP and boost-python?

2010-02-01 Thread Stefan Seefeld
On 02/01/2010 12:07 PM, Anders Wallin wrote: Hello group, I have C++ code which uses OpenMP to parallellize some algorithms. When wrapped with boost-python only one thread seems to run at a time, and there is no speedup (as seen with pure C++) when using multiple core machines. The FAQ says this

Re: [C++-sig] OpenMP and boost-python?

2010-02-01 Thread Stefan Seefeld
On 02/01/2010 12:58 PM, Anders Wallin wrote: How difficult is it to make boost-python play nice with OpenMP? Anyone done it? Is this ever going to be a feature of boost-python, or always going to require special patching and hacking? I'm not sure in how much boost.python would actually n

Re: [C++-sig] Getting the wrapped C++ instance from a boost::python::object

2010-02-06 Thread Stefan Seefeld
On 02/06/2010 08:39 AM, Murray Cumming wrote: If I have a boost::python::object that I know contains a PyObject that wraps an instance of my C++ class, MyClass, can I get a pointer to that MyClass instance, so I can call its C++ methods? http://www.boost.org/doc/libs/1_41_0/libs/python/doc/

Re: [C++-sig] Executing python code from C++

2010-02-07 Thread Stefan Seefeld
On 02/07/2010 05:22 AM, Murray Cumming wrote: In Glom, to execute arbitrary Python code, I use PyRun_String() to parse the Python code, PyDict_GetItemString() and PyObject_Call() to get a callable object for that code, and then PyObject_CallObject() to actually execute the code and get a return v

Re: [C++-sig] Executing python code from C++

2010-02-07 Thread Stefan Seefeld
On 02/07/2010 08:29 AM, Murray Cumming wrote: So, I guess I can use boost::python::exec() to call code that defines a Python function. bpl::exec() executes a chunk of Python code, no matter what it contains. But how can I get a boost::python::object for the (callable object of) the functi

Re: [C++-sig] Executing python code from C++

2010-02-07 Thread Stefan Seefeld
On 02/07/2010 04:51 PM, Murray Cumming wrote: On Sun, 2010-02-07 at 09:51 -0500, Stefan Seefeld wrote: Sorry, I don't understand the question. Can you give an example of what you want to do ? May be you want to "exec" some python code that defines a function, which you then

Re: [C++-sig] Checking for or null PyObject* or PyNone

2010-02-07 Thread Stefan Seefeld
On 02/07/2010 09:32 PM, Jim Bosch wrote: On Sun, 2010-02-07 at 11:47 +0100, Murray Cumming wrote: And what's the correct way to check for PyNone other than if (obj == boost::python::object()) ? I think that's the standard way. I suppose if (obj.ptr() == Py_None) might be faster on

Re: [C++-sig] Checking for or null PyObject* or PyNone

2010-02-08 Thread Stefan Seefeld
On 02/08/2010 02:02 AM, Ralf W. Grosse-Kunstleve wrote: if (obj) ... is definitely the right way to do it. Sorry to correct, but it isn't equivalent to "obj is None". if (obj) uses PyObject_IsTrue(); see boost/python/object_operators.hpp line 60. Oh, thanks for the correct

Re: [C++-sig] Getting object for PyObject (reference counting)

2010-02-11 Thread Stefan Seefeld
On 02/11/2010 07:18 AM, Murray Cumming wrote: On Fri, 2009-02-27 at 15:18 -0800, Alex Mohr wrote: [snip] If you have a PyObject *p and you want a bp::object, construct it via: object(handle<>(p)) // when p's a new reference I find that I have to split the handle and objec

Re: [C++-sig] [Boost.Python] Wrapping C library functions

2010-02-14 Thread Stefan Seefeld
On 02/14/2010 07:32 PM, TP wrote: Suppose I am attempting to use a C (not C++) library that has an .h file with things like this: extern PIX * pixCreate ( l_int32 width, l_int32 height, l_int32 depth ); extern void pixDestroy ( PIX **ppix ); extern PIX * pixClone ( PIX *pixs ); extern PIX

  1   2   3   >