[pytango] 34/483: c

Sandor Bodo-Merle sbodomerle-guest at moszumanska.debian.org
Thu Sep 28 19:14:22 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 f7161b4e573b8bb56a5f13b7b89b16ef9f1d680e
Author: tiagocoutinho <tiagocoutinho at 4e9c00fd-8f2e-0410-aa12-93ce3db5e235>
Date:   Tue May 24 15:20:07 2011 +0000

    c
    
    git-svn-id: http://svn.code.sf.net/p/tango-cs/code/bindings/PyTango/trunk@16954 4e9c00fd-8f2e-0410-aa12-93ce3db5e235
---
 Makefile                 |  8 +++---
 PyTango/device_proxy.py  | 64 +++++++++++++++++++++++++++++++++---------------
 PyTango/utils.py         | 13 ++++++++--
 doc/revision.rst         |  7 ++++++
 src/constants.cpp        | 14 +++++++++++
 src/server/attribute.cpp | 15 +++++++-----
 src/server/command.cpp   |  8 +++---
 7 files changed, 94 insertions(+), 35 deletions(-)

diff --git a/Makefile b/Makefile
index 8f95c17..ac36f17 100644
--- a/Makefile
+++ b/Makefile
@@ -189,10 +189,10 @@ $(OBJS_DIR)/%.o: $(SRC_DIR)/server/%.cpp
 
 $(LIB_NAME): $(OBJS)
 	$(LN) $(OBJS) $(LN_DIRS) $(LN_LIBS) -o $(OBJS_DIR)/$(LIB_NAME) $(LN_VER)
-	objcopy --only-keep-debug $(OBJS_DIR)/$(LIB_NAME) $(OBJS_DIR)/$(LIB_SYMB_NAME)
-	objcopy --strip-debug --strip-unneeded $(OBJS_DIR)/$(LIB_NAME)
-	objcopy --add-gnu-debuglink=$(OBJS_DIR)/$(LIB_SYMB_NAME) $(OBJS_DIR)/$(LIB_NAME)
-	chmod -x $(OBJS_DIR)/$(LIB_SYMB_NAME)
+#	objcopy --only-keep-debug $(OBJS_DIR)/$(LIB_NAME) $(OBJS_DIR)/$(LIB_SYMB_NAME)
+#	objcopy --strip-debug --strip-unneeded $(OBJS_DIR)/$(LIB_NAME)
+#	objcopy --add-gnu-debuglink=$(OBJS_DIR)/$(LIB_SYMB_NAME) $(OBJS_DIR)/$(LIB_NAME)
+#	chmod -x $(OBJS_DIR)/$(LIB_SYMB_NAME)
 
 clean:
 	rm -f *.o core
diff --git a/PyTango/device_proxy.py b/PyTango/device_proxy.py
index 1b14e70..b124bfa 100644
--- a/PyTango/device_proxy.py
+++ b/PyTango/device_proxy.py
@@ -31,6 +31,7 @@ __docformat__ = "restructuredtext"
 
 import operator
 import types
+import threading
 
 from _PyTango import StdStringVector
 from _PyTango import DbData, DbDatum
@@ -618,6 +619,15 @@ def __DeviceProxy__set_attribute_config(self, value):
 
     return self._set_attribute_config(v)
 
+def __DeviceProxy__get_event_map_lock(self):
+    """
+    Internal helper method"""
+    if not hasattr(self, '_subscribed_events_lock'):
+        # do it like this instead of self._subscribed_events = dict() to avoid
+        # calling __setattr__ which requests list of tango attributes from device
+        self.__dict__['_subscribed_events_lock'] = threading.Lock()
+    return self._subscribed_events_lock
+
 def __DeviceProxy__get_event_map(self):
     """
     Internal helper method"""
@@ -706,15 +716,20 @@ def __DeviceProxy__subscribe_event ( self, attr_name, event_type, cb_or_queuesiz
 
     event_id = self.__subscribe_event(attr_name, event_type, cb, filters, stateless, extract_as)
 
-    se = self.__get_event_map()
-    evt_data = se.get(event_id)
-    if evt_data is not None:
-        desc = "Internal PyTango error:\n" \
-               "%s.subscribe_event(%s, %s) already has key %d assigned to (%s, %s)\n" \
-               "Please report error to PyTango" % \
-               (self, attr_name, event_type, event_id, evt_data[2], evt_data[1])
-        Except.throw_exception("Py_InternalError", desc, "DeviceProxy.subscribe_event")
-    se[event_id] = (cb, event_type, attr_name)
+    l = self.__get_event_map_lock()
+    l.acquire()
+    try:
+        se = self.__get_event_map()
+        evt_data = se.get(event_id)
+        if evt_data is not None:
+            desc = "Internal PyTango error:\n" \
+                   "%s.subscribe_event(%s, %s) already has key %d assigned to (%s, %s)\n" \
+                   "Please report error to PyTango" % \
+                   (self, attr_name, event_type, event_id, evt_data[2], evt_data[1])
+            Except.throw_exception("Py_InternalError", desc, "DeviceProxy.subscribe_event")
+        se[event_id] = (cb, event_type, attr_name)
+    finally:
+        l.release()
     return event_id
 
 def __DeviceProxy__unsubscribe_event(self, event_id):
@@ -733,20 +748,28 @@ def __DeviceProxy__unsubscribe_event(self, event_id):
 
         Throws     : EventSystemFailed
     """
-    se = self.__get_event_map()
-    if event_id not in se:
-        raise IndexError("This device proxy does not own this subscription " + str(event_id))
+    l = self.__get_event_map_lock()
+    l.acquire()
+    try:
+        se = self.__get_event_map()
+        if event_id not in se:
+            raise IndexError("This device proxy does not own this subscription " + str(event_id))
+        del se[event_id]
+    finally:
+        l.release()
     self.__unsubscribe_event(event_id)
-    del se[event_id]
 
 def __DeviceProxy__unsubscribe_event_all(self):
-    se = self.__get_event_map()
-    for event_id in se:
-        try:
-            self.__unsubscribe_event(event_id)
-        except Exception:
-            pass # @todo print or something, but not rethrow
-    se.clear()
+    l = self.__get_event_map_lock()
+    l.acquire()
+    try:
+        se = self.__get_event_map()
+        event_ids = se.keys()
+        se.clear()
+    finally:
+        l.release()
+    for event_id in event_ids:
+        self.__unsubscribe_event(event_id)
 
 def __DeviceProxy__get_events(self, event_id, callback=None, extract_as=ExtractAs.Numpy):
     """
@@ -849,6 +872,7 @@ def __init_DeviceProxy():
     DeviceProxy.set_attribute_config = __DeviceProxy__set_attribute_config
 
     DeviceProxy.__get_event_map = __DeviceProxy__get_event_map
+    DeviceProxy.__get_event_map_lock = __DeviceProxy__get_event_map_lock
     DeviceProxy.subscribe_event = __DeviceProxy__subscribe_event
     DeviceProxy.unsubscribe_event = __DeviceProxy__unsubscribe_event
     DeviceProxy.__unsubscribe_event_all = __DeviceProxy__unsubscribe_event_all
diff --git a/PyTango/utils.py b/PyTango/utils.py
index 15c96ac..e00565e 100644
--- a/PyTango/utils.py
+++ b/PyTango/utils.py
@@ -30,7 +30,8 @@ from __future__ import with_statement
 __all__ = [ "is_scalar_type", "is_array_type", "is_numerical_type", 
             "is_int_type", "is_float_type", "obj_2_str", "seqStr_2_obj",
             "document_method", "document_static_method", "document_enum",
-            "CaselessList", "CaselessDict", "EventCallBack", "get_home" ]
+            "CaselessList", "CaselessDict", "EventCallBack", "get_home",
+            "from_version_str_to_hex_str", "from_version_str_to_int", ]
 
 __docformat__ = "restructuredtext"
 
@@ -926,4 +927,12 @@ def _get_env_var(env_var_name):
         
         key, val = map(str.strip, tup)
         if key == env_var_name:
-            return val
\ No newline at end of file
+            return val
+
+def from_version_str_to_hex_str(version_str):
+    v = map(int, version_str.split('.'));
+    return "0x%02d%02d%02d00" % (v[0],v[1],v[2])
+
+def from_version_str_to_int(version_str):
+    return int(from_version_str_to_hex_str(version_str, 16))
+
diff --git a/doc/revision.rst b/doc/revision.rst
index 1bfe305..22cbe4a 100644
--- a/doc/revision.rst
+++ b/doc/revision.rst
@@ -61,6 +61,8 @@ History of modifications:
 +----------+----------------------------------------------------------------------------------+-----------------------------------------------------+-----------------------+
 | 15/04/11 | `8.11 <http://www.tango-controls.org/static/PyTango/v720/doc/html/index.html>`_  | Update to PyTango 7.2.0                             | T\. Coutinho          |
 +----------+----------------------------------------------------------------------------------+-----------------------------------------------------+-----------------------+
+| --/--/11 | `8.12 <http://www.tango-controls.org/static/PyTango/v721/doc/html/index.html>`_  | Update to PyTango 7.2.1                             | T\. Coutinho          |
++----------+----------------------------------------------------------------------------------+-----------------------------------------------------+-----------------------+
 
 .. _version-history:
 
@@ -70,7 +72,12 @@ Version history
 +------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
 | version    | Changes                                                                                                                                                                      |
 +============+==============================================================================================================================================================================+
+| 7.2.1      | Features:                                                                                                                                                                    |
+|            |     - from sourceforge:                                                                                                                                                      |
+|            |         - `3305251: DS dynamic attributes discards some Attr properties <https://sourceforge.net/tracker/?func=detail&aid=3305251&group_id=57612&atid=484772>`_                        |
++------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
 | 7.2.0      | Features:                                                                                                                                                                    |
+
 |            |     - from sourceforge:                                                                                                                                                      |
 |            |         - `3286678: Add missing EncodedAttribute JPEG methods <https://sourceforge.net/tracker/?func=detail&aid=3286678&group_id=57612&atid=484772>`_                        |
 +------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
diff --git a/src/constants.cpp b/src/constants.cpp
index 63ee39a..6edcd65 100644
--- a/src/constants.cpp
+++ b/src/constants.cpp
@@ -26,6 +26,8 @@
 
 using namespace boost::python;
 
+long TANGO_VERSION_HEX;
+
 void export_constants()
 {
     object consts_module(handle<>(borrowed(PyImport_AddModule("PyTango.constants"))));
@@ -40,6 +42,18 @@ void export_constants()
 #else
     consts_scope.attr("NUMPY_SUPPORT") = true;
 #endif
+
+    str py_TgLibVers = TgLibVers;
+    boost::python::list pylist_TgLibVers = py_TgLibVers.split(".");
+    long_ major = long_(pylist_TgLibVers[0]);
+    long_ minor = long_(pylist_TgLibVers[1]);
+    long_ patch = long_(pylist_TgLibVers[2]);
+    object h = "0x%02d%02d%02d00" % make_tuple(major, minor, patch);
+    PyObject *ptr = PyInt_FromString(PyString_AsString(h.ptr()), NULL, 0);
+    TANGO_VERSION_HEX = PyInt_AsLong(ptr);
+    Py_DECREF(ptr);
+    consts_scope.attr("TANGO_VERSION_HEX") = TANGO_VERSION_HEX;
+
     //
     // From tango_const.h
     //
diff --git a/src/server/attribute.cpp b/src/server/attribute.cpp
index e0b13c4..232e47e 100644
--- a/src/server/attribute.cpp
+++ b/src/server/attribute.cpp
@@ -72,6 +72,8 @@ inline static void throw_wrong_python_data_type_in_array(const std::string &att_
             o.str(), method);
 }
 
+extern long TANGO_VERSION_HEX;
+
 namespace PyAttribute
 {
     /**
@@ -116,16 +118,17 @@ namespace PyAttribute
     {
         Tango::DevString *v = new Tango::DevString;
 
-        if (att.get_writable() == Tango::READ)
-        { // No memory leak here. Do the standard thing
-            from_py<Tango::DEV_STRING>::convert(value, *v);
-        }
-        else
+        if (TANGO_VERSION_HEX < 0x07020000 && att.get_writable() != Tango::READ)
         { // MEMORY LEAK: use the python string directly instead of creating a
           // string
             v[0] = PyString_AsString(value.ptr());
+            att.set_value(v, 1, 0);
+        }
+        else
+        { // No memory leak here. Do the standard thing
+            from_py<Tango::DEV_STRING>::convert(value, *v);
+            att.set_value(v, 1, 0, true);
         }
-        att.set_value(v, 1, 0, true);
     }
     */
     
diff --git a/src/server/command.cpp b/src/server/command.cpp
index 3d85ac1..a7935ad 100644
--- a/src/server/command.cpp
+++ b/src/server/command.cpp
@@ -167,6 +167,7 @@ template<>
 void extract_scalar<Tango::DEV_VOID>(const CORBA::Any &any, boost::python::object &o)
 {}
 
+#ifndef DISABLE_PYTANGO_NUMPY
 /// This callback is run to delete Tango::DevVarXArray* objects.
 /// It is called by python. The array was associated with an attribute
 /// value object that is not being used anymore.
@@ -182,6 +183,7 @@ static void dev_var_x_array_deleter__(void * ptr_, void *type_)
         delete static_cast<TANGO_const2type(tangoTypeConst)*>(ptr_);
     );
 }
+#endif
 
 template<long tangoArrayTypeConst>
 void extract_array(const CORBA::Any &any, boost::python::object &py_result)
@@ -193,7 +195,7 @@ void extract_array(const CORBA::Any &any, boost::python::object &py_result)
     if ((any >>= tmp_ptr) == false)
         throw_bad_type(Tango::CmdArgTypeName[tangoArrayTypeConst]);
 
-#   ifndef DISABLE_PYTANGO_NUMPY
+#ifndef DISABLE_PYTANGO_NUMPY
       // For numpy we need a 'guard' object that handles the memory used
       // by the numpy object (releases it).
       // But I cannot manage memory inside our 'any' object, because it is
@@ -217,9 +219,9 @@ void extract_array(const CORBA::Any &any, boost::python::object &py_result)
       }
 
       py_result = to_py_numpy<tangoArrayTypeConst>(copy_ptr, object(handle<>(guard)));
-#   else
+#else
       py_result = to_py_list(tmp_ptr);
-#   endif
+#endif
 }
 
 CORBA::Any *PyCmd::execute(Tango::DeviceImpl *dev, const CORBA::Any &param_any)

-- 
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