❌ About FreshRSS

Normal view

There are new articles available, click to refresh the page.
Before yesterdayNews from the Ada programming language world

Review my code: Thick bindings to libusb

26 October 2023 at 19:27

Folks,

I started learning Ada about 2 weeks ago and these thick bindings to libusb is my first Ada project.

I can now neatly iterate over connected USB devices. I only added enough functionality to list USB devices but will add more in the near future.

Please spare a few minutes to review my code and let me know what I’m doing wrong, what I should do differently, what can be improved, etc.

For example, I’m not sure if I should collect all type definitions at the beginning of the package or intersperse them between function declarations.

2 posts - 2 participants

Read full topic

Type and variable naming

26 October 2023 at 16:39

Is there a convention for naming types and variables?

For example, I have a type named Context which means that I can’t name a variable below Context. I could rename type to Context_Type but then would need to add _Type to the rest of the types in this library lest I be inconsistent.

Alternatively, I can name the variable Ctx and leave the type as Context (also Dev : Device, Devices : Device_List, etc.) which is the approach I’m taking now.

What is the canonical Ada way? I much prefer to use full variable names (in Ada) as opposed to abbreviations. I’m trying to follow the AdaCore naming approach as much is possible but it fails in the case above.

  function Init (Context : out Context) return C.int with
   Import => True, Convention => C, External_Name => "libusb_init";

And a follow-up example below…

I can’t have a Device_Descriptor since that’s a record type in my library. I decided to use the _Kind suffix but I’m not happy about it.

type Descriptor_Kind is
   (Device_Descriptor_Kind,
    Config_Descriptor_Kind,
    String_Descriptor_Kind,

21 posts - 10 participants

Read full topic

Implementing Release for GNATCOLL.Refcount

19 October 2023 at 15:28

GNATCOLL.Refcount provides a procedure to run some code when the reference-counted element is released.

How do I implement this procedure?

I’m clearly missing something because Release is not visible as GNATCOLL.Refcount.Release and this doesn’t work

type Context_Contents is new GNATCOLL.Refcount.Refcounted with record
    Address : System.Address;
end record;

procedure Release is new GNATCOLL.Refcount.Release
   (Self => Context_Contents);

and gives me

usb.ads:29:47: error: "Release" not declared in "Refcount"

4 posts - 3 participants

Read full topic

What exceptions are thrown?

19 October 2023 at 05:46

How do I find out what exceptions a procedure or function throws?

Is there a language construct like β€œthrows” in C++ or is it up to the developer to document this in comments?

I’m wrapping a C library that returns a handle in an argument unless the error code returned is non-zero. I would rather not have users of my library check for null handles so I thought I would convert errors to Ada exceptions. Is this the way to go?

18 posts - 7 participants

Read full topic

VSCode formatting

17 October 2023 at 13:56

Good day folks!

Is this canonical Ada formatting or is there a way to improve it in Visual Studio Code?

  type Size is
    (Device, Config, Intface, Endpoint, Audio_Endpoint, HUB_NonVAR,
     SS_Endpoint_Companion, BOS, Capability);
  for Size use
    (Device         => 18, Config => 9, Intface => 9, Endpoint => 7,
     Audio_Endpoint => 9, HUB_NonVAR => 7, SS_Endpoint_Companion => 6,
     BOS            => 5, Capability => 3);
  for Size'Size use Interfaces.C.unsigned_char'Size;
Thanks, Joel

13 posts - 5 participants

Read full topic

❌
❌