After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 638094 - Libusb : fix segfault + updates
Libusb : fix segfault + updates
Status: RESOLVED OBSOLETE
Product: vala
Classification: Core
Component: Bindings
unspecified
Other All
: Normal normal
: ---
Assigned To: Vala maintainers
Vala maintainers
Depends on:
Blocks:
 
 
Reported: 2010-12-27 10:33 UTC by geert jordaens
Modified: 2018-05-22 13:49 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Patch Fix-segfault + updates. (2.56 KB, patch)
2010-12-27 10:34 UTC, geert jordaens
none Details | Review
libusb-1.0: Use a wrapper for Context.get_device_list (2.69 KB, patch)
2011-01-19 21:57 UTC, Evan Nemerson
needs-work Details | Review

Description geert jordaens 2010-12-27 10:33:51 UTC
1. Make Context nullable for DeviceHandle.from_vid_pid

2. Remove [CCode (array_length = false)] from get_device_list
  This this fixes a segfault for :

/* valac --pkg libusb-1.0 TestLibUsb.vala */
using LibUSB;

namespace TestLibUSb

{



  public static class TestLibUSb

  {

    static int main (string[] args)

    {

      Context       context = null;

      Device[]      devices = null;
      Context.init  (out context);
      context.get_device_list(out devices);

      return 0;

    }

  }
}

3. Replace Glib.TimeVal with Posix.TimeVal for methods 
   wait_for_event, handle_events_timeout and handle_events_locked
   
4. add TransferFlags
Comment 1 geert jordaens 2010-12-27 10:34:59 UTC
Created attachment 177089 [details] [review]
Patch Fix-segfault + updates.
Comment 2 geert jordaens 2010-12-27 13:45:20 UTC
The patch fixes the segfault during the c-code generation but breaks the compilation.

I've tried several attributes in the vapi file:

/* valac --pkg libusb-1.0 TestLibUsb.vala */
using LibUSB;

namespace TestLibUSb

{



  public static class TestLibUSb

  {

    static int main (string[] args)

    {

      Context       context = null;

      Device[]      devices = null;
      Context.init  (out context);
      context.get_device_list(out devices);

      return 0;

    }

  }

}


/*
public ssize_t get_device_list ([CCode (array_length = false, array_null_terminated = true)]  out unowned Device[]? list);
public ssize_t get_device_list ([CCode (array_length = false, array_null_terminated = true)]  out unowned Device[] list);
public ssize_t get_device_list ([CCode (array_length = false)]  out unowned Device[]? list);
public ssize_t get_device_list ([CCode (array_length = false)]  out unowned Device[] list);

valac -v -g  --pkg libusb-1.0 TestLibUsb.vala --save-temps --dump-tree test.tree
**
ERROR:valaccodearraymodule.c:941:vala_ccode_array_module_real_get_array_length_cvalue: assertion failed: (_tmp20_)
Aborted

public ssize_t get_device_list ([CCode (array_length = false)]  out Device[] list);
public ssize_t get_device_list ([CCode (array_length = false, array_null_terminated = true)]  out Device[] list);
public ssize_t get_device_list ([CCode (array_length = false, array_null_terminated = true)]  out Device[]? list);
public ssize_t get_device_list ([CCode (array_length = false)]  out Device[]? list);

valac -v -g  --pkg libusb-1.0 TestLibUsb.vala --save-temps --dump-tree test.tree
Segmentation fault


public ssize_t get_device_list (out Device[] list);
public ssize_t get_device_list (out unowned Device[] list);
public ssize_t get_device_list ([CCode (array_null_terminated = true)]  out unowned Device[] list);

valac -v -g  --pkg libusb-1.0 TestLibUsb.vala --save-temps --dump-tree test.tree
cc -g -o 'TestLibUsb' 'TestLibUsb.c' -pthread -I/usr/include/glib-2.0 -I/usr/lib64/glib-2.0/include -I/usr/include/libusb-1.0  -pthread -lgobject-2.0 -lgthread-2.0 -lrt -lglib-2.0 -lusb-1.0
TestLibUsb.c: In function ‘test_lib_usb_test_lib_usb_main’:
TestLibUsb.c:100:2: error: too many arguments to function ‘libusb_get_device_list’
/usr/include/libusb-1.0/libusb.h:778:9: note: declared here
*/
Comment 3 geert jordaens 2010-12-27 21:43:23 UTC
I was able to compile the code by changing the libusb-1.0.vapi :

/* valac --pkg libusb-1.0 TestLibUsb.vala */
using LibUSB;
namespace TestLibUSb
{
  public static class TestLibUSb
  {
    static int main (string[] args)
    {
      Context?       context = null;
      Device[]?      devices = null;
      Context.init  (out context);
      context.get_device_list(ref devices);
      return 0;
    }
  }
}

diff --git a/vapi/libusb-1.0.vapi b/vapi/libusb-1.0.vapi
index a9c0311..b665d56 100644
--- a/vapi/libusb-1.0.vapi
+++ b/vapi/libusb-1.0.vapi
@@ -251,7 +251,7 @@ namespace LibUSB {
        public class Context {
                public static int init (out Context context);
                public void set_debug (int level);
-               public ssize_t get_device_list (out Device[] list);
+               public ssize_t get_device_list ([CCode (array_length = false, array_null_terminated = true)] ref Device[] list);
                public DeviceHandle open_device_with_vid_pid (uint16 vendor_id, uint16 product_id);
 
                public int try_lock_events ();
Comment 4 Evan Nemerson 2011-01-19 21:55:07 UTC
commit 0f9f2987450ebc95b1c6ed4f9225e1b410eaca3d
Author: Geert Jordaens <geert.jordaens@telenet.be>
Date:   Wed Jan 19 12:19:13 2011 -0800

    libusb-1.0: Add TransferFlags, use Posix.timeval not GLib.TimeVal
Comment 5 Evan Nemerson 2011-01-19 21:57:14 UTC
Created attachment 178788 [details] [review]
libusb-1.0: Use a wrapper for Context.get_device_list

Use a wrapper method to make the binding a bit nicer. The argument needs to be out and not have an array length, which is what is causing valac to crash. This includes a fix for that.
Comment 6 Jürg Billeter 2011-01-21 16:02:46 UTC
Review of attachment 178788 [details] [review]:

::: codegen/valaccodemethodcallmodule.vala
@@ +788,3 @@
 			if (array_type != null) {
 				for (int dim = 1; dim <= array_type.rank; dim++) {
+					ccode.add_assignment (get_array_sizes (unary.inner).get (dim - 1), params[dim - 1].no_array_length ? new CCodeIdentifier ("-1") : get_array_sizes (unary).get (dim - 1));

params[dim - 1] doesn't look right. Also, I think it would be better to add the (dummy) array length to the TargetValue instead, i.e., handle no_array_length case at line 406ff. Also, in the case of null-terminated arrays, this should calculate the array length at runtime instead of just using -1.
Comment 7 Michael 'Mickey' Lauer 2018-02-16 10:51:29 UTC
This VAPI still has some problems. First off, rev 3f33d23c884092ce95ffb0afaa45292acc46f778 introduced

+               [CCode (cname = "_vala_libusb_device_handle_new")]

which leads to a linking error when calling the DeviceHandle constructor here. How is this constructor supposed to work?

More over, foreach ( var device in devices ) does not work until we apply

-               public ssize_t get_device_list ([CCode (array_length = false)] out Device[] list);
+               public ssize_t get_device_list ([CCode (array_length = false, array_null_terminated = true)] out Device[] list);

There's probably more issues, but at least these two should be fixed first.
Comment 8 GNOME Infrastructure Team 2018-05-22 13:49:45 UTC
-- GitLab Migration Automatic Message --

This bug has been migrated to GNOME's GitLab instance and has been closed from further activity.

You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.gnome.org/GNOME/vala/issues/151.