FU Logo
  • Startseite
  • Kontakt
  • Impressum
  • Home
  • Listenauswahl
  • Anleitungen

[linux-minidisc] [PATCH 06/14] Fix segfaults at interpreter exit.

<-- thread -->
<-- date -->
  • From: Vincent Pelletier <plr.vincent@gmail.com>
  • To: <linux-minidisc@lists.fu-berlin.de>
  • Date: Thu, 11 Feb 2010 21:47:33 -0000
  • Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:in-reply-to:references:from:date:subject:to:mime-version :content-type:x-length:x-uid; b=F9HzhiZs6pAtY7lAF15bKi7TjKjM1uP3545MiFDqVvg+zfvDleHMNC0/H/Nj3Gvdx1 hT0G5e0/n3JLycpar+3PX4i+KC4fr1pUUs8p8vUET8YrFMdJGAk2Ljmani1ebS1uHr2u DExVhmgPhqZssrTKrxpzke1F5VJXYrKjnaz3Y=
  • Subject: [linux-minidisc] [PATCH 06/14] Fix segfaults at interpreter exit.

---
 netmd/usb1.py |   14 +++++++++-----
 1 files changed, 9 insertions(+), 5 deletions(-)

diff --git a/netmd/usb1.py b/netmd/usb1.py
index c5d9f77..925adfc 100644
--- a/netmd/usb1.py
+++ b/netmd/usb1.py
@@ -11,7 +11,10 @@ STRING_LENGTH = 256
 class USBDeviceHandle(object):
     handle = None
 
-    def __init__(self, handle):
+    def __init__(self, context, handle):
+        # XXX Context parameter is just here as a hint for garbage collector:
+        # It must collect USBDeviceHandle instance before their LibUSBContext.
+        self.context = context
         self.handle = handle
 
     def __del__(self):
@@ -232,7 +235,8 @@ class USBDevice(object):
 
     configuration_descriptor_list = None
 
-    def __init__(self, device_p):
+    def __init__(self, context, device_p):
+        self.context = context
         libusb1.libusb_ref_device(device_p)
         self.device_p = device_p
         # Fetch device descriptor
@@ -373,7 +377,7 @@ class USBDevice(object):
         result = libusb1.libusb_open(self.device_p, byref(handle))
         if result:
             raise libusb1.USBError, result
-        return USBDeviceHandle(handle)
+        return USBDeviceHandle(self.context, handle)
 
 class LibUSBContext(object):
 
@@ -399,7 +403,7 @@ class LibUSBContext(object):
         device_p_p = libusb1.libusb_device_p_p()
         device_list_len = libusb1.libusb_get_device_list(self.context_p,
                                                          byref(device_p_p))
-        result = [USBDevice(x) for x in device_p_p[:device_list_len]]
+        result = [USBDevice(self, x) for x in device_p_p[:device_list_len]]
         # XXX: causes problems, why ?
         #libusb1.libusb_free_device_list(device_p_p, 1)
         return result
@@ -408,7 +412,7 @@ class LibUSBContext(object):
         handle_p = libusb1.libusb_open_device_with_vid_pid(self.context_p,
             vendor_id, product_id)
         if handle_p:
-            result = USBDeviceHandle(handle_p)
+            result = USBDeviceHandle(self, handle_p)
         else:
             result = None
         return result
<-- thread -->
<-- date -->
  • References:
    • [linux-minidisc] [PATCH 01/14] Make some function accepting opaque data pointer accept a py_object.
      • From: Vincent Pelletier <plr.vincent@gmail.com>
  • linux-minidisc - February 2010 - Archives indexes sorted by:
    [ thread ] [ subject ] [ author ] [ date ]
  • Complete archive of the linux-minidisc mailing list
  • More info on this list...

Hilfe

  • FAQ
  • Dienstbeschreibung
  • ZEDAT Beratung
  • postmaster@lists.fu-berlin.de

Service-Navigation

  • Startseite
  • Listenauswahl

Einrichtung Mailingliste

  • ZEDAT-Portal
  • Mailinglisten Portal