* help bridging C and Ada @ 2012-03-25 13:37 Patrick 2012-03-25 14:52 ` Patrick ` (2 more replies) 0 siblings, 3 replies; 12+ messages in thread From: Patrick @ 2012-03-25 13:37 UTC (permalink / raw) Please forgive any ignorance in this post. I am not a professional programmer. In fact this is why I am attracted to Ada. I believe the strict compiler will substitute for years of experience with buggy languages. This seem to be an overlooked feature of the language. While I am planning on using it for embedded use later, at the moment it is all desktop and as you know, it's a world dominated by C and it's cousins. I am having some luck with gnat's -fdump-ada-spec feature and I can use it to integrate simple C functions I have written. However when I try to bind large libraries like gstreamer I end up with a sort of dependency hell. -fdump-ada-spec-slim just generates the one spec file but when I try to build with the generated spect, I get errors about other spec files missing. Without the slim option I get about 100 specs. I tried to "with" them all but I ended up with more errors about circular dependencies. I've also tried pragma import. I can get an executable compiled but when I call it I get errors like: stack overflow (or erroneous memory access) that was with with Gstreamer and I had others errors when I tried the same process with gtk. All I really need is a way to create a small bridge between a C application and an Ada one. Is there a way to do this without creating such a deep interface with fdump? Should I try the pragma route some more or is this feature problematic? I am not attracted to pipes but is this a more sensible option? If anyone would like me to post code please let me know. Thanks for reading-Patrick ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: help bridging C and Ada 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-26 13:45 ` Stephen Leake 2012-03-26 10:03 ` Brian Drummond 2012-03-27 18:09 ` Shark8 2 siblings, 2 replies; 12+ messages in thread From: Patrick @ 2012-03-25 14:52 UTC (permalink / raw) sorry. I just want to rephase something..... I guess fdump is really a front end to using pragma options. I guess I should have said something like, is it better to use fdump for complicated bindings or to try to use pragma import to hook into a few functions. Thanks ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: help bridging C and Ada 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 1 sibling, 1 reply; 12+ messages in thread From: Simon Wright @ 2012-03-25 17:00 UTC (permalink / raw) Patrick <patrick@spellingbeewinnars.org> writes: > sorry. I just want to rephase something..... I guess fdump is really a > front end to using pragma options. I guess I should have said > something like, is it better to use fdump for complicated bindings or > to try to use pragma import to hook into a few functions. The gstreamer headers total 28446 lines, and the Python bindings total 14736 lines. This includes blank lines and comments, but is still a massive target you've set yourself. For this one, you might be better off deciding on which (small subset of!) the facilities you want to interface with, at least to start with, and writing the bindings by hand. ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: help bridging C and Ada 2012-03-25 17:00 ` Simon Wright @ 2012-03-25 17:47 ` Patrick 0 siblings, 0 replies; 12+ messages in thread From: Patrick @ 2012-03-25 17:47 UTC (permalink / raw) Hi Simon Yep it's massive and even a fractional binding is probably out of my league. All I really want to be able to do is to call a few functions in my small C gstreamer program like play and pause. I was able to build an executable but then ended up with memory errors. Thanks for responding to my post ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: help bridging C and Ada 2012-03-25 14:52 ` Patrick 2012-03-25 17:00 ` Simon Wright @ 2012-03-26 13:45 ` Stephen Leake 1 sibling, 0 replies; 12+ messages in thread From: Stephen Leake @ 2012-03-26 13:45 UTC (permalink / raw) Patrick <patrick@spellingbeewinnars.org> writes: > sorry. I just want to rephase something..... I guess fdump is really a > front end to using pragma options. I guess I should have said > something like, is it better to use fdump for complicated bindings or > to try to use pragma import to hook into a few functions. Another option is two write an intermediate layer in C, that calls all the Gstreamer stuff, but has a clean interface that is easy to import into Ada. -- -- Stephe ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: help bridging C and Ada 2012-03-25 13:37 help bridging C and Ada Patrick 2012-03-25 14:52 ` Patrick @ 2012-03-26 10:03 ` Brian Drummond 2012-03-26 12:05 ` J-P. Rosen 2012-03-26 12:49 ` Marc C 2012-03-27 18:09 ` Shark8 2 siblings, 2 replies; 12+ messages in thread From: Brian Drummond @ 2012-03-26 10:03 UTC (permalink / raw) On Sun, 25 Mar 2012 06:37:02 -0700, Patrick wrote: > I am having some luck with gnat's -fdump-ada-spec feature and I can use > it to integrate simple C functions I have written. > > However when I try to bind large libraries like gstreamer I end up with > a sort of dependency hell. -fdump-ada-spec-slim just generates the one > spec file but when I try to build with the generated spec, I get errors > about other spec files missing. First : how many errors? Probably (hopefully) only a few, or from only a few further dependencies. > Without the slim option I get about 100 > specs. I tried to "with" them all but I ended up with more errors about > circular dependencies. Only "with" what you need. One of the REALLY STRONG points about Ada is that YOU get to control what is visible and accessible in your program. As opposed to the complete mess that a couple of #includes can get you in C/C++. The huge binding you get with -fdump-ada-spec is just that mess made explicit... I would use -fdump-ada-spec in one folder, just for reference. Then use -slim in my project, and bring across the LEAST you can get away with from the -fdump-ada-spec folder to cover the missing dependencies. (The extra functions can be added to the gstreamer_slim.ads file, or a new gstreamer_extra.ads file, rather than adding complete files from - fdump-ada-spec if you wish. That gives you more control) 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. > that was with with Gstreamer and I had others errors when I tried the > same process with gtk. For GTK, there is already an Ada binding - representing a lot of work in itself - gtkada. The Glade GUI builder tool understands gtkada so it can do a lot of the work for you, though not everybody likes it, some want more control over the interface than Glade gives. One point of warning about -fdump-ada-spec : it may still be a work in progress. It does a great job of interfacing to C, but some of the more advanced features of C++ give it problems - it has a good try at processing templates for example, but you have to finish the job. (I had to write dummy C++ code to instantiate each templated function I needed, so that the C++ compiler would actually generate code for them, to prevent linker errors. It didn't seem to understand they were being called from Ada.) - Brian ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: help bridging C and Ada 2012-03-26 10:03 ` Brian Drummond @ 2012-03-26 12:05 ` J-P. Rosen 2012-03-26 22:03 ` Brian Drummond 2012-03-26 12:49 ` Marc C 1 sibling, 1 reply; 12+ messages in thread From: J-P. Rosen @ 2012-03-26 12:05 UTC (permalink / raw) Le 26/03/2012 12:03, Brian Drummond a écrit : > I would use -fdump-ada-spec in one folder, just for reference. > Then use -slim in my project, and bring across the LEAST you can get away > with from the -fdump-ada-spec folder to cover the missing dependencies. > (The extra functions can be added to the gstreamer_slim.ads file, or a > new gstreamer_extra.ads file, rather than adding complete files from - > fdump-ada-spec if you wish. That gives you more control) > <shameless plug> AdaDep is a small utility that can help you there. It analyzes your units, and tells you, for each unit you with, which elements are really used. AdaDep is free software, and available from Adalog's components and utilities page: http://www.adalog.fr/compo2.htm </shameless plug> -- J-P. Rosen Adalog 2 rue du Docteur Lombard, 92441 Issy-les-Moulineaux CEDEX Tel: +33 1 45 29 21 52, Fax: +33 1 45 29 25 00 http://www.adalog.fr ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: help bridging C and Ada 2012-03-26 12:05 ` J-P. Rosen @ 2012-03-26 22:03 ` Brian Drummond 2012-03-27 2:44 ` Patrick 0 siblings, 1 reply; 12+ messages in thread From: Brian Drummond @ 2012-03-26 22:03 UTC (permalink / raw) On Mon, 26 Mar 2012 14:05:51 +0200, J-P. Rosen wrote: > Le 26/03/2012 12:03, Brian Drummond a écrit : >> I would use -fdump-ada-spec in one folder, just for reference. >> Then use -slim in my project, and bring across the LEAST you can get >> away with ... > <shameless plug> > AdaDep is a small utility that can help you there. It analyzes your > units, and tells you, for each unit you with, which elements are really > used. > > AdaDep is free software, and available from Adalog's components and > utilities page: > http://www.adalog.fr/compo2.htm </shameless plug> Good to know, thanks! - Brian ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: help bridging C and Ada 2012-03-26 22:03 ` Brian Drummond @ 2012-03-27 2:44 ` Patrick 0 siblings, 0 replies; 12+ messages in thread From: Patrick @ 2012-03-27 2:44 UTC (permalink / raw) Hi Brian, Hi J-P, Hi Marc, Hi Stephe Thanks for all your feedback. Yes I really don't want to write a full binding, especially as I am new to ada. It's my understanding that a C function ends up as a macro in ASM during the compilation process and it is even possible for some people to call them in executables without having had the original source code. It's my understanding that foreign function interfaces work much the same way only it is easier as there is source code involved. I wrote a very simple C application the uses gtk and gstreamer. I split it into two even simpler applications. I have edited the results from fdump slim so that I am only trying to call one C function. It won't compile as it wants other spec files for gtk. This is quite advanced for me. Would I be better off sticking to bindings that had no external dependencies? Is there a way to call one specific function without becoming entangled with the rest of the C application? Thanks again Brian. I at least 5 errors the first time I tried to compile the gstreamer binding and after I commented out the problematic "withs" I had more and more, I'm really bombing this. Thanks for sharing your tools, J-P, AdaDep looks interesting. Thanks again to everyone. Sorry if I am clutter the list with my newbie stupidity. ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: help bridging C and Ada 2012-03-26 10:03 ` Brian Drummond 2012-03-26 12:05 ` J-P. Rosen @ 2012-03-26 12:49 ` Marc C 1 sibling, 0 replies; 12+ messages in thread From: Marc C @ 2012-03-26 12:49 UTC (permalink / raw) 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 ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: help bridging C and Ada 2012-03-25 13:37 help bridging C and Ada Patrick 2012-03-25 14:52 ` Patrick 2012-03-26 10:03 ` Brian Drummond @ 2012-03-27 18:09 ` Shark8 2012-03-28 0:19 ` Patrick 2 siblings, 1 reply; 12+ messages in thread From: Shark8 @ 2012-03-27 18:09 UTC (permalink / raw) On Sunday, March 25, 2012 8:37:02 AM UTC-5, Patrick wrote: > Please forgive any ignorance in this post. I am not a professional > programmer. In fact this is why I am attracted to Ada. I believe the > strict compiler will substitute for years of experience with buggy > languages. This seem to be an overlooked feature of the language. > > While I am planning on using it for embedded use later, at the moment > it is all desktop and as you know, it's a world dominated by C and > it's cousins. > > I am having some luck with gnat's -fdump-ada-spec feature and I can > use it to integrate simple C functions I have written. > > However when I try to bind large libraries like gstreamer I end up > with a sort of dependency hell. -fdump-ada-spec-slim just generates > the one spec file but when I try to build with the generated spect, I > get errors about other spec files missing. Without the slim option I > get about 100 specs. I tried to "with" them all but I ended up with > more errors about circular dependencies. > > I've also tried pragma import. I can get an executable compiled but > when I call it I get errors like: stack overflow (or erroneous memory > access) > > that was with with Gstreamer and I had others errors when I tried the > same process with gtk. > > All I really need is a way to create a small bridge between a C > application and an Ada one. Is there a way to do this without creating > such a deep interface with fdump? Should I try the pragma route some > more or is this feature problematic? > > I am not attracted to pipes but is this a more sensible option? > > If anyone would like me to post code please let me know. > > Thanks for reading-Patrick You could try running it (the C code) through the preprocessor first. This will mean that you end up with a single file though, eliminating the multiple header file problem... this would of course have the drawback of not preserving where structures are declared. ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: help bridging C and Ada 2012-03-27 18:09 ` Shark8 @ 2012-03-28 0:19 ` Patrick 0 siblings, 0 replies; 12+ messages in thread From: Patrick @ 2012-03-28 0:19 UTC (permalink / raw) Hi Shark8 I tried my best but -dump-ada-spec doesn't seem to work with the the preprocessed file. I used gcc -E and tried to output as .c and .i Maybe I didn't do it right. Thanks for responding to my post though-Patrick ^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2012-03-28 0:27 UTC | newest] Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 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 2012-03-27 18:09 ` Shark8 2012-03-28 0:19 ` Patrick
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox