Re: [Plplot-devel] Problem with ada interface example code
I have submitted a new Ada example file, xt12a.adb and have made changes to x12a.adb according to the discussion several days ago about problems with emulating sprintf. I also made changes in x12a.adb so that it uses data structures from the thick binding rather than the thin binding. (See related note in another e-mail from me today.) I think that it is generally not a good idea to make the Ada examples emulate C when there is an Ada way to get the job done. Those who are interested will see that rather than use sprintf and make Ada programmers (including this one 8^) scratch their heads, I used the 'Image function. Generally, if there is a type T and X is a value of T, there is a function T'Image(X) which returns a string representation of the name of X unless T is an Integer type in which case the returned string consists of the digits of X along with a leading minus sign if X is negative. Inversely, if S is a string containing a valid integer literal and T is an Integer type, then T'Value(S) is the numeric value of that literal. This is not used in this example, just FYI. String (and 1D array) concatenation is accomplished using the & operator but that is not necessary in this example either. Jerry On May 24, 2007, at 4:48 PM, Alan W. Irwin wrote: > On 2007-05-24 15:25-0600 Orion Poplawski wrote: > >> In plplot-5.7.3/examples/ada/x12a.adb, the sprintf function is >> declared >> and imported as follows: >> >> procedure Sprintf( buffer : out char_array; format : in >> char_array; >> variable: in PLFLT ); >> pragma Import(C, Sprintf, "sprintf" ); >> >> This is incorrect because sprintf's declaration is sprintf (char *, >> const char *, ...) (varargs) not sprintf (char *, const char *, >> float). >> This happens to work on i386 because of the ABI happens to be the >> same. It isn't on x86_64 and so crashes. See >> https://bugzilla.redhat.com/bugzilla/process_bug.cgi#c1 and the >> http://gcc.gnu.org/onlinedocs/gnat_ugn_unw/Calling- >> Conventions.html note >> about varargs for more info. >> >> If you really need to use sprintf you'll need to write a write a >> sprintff(char *, const char *, float) wrapper to sprintf and >> interface >> to that. Likewise for any other arguments used (currently just >> the one). >> >> Not sure if any plplot routines use varargs arguments, but if so the >> current ada imports are probably incorrect. > > Thanks, Orion, for your report. > > To answer Orion's last comment first, I looked in src/*.c for "..." > and there > doesn't seem to be any libplplot routines with a variable number of > arguments so I don't think that is going to be an issue. > > To answer Orion's second-last comment, I think we should look for > an Ada > alternative to Importing the C sprintf function because of the > difficulties > you have found with that method. Virtually every language has a > native way > to transform from integer, floating-point etc. representations, to > strings. > > Jerry, are you aware of the normal way to do this in Ada? N.B. > this has > nothing to do with API questions or our Ada interface and is merely a > question about how to transform from integer and floating point > representations to strings in Ada since that capability is needed for > the Ada implemention of example 12 and several other of our examples. > > Alan - This SF.net email is sponsored by DB2 Express Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now. http://sourceforge.net/powerbar/db2/ ___ Plplot-devel mailing list Plplot-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/plplot-devel
[Plplot-devel] Ada bindings and examples
Some time back, Alan suggested that I make what amounts to a new, third, Ada binding, and I agree that this is a good idea. Of the two Ada bindings which I have called "thick" and "thin," the thin binding adheres to the C API of PLplot, using the same subroutine names, argument lists, and data structures including type names. The thick binding differs in several ways. The subroutine names have been changed to be more pleasing to programmers from the Ada culture, the data structures have been changed to be more Ada-like thus requiring a shorter learning curve, argument lists have been modified by removing array dimensions since Ada has true arrays which include their beginning and ending indices and thus their sizes, many constants (mostly integer) have been given names (e.g. one can use "Red" instead of "1" but "1" still works--see xt12a.adb), and a number of high-level "easy-plotters" have been included which in part exploit Ada's ability to have variable argument lists and which take care of much of the PLplot set-up (look in the early parts of plplot.ads). Because of the new subroutine names in the thick binding, some programmers may find it annoying to deal with two names for each subroutine when using the documentation and this is the crux of Alan's suggestion, which was to make what amounts to a new thick binding but which uses the traditional PLplot subroutine names. I'm willing to make a version of the thick binding that substitutes the traditional PLplot subroutine names for the names that I used in the thick Ada binding for those Ada programmers who find it more convenient to look up things in the PLplot documents that way, but note that: (a) I have carefully kept the traditional subroutine names in a comment immediately before the new names in the thick binding, plplot.ads (specification) files as well as the plplot.adb (body) files specifically for ease of looking up function names. I use them all the time and it's not that big of a deal. (b) I doubt that there will be many Ada programmers using the thin interface. Consequently, I feel that the examples should use only the data structures from the thick interface, because those are the data structures that Ada programmers will be using in their coding. To summarize: The plan is to make a quasi-third Ada binding which is exactly like the current thick binding except that the subroutine names are the traditional PLplot names. There will be two example files for each example, one written to the thick binding and one written to the new binding. The naming conventions are e.g. for Example 1, xt01a.adb is written for the thick binding and x01a.adb is written to the new binding. Coding for the Ada examples should use Ada constructs and functions as needed. (See the other note from me today relating to the sprintf problem from a few days ago.) Once an example is complete for one binding, the corresponding example can be automatically generated by a series of string substitutions for subroutine names on the source--that's how I plan to generate the new binding as well. Jerry - This SF.net email is sponsored by DB2 Express Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now. http://sourceforge.net/powerbar/db2/ ___ Plplot-devel mailing list Plplot-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/plplot-devel
Re: [Plplot-devel] Ada bindings and examples
On 2007-06-01 15:18-0700 Jerry wrote: > [...]To summarize: The plan is to make a quasi-third Ada binding which is > exactly like the current thick binding except that the subroutine > names are the traditional PLplot names. There will be two example > files for each example, one written to the thick binding and one > written to the new binding. The naming conventions are e.g. for > Example 1, xt01a.adb is written for the thick binding and x01a.adb is > written to the new binding. > > Coding for the Ada examples should use Ada constructs and functions > as needed. (See the other note from me today relating to the sprintf > problem from a few days ago.) > > Once an example is complete for one binding, the corresponding > example can be automatically generated by a series of string > substitutions for subroutine names on the source--that's how I plan > to generate the new binding as well. Sounds like an excellent plan. Alan __ Alan W. Irwin Astronomical research affiliation with Department of Physics and Astronomy, University of Victoria (astrowww.phys.uvic.ca). Programming affiliations with the FreeEOS equation-of-state implementation for stellar interiors (freeeos.sf.net); PLplot scientific plotting software package (plplot.org); the libLASi project (unifont.org/lasi); the Loads of Linux Links project (loll.sf.net); and the Linux Brochure Project (lbproject.sf.net). __ Linux-powered Science __ - This SF.net email is sponsored by DB2 Express Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now. http://sourceforge.net/powerbar/db2/ ___ Plplot-devel mailing list Plplot-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/plplot-devel