[pytango] 348/483: Fix #648

Sandor Bodo-Merle sbodomerle-guest at moszumanska.debian.org
Thu Sep 28 19:14:58 UTC 2017


This is an automated email from the git hooks/post-receive script.

sbodomerle-guest pushed a commit to annotated tag bliss_8.10
in repository pytango.

commit 7493ec31cf09a89052524998b6fd6017aeaef9b1
Author: tiagocoutinho <tiagocoutinho at 4e9c00fd-8f2e-0410-aa12-93ce3db5e235>
Date:   Mon Feb 3 16:33:23 2014 +0000

    Fix #648
    
    git-svn-id: http://svn.code.sf.net/p/tango-cs/code/bindings/PyTango/trunk@24824 4e9c00fd-8f2e-0410-aa12-93ce3db5e235
---
 doc/revision.rst                  |  7 ++++-
 src/boost/cpp/attribute_proxy.cpp | 19 +++++++++---
 src/boost/cpp/base_types.cpp      | 65 ++++++++++++++++++++++++++++++++++++++-
 src/boost/cpp/device_proxy.cpp    | 12 ++++++++
 src/boost/python/group.py         |  4 +--
 5 files changed, 98 insertions(+), 9 deletions(-)

diff --git a/doc/revision.rst b/doc/revision.rst
index 0a2d7ae..8a42cd9 100644
--- a/doc/revision.rst
+++ b/doc/revision.rst
@@ -73,7 +73,9 @@ History of modifications:
 +----------+----------------------------------------------------------------------------------+-----------------------------------------------------+-----------------------+
 | 28/08/13 | `8.13 <http://www.tango-controls.org/static/PyTango/v723/doc/html/index.html>`_  | Update to PyTango 7.2.4                             | T\. Coutinho          |
 +----------+----------------------------------------------------------------------------------+-----------------------------------------------------+-----------------------+
-| 27/11/13 | `8.18 <http://www.tango-controls.org/static/PyTango/v810/doc/html/index.html>`_  | Update to PyTango 8.1.1                             | T\. Coutinho          |
+| 27/11/13 | `8.18 <http://www.tango-controls.org/static/PyTango/v811/doc/html/index.html>`_  | Update to PyTango 8.1.1                             | T\. Coutinho          |
++----------+----------------------------------------------------------------------------------+-----------------------------------------------------+-----------------------+
+| __/02/14 | `8.19 <http://www.tango-controls.org/static/PyTango/v812/doc/html/index.html>`_  | Update to PyTango 8.1.2                             | T\. Coutinho          |
 +----------+----------------------------------------------------------------------------------+-----------------------------------------------------+-----------------------+
 
 .. _version-history:
@@ -84,6 +86,9 @@ Version history
 +----------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------+
 | version  | Changes                                                                                                                                                           |
 +==========+===================================================================================================================================================================+
+| 8.1.2    | Bug fixes:                                                                                                                                                        |
+|          | - `648: PyTango unicode method parameters fail <https://sourceforge.net/p/tango-cs/bugs/648/>`_                                                                   |
++----------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------+
 | 8.1.1    | Features:                                                                                                                                                         |
 |          | - Implemented tango C++ 8.1 API                                                                                                                                   |
 |          |                                                                                                                                                                   |
diff --git a/src/boost/cpp/attribute_proxy.cpp b/src/boost/cpp/attribute_proxy.cpp
index 8beaf9c..3f0f7ed 100644
--- a/src/boost/cpp/attribute_proxy.cpp
+++ b/src/boost/cpp/attribute_proxy.cpp
@@ -32,6 +32,16 @@ namespace PyAttributeProxy
             return bopy::make_tuple(ret);
         }
     };
+
+    static boost::shared_ptr<Tango::AttributeProxy> makeAttributeProxy1(const std::string& name)
+    {
+        return boost::shared_ptr<Tango::AttributeProxy>(new Tango::AttributeProxy(name.c_str()));
+    }
+
+    static boost::shared_ptr<Tango::AttributeProxy> makeAttributeProxy2(const Tango::DeviceProxy *dev, const std::string& name)
+    {
+      return boost::shared_ptr<Tango::AttributeProxy>(new Tango::AttributeProxy(dev, name.c_str()));
+    }
 }
 
 void export_attribute_proxy()
@@ -46,14 +56,13 @@ void export_attribute_proxy()
     void (Tango::AttributeProxy::*delete_property_)(std::string &) =
         &Tango::AttributeProxy::delete_property;
 
-    bopy::class_<Tango::AttributeProxy> AttributeProxy(
-        "__AttributeProxy",
-        bopy::init<const char *>())
+    bopy::class_<Tango::AttributeProxy> AttributeProxy("__AttributeProxy",
+        bopy::init<const Tango::AttributeProxy &>())
     ;
 
     AttributeProxy
-        .def(bopy::init<const Tango::DeviceProxy *, const char *>())
-        .def(bopy::init<const Tango::AttributeProxy &>())
+        .def("__init__", boost::python::make_constructor(PyAttributeProxy::makeAttributeProxy1))
+        .def("__init__", boost::python::make_constructor(PyAttributeProxy::makeAttributeProxy2))
 
         //
         // Pickle
diff --git a/src/boost/cpp/base_types.cpp b/src/boost/cpp/base_types.cpp
index cb7c5e5..e6ca8e3 100644
--- a/src/boost/cpp/base_types.cpp
+++ b/src/boost/cpp/base_types.cpp
@@ -159,6 +159,65 @@ struct convert_PySequence_to_CORBA_Sequence
     
 };
 
+#if PY_VERSION_HEX < 0x03000000
+bool is_str(PyObject* obj)
+{
+    return PyString_Check(obj) || PyUnicode_Check(obj);
+}
+
+struct StdString_from_python_str_unicode
+{
+    StdString_from_python_str_unicode()
+    {
+        boost::python::converter::registry::push_back(
+          &convertible,
+          &construct,
+          boost::python::type_id<std::string>());
+    }
+ 
+    // Determine if obj_ptr can be converted in a std::string
+    static void* convertible(PyObject* obj)
+    {
+        if (!is_str(obj))
+        {
+            return 0;
+        }
+        return obj;
+    }
+ 
+    // Convert obj_ptr into a std::string
+    static void construct(PyObject* obj,
+                          boost::python::converter::rvalue_from_python_stage1_data* data)
+    {
+      bool decref = false;
+
+      if (PyUnicode_Check(obj))
+      {
+          decref = true;
+          obj = PyUnicode_AsLatin1String(obj);
+      }
+      
+      const char* value = PyBytes_AsString(obj);
+ 
+      // Grab pointer to memory into which to construct the new std::string
+      void* storage = (
+        (boost::python::converter::rvalue_from_python_storage<std::string>*)
+        data)->storage.bytes;
+ 
+      // in-place construct the new std::string using the character data
+      // extraced from the python object
+      new (storage) std::string(value);
+ 
+      // Stash the memory chunk pointer for later use by boost.python
+      data->convertible = storage;
+
+      if (decref)
+          Py_DECREF(obj);
+    }
+};
+
+#endif // PY_VERSION_HEX < 0x03000000
+
 int raise_asynch_exception(long thread_id, boost::python::object exp_klass)
 {
     return PyThreadState_SetAsyncExc(thread_id, exp_klass.ptr());
@@ -317,7 +376,11 @@ void export_base_types()
     convert_numpy_to_integer<Tango::DEV_ULONG>();
     convert_numpy_to_integer<Tango::DEV_LONG64>();
     convert_numpy_to_integer<Tango::DEV_ULONG64>();
-    
+
+#if PY_VERSION_HEX < 0x03000000
+    StdString_from_python_str_unicode();
+#endif
+
     // from tango_const.h
     export_poll_device();
 
diff --git a/src/boost/cpp/device_proxy.cpp b/src/boost/cpp/device_proxy.cpp
index f99838c..08c5f03 100644
--- a/src/boost/cpp/device_proxy.cpp
+++ b/src/boost/cpp/device_proxy.cpp
@@ -372,6 +372,16 @@ namespace PyDeviceProxy
         return get_events__aux<Tango::DataReadyEventData, Tango::DataReadyEventDataList>
                                                 (py_self, event_id);
     }
+
+    static boost::shared_ptr<Tango::DeviceProxy> makeDeviceProxy1(const std::string& name)
+    {
+        return boost::shared_ptr<Tango::DeviceProxy>(new Tango::DeviceProxy(name.c_str()));
+    }
+
+    static boost::shared_ptr<Tango::DeviceProxy> makeDeviceProxy2(const std::string& name, bool b)
+    {
+      return boost::shared_ptr<Tango::DeviceProxy>(new Tango::DeviceProxy(name.c_str(), b));
+    }
 };
 
 void export_device_proxy()
@@ -394,6 +404,8 @@ void export_device_proxy()
         .def(bopy::init<const char *>())
         .def(bopy::init<const char *, bool>())
         .def(bopy::init<const Tango::DeviceProxy &>())
+        .def("__init__", boost::python::make_constructor(PyDeviceProxy::makeDeviceProxy1))
+        .def("__init__", boost::python::make_constructor(PyDeviceProxy::makeDeviceProxy2))
 
         //
         // Pickle
diff --git a/src/boost/python/group.py b/src/boost/python/group.py
index cbd75b7..d97e9c4 100644
--- a/src/boost/python/group.py
+++ b/src/boost/python/group.py
@@ -20,7 +20,7 @@ __docformat__ = "restructuredtext"
 import operator
 
 from ._PyTango import __Group as _RealGroup, StdStringVector
-from .utils import seq_2_StdStringVector
+from .utils import seq_2_StdStringVector, is_pure_str
 from .utils import document_method as __document_method
 import collections
 
@@ -54,7 +54,7 @@ class Group:
     same attribute(s)/command(s) to be able to do parallel requests."""
     
     def __init__(self, name):
-        if isinstance(name, str):
+        if is_pure_str(name):
             name = _RealGroup(name)
         if not isinstance(name, _RealGroup):
             raise TypeError("Constructor expected receives a str")

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/pytango.git



More information about the debian-science-commits mailing list