comp.lang.ada
 help / color / mirror / Atom feed
From: Marc C <mc.provisional@gmail.com>
Subject: Re: help bridging C and Ada
Date: Mon, 26 Mar 2012 05:49:32 -0700 (PDT)
Date: 2012-03-26T05:49:32-07:00	[thread overview]
Message-ID: <1909024.5.1332766172831.JavaMail.geo-discussion-forums@vbbp15> (raw)
In-Reply-To: <jkpeto$nk4$1@dont-email.me>

On Monday, March 26, 2012 5:03:37 AM UTC-5, Brian Drummond wrote:

> This partly amounts to writing your own binding, as Simon suggested.
> The other part is to create a package with Ada procedures and functions 
> to interface to gstreamer, and use ONLY those functions everywhere else 
> in your code. Then only that package needs to interface to the C code.

My approach to writing bindings has gotten quite minimalist and application-specific in recent years.  Unless the project itself is developing the binding to a library, I create only the minimal subset of functions and data structures that the app actually needs to use.

I pay close attention to how the structs are being used by the C functions and which ones I actually need to read from and write to.  Between this and exploiting C's penchant for pointers, I can dramatically reduce the amount of binding code I need to write and verify.

If some struct, say, is passed as a function argument and its purpose is to hold some data being returned from the function, *but I don't care about any of that specific data*, then I just use a type that's derived from GNAT's Interfaces.C.Extensions package, like Opaque_Structure_Def_Ptr.  (This Extensions package is GNAT-supplied, but the types are nothing more than Addresses and access Addresses, so one can easily roll their own.)  Likewise, if a struct that I am binding to has some pointer fields that, again, I don't care about, I just use an Opaque_Structure_Def_Ptr-derived type.

Granted, if I or someone else needs a more thorough binding in the future, this binding would have to be extended.  But by not writing code that I don't know if I'll ever need, I save the time spent writing and debugging that, and spend it on making needed code now.

Marc A. Criley





  parent reply	other threads:[~2012-03-26 12:49 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-03-25 13:37 help bridging C and Ada Patrick
2012-03-25 14:52 ` Patrick
2012-03-25 17:00   ` Simon Wright
2012-03-25 17:47     ` Patrick
2012-03-26 13:45   ` Stephen Leake
2012-03-26 10:03 ` Brian Drummond
2012-03-26 12:05   ` J-P. Rosen
2012-03-26 22:03     ` Brian Drummond
2012-03-27  2:44       ` Patrick
2012-03-26 12:49   ` Marc C [this message]
2012-03-27 18:09 ` Shark8
2012-03-28  0:19   ` Patrick
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox