Re: [C++-sig] Project architecture and Py++

2010-07-16 Thread Benoit Leveau

Pentix wrote:

Hi,

I’d like to use Python in the following way:

1) create a library (pyd) with some interfaces of the main program taken
outside; generate then its code with py++
2) create a set of scripts, that use this library
3) execute these scripts with boost::python from the main program

Unwillingness to carry out any manual corrections of the generated code is
an important part of the solution. The code is being generated
authomatically, and only the script and the imported header are to be
corrected in case of any problem. It is motivated by the fact, that
the program is developing dynamically and it is better to see and solve
immedeately the emerging discrepancies.

Thus, the main task of implementation phase been solved already, but there
arose the following problem: there appeared a desire to transfer
into python our objects (from those being exposed). But all wrappers are
being generated into the library from the point 1, and are in the
cpp files. 


I’m ready to make the dependance of the main module on the library. But how
to get the wrappers, if it is undesirable to correct the generated code
manually?


Hi,

Manually fixing the generated code is indeed a bad idea.

You should take a look at the code injection feature of py++.

What you can do is having your "binding generator" detecting some
custom files and then injecting the code in the wrappers.
- you define a "custom code" folder,
- whenever your generator detects a "MyClass_injection.cpp" file,
then it will inject the code of this file into the wrapper of 'MyClass',

cls.add_wrapper_code( custom_code )


This is the basic approach, you may need to inject declaration code, 
registration code, some code at the
module level and not the class level, handle templates, etc. but once you get 
the basic system in place,
you can add more features as the need arise.

This way, you don't have to change your original headers nor the generated code 
directly.

Hope that helps,
Benoit
___
Cplusplus-sig mailing list
[email protected]
http://mail.python.org/mailman/listinfo/cplusplus-sig

Re: [C++-sig] Project architecture and Py++

2010-07-16 Thread Benoit Leveau

Benoit Leveau wrote:

Pentix wrote:

Hi,

I’d like to use Python in the following way:

1) create a library (pyd) with some interfaces of the main program taken
outside; generate then its code with py++
2) create a set of scripts, that use this library
3) execute these scripts with boost::python from the main program

Unwillingness to carry out any manual corrections of the generated 
code is

an important part of the solution. The code is being generated
authomatically, and only the script and the imported header are to be
corrected in case of any problem. It is motivated by the fact, that
the program is developing dynamically and it is better to see and solve
immedeately the emerging discrepancies.

Thus, the main task of implementation phase been solved already, but 
there

arose the following problem: there appeared a desire to transfer
into python our objects (from those being exposed). But all wrappers are
being generated into the library from the point 1, and are in the
cpp files.
I’m ready to make the dependance of the main module on the library. 
But how

to get the wrappers, if it is undesirable to correct the generated code
manually?


Hi,

Manually fixing the generated code is indeed a bad idea.

You should take a look at the code injection feature of py++.

What you can do is having your "binding generator" detecting some
custom files and then injecting the code in the wrappers.
- you define a "custom code" folder,
- whenever your generator detects a "MyClass_injection.cpp" file,
then it will inject the code of this file into the wrapper of 'MyClass',

cls.add_wrapper_code( custom_code )


This is the basic approach, you may need to inject declaration code, 
registration code, some code at the
module level and not the class level, handle templates, etc. but once 
you get the basic system in place,

you can add more features as the need arise.

This way, you don't have to change your original headers nor the 
generated code directly.


Hope that helps,
Benoit


I've just realized this is C++-sig mailing list, you may want to post to
[email protected]
if the conversation is more about py++.

Benoit
___
Cplusplus-sig mailing list
[email protected]
http://mail.python.org/mailman/listinfo/cplusplus-sig

[C++-sig] [patch] Make boost python accessible by multiple threads

2010-07-16 Thread Charles Solar
I mentioned it before but I have this patch for boost python that adds
code to lock and unlock the gil at all the boundaries I have found
between python and boost python.  This makes it so multiple threads
can call into python without the user having to lock and unlock the
gil themselves.  I am pretty sure this is a very much desired feature
but I guess the developers are waiting for a head start, so here is
the patch file that can be applied to the boost trunk or any of the
1.4x versions of boost python.  I would very much like to see the
patch correctly worked into boost python so I no longer have to
maintain it myself.
I have been using this in my application for a few months now and I am
fairly confident in its completeness when NOT embedding python
interpreters.  There may be more entry points I have missed because I
do not embed python in my app, therefore I would say this patch is
only non-embedded systems.

Charles


boost_python.patch
Description: Binary data
___
Cplusplus-sig mailing list
[email protected]
http://mail.python.org/mailman/listinfo/cplusplus-sig

Re: [C++-sig] [patch] Make boost python accessible by multiple threads

2010-07-16 Thread Jim Bosch

On 07/16/2010 11:38 AM, Charles Solar wrote:

I mentioned it before but I have this patch for boost python that adds
code to lock and unlock the gil at all the boundaries I have found
between python and boost python.  This makes it so multiple threads
can call into python without the user having to lock and unlock the
gil themselves.  I am pretty sure this is a very much desired feature
but I guess the developers are waiting for a head start, so here is
the patch file that can be applied to the boost trunk or any of the
1.4x versions of boost python.  I would very much like to see the
patch correctly worked into boost python so I no longer have to
maintain it myself.
I have been using this in my application for a few months now and I am
fairly confident in its completeness when NOT embedding python
interpreters.  There may be more entry points I have missed because I
do not embed python in my app, therefore I would say this patch is
only non-embedded systems.



I think there have already been (at least two?) other submitted patches 
to add multithreading support to Boost.Python.  I believe one of them 
has been languishing in the Boost ticket system for quite a long time, 
and I've gathered that some people have put together their own forks of 
Boost.Python that have threading support.


But I don't know much more than this, and I'm also curious to hear the 
story told by someone who has more information...why hasn't 
multithreading support been added?  Does it just add too much overhead 
for those who don't need it?


(bump)

Jim Bosch
___
Cplusplus-sig mailing list
[email protected]
http://mail.python.org/mailman/listinfo/cplusplus-sig