Something in this patch bomb broke the interp/python-self test.

On Feb 17, 2012, at 16:31 , Michael Haberler wrote:

> interp/python: drop reference to shared_ptr, use boost::cref
> 
> Using cref ensures that a call from C++->Python does not instantiate a
> new wrapper object for 'self'.
> 
> Adapt interpreter calls to changed pythonplugin interface.
> 
> 
> http://git.linuxcnc.org/?p=emc2.git;a=commitdiff;h=fdf334d
> 
> ---
> .../remap/iocontrol-removed/python/customtask.py   |    5 ++-
> src/emc/rs274ngc/interp_internal.hh                |    4 +--
> src/emc/rs274ngc/interp_python.cc                  |    2 -
> src/emc/rs274ngc/interpmodule.cc                   |    3 +-
> src/emc/rs274ngc/interpmodule.hh                   |    2 -
> src/emc/rs274ngc/rs274ngc_pre.cc                   |   30 ++++++++++++++-----
> src/emc/task/taskclass.cc                          |    4 +-
> 7 files changed, 30 insertions(+), 20 deletions(-)
> 
> diff --git a/configs/sim/remap/iocontrol-removed/python/customtask.py 
> b/configs/sim/remap/iocontrol-removed/python/customtask.py
> index a540500..7eaf536 100644
> --- a/configs/sim/remap/iocontrol-removed/python/customtask.py
> +++ b/configs/sim/remap/iocontrol-removed/python/customtask.py
> @@ -24,7 +24,10 @@ except ImportError:
>     from nulluserfuncs import UserFuncs
> 
> def debug():
> -    return interpreter.this.debugmask &  0x00040000 # EMC_DEBUG_PYTHON_TASK
> +    # interpreter.this isnt usable until after Interpreter.init has been 
> called
> +    if hasattr(interpreter,'this'):
> +        return interpreter.this.debugmask &  0x00040000 # 
> EMC_DEBUG_PYTHON_TASK
> +    return 
> 
> 
> def handler(signum, frame):
> diff --git a/src/emc/rs274ngc/interp_internal.hh 
> b/src/emc/rs274ngc/interp_internal.hh
> index 8f1fab9..e61dbbf 100644
> --- a/src/emc/rs274ngc/interp_internal.hh
> +++ b/src/emc/rs274ngc/interp_internal.hh
> @@ -722,9 +722,7 @@ typedef struct setup_struct
>     // do not lowercase named params inside comments - for #<_hal[PinName]>
> #define FEATURE_NO_DOWNCASE_OWORD    0x00000010
> 
> -
> -    interp_ptr pythis;  // shared_ptr representation of 'this'
> -
> +    boost::python::object pythis;  // boost::cref to 'this'
>     const char *on_abort_command;
>     int_remap_map  g_remapped,m_remapped;
>     remap_map remaps;
> diff --git a/src/emc/rs274ngc/interp_python.cc 
> b/src/emc/rs274ngc/interp_python.cc
> index a982754..e8618d6 100644
> --- a/src/emc/rs274ngc/interp_python.cc
> +++ b/src/emc/rs274ngc/interp_python.cc
> @@ -35,8 +35,6 @@ namespace bp = boost::python;
> #include "interp_internal.hh"
> #include "rs274ngc_interp.hh"
> #include "units.h"
> -#include "interpmodule.hh"
> -
> 
> extern    PythonPlugin *python_plugin;
> 
> diff --git a/src/emc/rs274ngc/interpmodule.cc 
> b/src/emc/rs274ngc/interpmodule.cc
> index b34c5a6..a1f9e4b 100644
> --- a/src/emc/rs274ngc/interpmodule.cc
> +++ b/src/emc/rs274ngc/interpmodule.cc
> @@ -17,7 +17,6 @@ namespace bp = boost::python;
> #include "interp_internal.hh"
> #include "rs274ngc_interp.hh"
> #include "units.h"
> -#include "interpmodule.hh"
> #include "array1.hh"
> 
> namespace pp = pyplusplus::containers::static_sized;
> @@ -591,7 +590,7 @@ BOOST_PYTHON_MODULE(interpreter) {
>     bp::register_exception_translator<InterpreterException>
>       (&translateInterpreterException);
> 
> -    class_< Interp,  interp_ptr, noncopyable >("Interp",no_init) //OK
> +    class_< Interp, noncopyable >("Interp",no_init) 
> 
>       .def("find_tool_pocket", &wrap_find_tool_pocket)
>       .def("load_tool_table", &Interp::load_tool_table)
> diff --git a/src/emc/rs274ngc/interpmodule.hh 
> b/src/emc/rs274ngc/interpmodule.hh
> deleted file mode 100644
> index c3d43eb..0000000
> --- a/src/emc/rs274ngc/interpmodule.hh
> +++ /dev/null
> @@ -1,2 +0,0 @@
> -typedef boost::shared_ptr< Interp > interp_ptr;
> -
> diff --git a/src/emc/rs274ngc/rs274ngc_pre.cc 
> b/src/emc/rs274ngc/rs274ngc_pre.cc
> index 9209943..d1eeb88 100644
> --- a/src/emc/rs274ngc/rs274ngc_pre.cc
> +++ b/src/emc/rs274ngc/rs274ngc_pre.cc
> @@ -88,16 +88,11 @@ include an option for suppressing superfluous commands.
> #include "interp_internal.hh" // interpreter private definitions
> #include "interp_queue.hh"
> #include "rs274ngc_interp.hh"
> -//#include "rs274ngc_errors.cc"
> -
> -#include "interpmodule.hh"
> 
> #include "units.h"
> 
> -static void interpDeallocFunc(Interp *interp) {} // 
> http://hafizpariabi.blogspot.com/2008/01/using-custom-deallocator-in.html
> extern char * _rs274ngc_errors[];
> 
> -
> const char *Interp::interp_status(int status) {
>     static char statustext[50];
>     static const char *msgs[] = { "INTERP_OK", "INTERP_EXIT",
> @@ -114,7 +109,6 @@ int trace;
> Interp::Interp()
>     : log_file(0)
> {
> -    // _setup.py_module_stat = PYMOD_NONE;
>     init_named_parameters();  // need this before Python init. FIXME logging 
> broken - too early in startup
>     if (trace) fprintf(stderr,"---> new Interp() pid=%d\"",getpid());
> }
> @@ -868,9 +862,29 @@ int Interp::init()
>         // initialize the Python plugin singleton
>         extern struct _inittab builtin_modules[];
>         if (inifile.Find("TOPLEVEL", "PYTHON")) {
> -           if (PythonPlugin::configure(iniFileName,"PYTHON",  
> builtin_modules, this) != NULL) {
> +           if (PythonPlugin::configure(iniFileName,"PYTHON",  
> builtin_modules) != NULL) {
>                 logPy("Python plugin configured");
> -               _setup.pythis =  interp_ptr(this, interpDeallocFunc);
> +               try {
> +                   // this import will register the C++->Python converter 
> for Interp
> +                   bp::object interp_module = bp::import("interpreter");
> +
> +                   // use a boost::cref to avoid per-call instantiation of 
> the 
> +                   // Interp Python wrapper (used for the 'self' parameter 
> in handlers)
> +                   _setup.pythis =  boost::python::object(boost::cref(this));
> +
> +                   // alias to 'interpreter.this' for the sake of ';py, .... 
> '' comments
> +                   bp::scope(interp_module).attr("this") =  _setup.pythis;
> +               }
> +               catch (bp::error_already_set) {
> +                   std::string exception_msg;
> +                   if (PyErr_Occurred()) {
> +                       exception_msg = handle_pyerror();
> +                   } else
> +                       exception_msg = "unknown exception";
> +                   bp::handle_exception();
> +                   PyErr_Clear();
> +                   Error("PYTHON: exception during 'this' 
> export:\n%s\n",exception_msg.c_str());
> +               }
>             } else {
>                 Error("no Python plugin available");
>             }
> diff --git a/src/emc/task/taskclass.cc b/src/emc/task/taskclass.cc
> index 00360d2..863f9c5 100644
> --- a/src/emc/task/taskclass.cc
> +++ b/src/emc/task/taskclass.cc
> @@ -300,15 +300,15 @@ int emcTaskOnce(const char *filename)
>     bp::object retval;
>     bp::tuple arg;
>     bp::dict kwarg;
> -    extern Interp interp;
> 
>     // initialize the Python plugin singleton
>     // Interp is already instantiated but not yet fully configured
>     // both Task and Interp use it - first to call configure() instantiates 
> the Python part
> +    // NB: the interpreter.this global will appear only after Interp.init()
> 
>     extern struct _inittab builtin_modules[];
> 
> -    if (PythonPlugin::configure(filename, "PYTHON",  builtin_modules, 
> &interp)) {
> +    if (PythonPlugin::configure(filename, "PYTHON",  builtin_modules)) {
>       if (emc_debug & EMC_DEBUG_PYTHON_TASK) {
>           rcs_print("emcTaskOnce: Python plugin configured");
>       }
> 
> ------------------------------------------------------------------------------
> Virtualization & Cloud Management Using Capacity Planning
> Cloud computing makes use of virtualization - but cloud computing 
> also focuses on allowing computing to be delivered as a service.
> http://www.accelacomm.com/jaw/sfnl/114/51521223/
> _____________________________________________
> Emc-commit mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/emc-commit

-- 
Sebastian Kuzminsky


------------------------------------------------------------------------------
Virtualization & Cloud Management Using Capacity Planning
Cloud computing makes use of virtualization - but cloud computing 
also focuses on allowing computing to be delivered as a service.
http://www.accelacomm.com/jaw/sfnl/114/51521223/
_______________________________________________
Emc-developers mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/emc-developers

Reply via email to