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

[linux-minidisc] [PATCH 09/17] Fix segfaults at interpreter exit.

<-- thread -->
<-- date -->
  • From: Vincent Pelletier <plr.vincent@gmail.com>
  • To: <linux-minidisc@lists.fu-berlin.de>
  • Date: Wed, 27 Jan 2010 20:34:07 +0100
  • 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-bogosity:x-uid; b=gmP0I8yokOKf/gGOSYQtKyCi9TQvJPCgVp0cxKNT7q+SdkBY0uTx3o0LNQxWXSRrjq 7JwDcv16kqZitCkm7oaI2KOuUhpFXY0+44XuJPAJmKhP++DF2BwOrmGj0xDn2uLY2Mdd WZflwRDx/tlOlWIor764LyUa4IRkQQQVhrXqk=
  • Subject: [linux-minidisc] [PATCH 09/17] 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/17] Make function acting on a transfer accept a pointer to transfer.
      • From: Vincent Pelletier <plr.vincent@gmail.com>
  • linux-minidisc - January 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