From Eliot:
authorAnders Broman <anders.broman@ericsson.com>
Mon, 24 Oct 2011 16:37:07 +0000 (16:37 -0000)
committerAnders Broman <anders.broman@ericsson.com>
Mon, 24 Oct 2011 16:37:07 +0000 (16:37 -0000)
Change to python support functions.

Avoid passing C dissector callback via python to create_dissector_handle.
This caused problems at least on 64 bit linux.

Get all dissector args in one call.  Simplifies common usage.
https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=6448

svn path=/trunk/; revision=39535

epan/wspython/wspy_dissector.py
epan/wspython/wspy_register.c

index 6dfb11a8870dbb2ea89967012778eedfb2c32bd3..7769603423c27bb8d88ac5c04ded788cc3c4ab31 100755 (executable)
@@ -263,11 +263,13 @@ class Dissector(object):
     '''private method executed right before dissect in order to retrieve some
     internal information and enabling the possibility to add the base tree of
     this protocol dissection to the tree without any user intervention'''
-    self.__tvb = self.__wsl.py_tvbuff()
-    self.__pinfo = self.__wsl.py_pinfo()
-    self.__tree = self.__wsl.py_tree()
 
-    #self.__wsl.print_current_proto(py_object(pinfo))
+    self.__tvb = ct.c_void_p()
+    self.__pinfo = ct.c_void_p()
+    self.__tree = ct.c_void_p()
+    self.__wsl.py_dissector_args(ct.byref(self.__tvb), ct.byref(self.__pinfo), ct.byref(self.__tree))
+    # print self.__tvb, self.__pinfo, self.__tree
+    #self.__wsl.print_current_proto(ct.py_object(pinfo))
     subt = self.subtrees
     try:
       if not subt.has_user_defined_protocol_tree():
@@ -283,13 +285,6 @@ class Dissector(object):
     implementing the dissector of a specific protocol.'''
     return [ (None, 0, None) ]
 
-  def create_dissector_handle(self, protocol=None):
-    '''create_dissector_handle : see proto.h'''
-    gdissector = self.__wsl.py_generic_dissector()
-    if not protocol:
-      protocol = self.__protocol
-    return self.__wsl.create_dissector_handle(gdissector, protocol)
-
   def find_dissector(self, protocol):
     '''find_dissector : see proto.h'''
     return self.__wsl.find_dissector(protocol)
@@ -307,8 +302,7 @@ class Dissector(object):
           continue
         if not handle:
           if not private_handle:
-            handle = \
-              self.create_dissector_handle(self.__protocol)
+            handle = self.__wsl.py_create_dissector_handle(self.__protocol)
           else:
             handle = private_handle
         self.__wsl.dissector_add_uint(type, protocol_id, handle)
index 97bde1b2f305704c0a88ef5464d51c16a1fbaac6..60e6e22d17004bb985067c682e69d9694ec101e5 100644 (file)
@@ -173,19 +173,11 @@ void register_all_py_protocols_func(void)
   }
 }
 
-tvbuff_t *py_tvbuff(void)
+void py_dissector_args(tvbuff_t ** tvb, packet_info ** pinfo, proto_tree ** tree)
 {
-  return g_tvb;
-}
-
-packet_info * py_pinfo(void)
-{
-  return g_pinfo;
-}
-
-proto_tree * py_tree(void)
-{
-  return g_tree;
+       *tvb = g_tvb;
+       *pinfo = g_pinfo;
+       *tree = g_tree;
 }
 
 /*
@@ -214,17 +206,9 @@ void py_dissect(tvbuff_t * tvb, packet_info * pinfo,
   PyObject_CallMethod(py_dissector, "pre_dissect", NULL);
 }
 
-/*
- * Return the pointer to the generic python dissector
- *
- * One could think that it could be a PyCObject but it is a
- * workaround because ctypes is used and it complains later -not
- * knowing how to conver the parameter - in the Python code when
- * calling back a C function with a PyCObject as parameter
- */
-dissector_t py_generic_dissector(void)
+dissector_handle_t py_create_dissector_handle(const int proto)
 {
-  return &py_dissect;
+               return create_dissector_handle(&py_dissect, proto);
 }
 
 static void register_all_py_handoffs_foreach(gpointer key _U_, gpointer value, gpointer user_data _U_)