gm2
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Gm2] Re: How do I declare a character pointer returned from a "C" funct


From: john o goyo
Subject: [Gm2] Re: How do I declare a character pointer returned from a "C" function?
Date: Tue, 31 Aug 2010 18:23:27 -0400

Results below.

On 31-Aug-10, at 1:20 PM, Gaius Mulley wrote:
Okay -- my question was too generic.  Specifically, it seems that the
TermFile tests fail on Solaris 10 because TermFile.mod tries to open /
dev/tty and this does not work in Solaris 10.  The recommended method
is to retrieve the name of the current terminal via ttyname() or
ttyname_r(), preferably the latter.  In both cases, pointers to the
string containing the name are returned.

I wish to replace the Assign('/dev/tty', a) statement in
TermFile.getname() with a call to ttyname_r() but I do not know how
to define the latter in libc.def.  If I define it as you suggest,
then it is unclear to me how to copy the contents of the string into
a (locus citato).


Hi John,

I hope you don't mind me CC:ing the list as this technique maybe
useful to others interfacing to C based libraries.

I understand the question better now I think and would use
the module DynamicStrings to create a String and CopyOut the
result.  So


PROCEDURE getname (d: DeviceTablePtr;
                   VAR a: ARRAY OF CHAR) ;
BEGIN
   Assign('/dev/tty', a)
END getname ;

could be replaced with the following code:

IMPORT DynamicStrings ;

  ...

PROCEDURE getname (d: DeviceTablePtr;
                   VAR a: ARRAY OF CHAR) ;
VAR
   s: DynamicStrings.String ;
BEGIN
   s := DynamicStrings.InitStringCharStar(ttyname_r()) ;
   DynamicStrings.CopyOut(a, s) ;
   s := DynamicStrings.KillString(s)
END getname ;

To start, here is the definition of ttyname() from "man ttyname".

        char *ttyname(int fildes);

I defined this as follows in libc.def.

        PROCEDURE ttyname(fildes :INTEGER) :ADDRESS;

Here is the new getname().

PROCEDURE getname (d: DeviceTablePtr;
                   VAR a: ARRAY OF CHAR) ;
VAR
   s: DynamicStrings.String ;
BEGIN
   s := DynamicStrings.InitStringCharStar(libc.ttyname(0)) ;
   DynamicStrings.CopyOut(a, s) ;
   s := DynamicStrings.KillString(s)
   (*Assign('/dev/tty', a)*)
END getname ;

I then rebuilt from scratch and was rewarded with the following.

./xgm2 -fsoft-check-all -g -funbounded-by-reference -fiso -fextended- opaque -Wpedantic-cast -Wpedantic-param-names -ffunction-sections - fdata-sections -c -B./stage1/gm2 -g -gdwarf-2 -B./ -Igm2/gm2-libs- iso:../../../src/gcc-4.1.2/gcc/gm2/gm2-libs-iso -I../../../src/ gcc-4.1.2/gcc/gm2/gm2-libs ../../../src/gcc-4.1.2/gcc/gm2/gm2-libs- iso/TermFile.mod -o gm2/gm2-libs-iso/TermFile.o
Internal error: Segmentation Fault

Suggestions are welcome.

john







regards,
Gaius




reply via email to

[Prev in Thread] Current Thread [Next in Thread]