comp.lang.ada
 help / color / mirror / Atom feed
* Libraries written in Ada
@ 2004-11-22 11:32 Thomas Lotze
  2004-11-22 15:58 ` Martin Krischik
  0 siblings, 1 reply; 25+ messages in thread
From: Thomas Lotze @ 2004-11-22 11:32 UTC (permalink / raw)


Hi,

I'm thinking about developing a library implementing a document model and
file format, and it seems Ada is a good choice of language for that. I
wonder, however, whether Ada's runtime environment doesn't count as a con
there.

The problem is not that it has to be initialized when using the library
from another language, e.g. C. Many libraries need some initialization.
But suppose I use two libs written in Ada in the same C program - will
there be problems with the runtime environment? I don't think there
should, just asking for your experience to be sure. (I also considered
OCaml, and it's a problem there. But linking works differently with OCaml
so that each lib effectively brings it's own runtime environment.)

Can the runtime environment and its initialization be omitted completely
by dropping runtime checks on variable bounds etc?

-- 
Viele Gr��e,
Thomas




^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: Libraries written in Ada
  2004-11-22 11:32 Libraries written in Ada Thomas Lotze
@ 2004-11-22 15:58 ` Martin Krischik
  2004-11-22 16:28   ` Thomas Lotze
  0 siblings, 1 reply; 25+ messages in thread
From: Martin Krischik @ 2004-11-22 15:58 UTC (permalink / raw)


Thomas Lotze wrote:

> I'm thinking about developing a library implementing a document model and
> file format, and it seems Ada is a good choice of language for that. I
> wonder, however, whether Ada's runtime environment doesn't count as a con
> there.
> 
> The problem is not that it has to be initialized when using the library
> from another language, e.g. C. Many libraries need some initialization.
> But suppose I use two libs written in Ada in the same C program - will
> there be problems with the runtime environment? I don't think there
> should, just asking for your experience to be sure. (I also considered
> OCaml, and it's a problem there. But linking works differently with OCaml
> so that each lib effectively brings it's own runtime environment.)
> 
> Can the runtime environment and its initialization be omitted completely
> by dropping runtime checks on variable bounds etc?

No, Ada packages allow for initialization code to included. Ada itself makes
shure all initialisation code is executed - even when several libraries are
combined. This happens automaticly when the main procedure is written in
Ada.

When main is written in another language then the standard demands that
"some form of initialisation" is provided. In GNAT this is done be:

void adainit (void);

You can request another name if you like or need.

The GNAT binder will generate this procedure for you and it will init all
libraries involved.

The good thing about Ada is that the ISO standard demands that if
interfacing with a language is allowed then one must allow main in that
language as well and must provide a way to initializing the runtime
environment. - Its not an optional exta.

The ISO Standart also defines interfacing with C, FORTRAN and COBOL. AFAIK
Ada is the only language where interfacing with other languages is defined
that strict.

Well the Standard does not say anything about DLLs. However, at least GNAT
can encapsulate the runtime initialisation on DLL level as well - making
shure that no DLL is initialized twice even when a "diamond" is the DLL
hirachie.

No realy no prob here.

With Regards

Martin

-- 
mailto://krischik@users.sourceforge.net
http://www.ada.krischik.com



^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: Libraries written in Ada
  2004-11-22 15:58 ` Martin Krischik
@ 2004-11-22 16:28   ` Thomas Lotze
  2004-11-22 16:46     ` Alex R. Mosteo
  2004-11-22 17:59     ` Martin Krischik
  0 siblings, 2 replies; 25+ messages in thread
From: Thomas Lotze @ 2004-11-22 16:28 UTC (permalink / raw)


On Mon, 22 Nov 2004 16:58:59 +0100, Martin Krischik wrote:

> No, Ada packages allow for initialization code to included. Ada itself
> makes shure all initialisation code is executed - even when several
> libraries are combined. This happens automaticly when the main procedure
> is written in Ada.

Does this mean every package contains its own runtime environment, or does
every package do some initialization on a common runtime?

> When main is written in another language then the standard demands that
> "some form of initialisation" is provided. In GNAT this is done be:
> 
> void adainit (void);
> 
> You can request another name if you like or need.

This would make it possible to initialize several Ada libraries separately
in a C main program.

> The GNAT binder will generate this procedure for you and it will init all
> libraries involved.

And this seems to make it necessary, at least if I don't want to expose
the implementation details of the libraries to the extent that all used
Ada libraries have to be bound together by GNAT before they can be bound
to a C main as a whole (or do I get something completely wrong here?).

That is, if I have libraries libfoo and libbar written in Ada and
installed in binary form along with appropriate C include files, can I get
away without using GNAT if I call both adainit_foo() and adainit_bar() in
the C main? I think it's much better for library users if they don't have
to do a separate GNAT binding step but can ignore the fact that there's
Ada behind the scenes except for the initialization calls.

-- 
Viele Gr��e,
Thomas




^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: Libraries written in Ada
  2004-11-22 16:28   ` Thomas Lotze
@ 2004-11-22 16:46     ` Alex R. Mosteo
  2004-11-22 19:09       ` Pascal Obry
  2004-11-22 17:59     ` Martin Krischik
  1 sibling, 1 reply; 25+ messages in thread
From: Alex R. Mosteo @ 2004-11-22 16:46 UTC (permalink / raw)


Thomas Lotze wrote:
> On Mon, 22 Nov 2004 16:58:59 +0100, Martin Krischik wrote:
> 
> 
>>No, Ada packages allow for initialization code to included. Ada itself
>>makes shure all initialisation code is executed - even when several
>>libraries are combined. This happens automaticly when the main procedure
>>is written in Ada.
> 
> 
> Does this mean every package contains its own runtime environment, or does
> every package do some initialization on a common runtime?

At least in the DLL case, each one has its own runtime.

> 
> 
>>When main is written in another language then the standard demands that
>>"some form of initialisation" is provided. In GNAT this is done be:
>>
>>void adainit (void);
>>
>>You can request another name if you like or need.
> 
> 
> This would make it possible to initialize several Ada libraries separately
> in a C main program.
> 
> 
>>The GNAT binder will generate this procedure for you and it will init all
>>libraries involved.
> 
> 
> And this seems to make it necessary, at least if I don't want to expose
> the implementation details of the libraries to the extent that all used
> Ada libraries have to be bound together by GNAT before they can be bound
> to a C main as a whole (or do I get something completely wrong here?).
> 
> That is, if I have libraries libfoo and libbar written in Ada and
> installed in binary form along with appropriate C include files, can I get
> away without using GNAT if I call both adainit_foo() and adainit_bar() in
> the C main? I think it's much better for library users if they don't have
> to do a separate GNAT binding step but can ignore the fact that there's
> Ada behind the scenes except for the initialization calls.
> 



^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: Libraries written in Ada
  2004-11-22 16:28   ` Thomas Lotze
  2004-11-22 16:46     ` Alex R. Mosteo
@ 2004-11-22 17:59     ` Martin Krischik
  2004-11-22 20:36       ` Thomas Lotze
  2004-11-22 20:45       ` Georg Bauhaus
  1 sibling, 2 replies; 25+ messages in thread
From: Martin Krischik @ 2004-11-22 17:59 UTC (permalink / raw)


Thomas Lotze wrote:

> On Mon, 22 Nov 2004 16:58:59 +0100, Martin Krischik wrote:
> 
>> No, Ada packages allow for initialization code to included. Ada itself
>> makes shure all initialisation code is executed - even when several
>> libraries are combined. This happens automaticly when the main procedure
>> is written in Ada.
> 
> Does this mean every package contains its own runtime environment, or does
> every package do some initialization on a common runtime?

Actually both. The common runtime consists of packages as well and every
package may or may not have it's own mini runtime environment. There are
pragma instructions to controll that i.E. "pragma Pure" says that a package
has no runtime environment and does not use another package with a runtime
environment.

Please Note: you are asking very low level questions. Normaly you don't need
to worry about it. Ada as a package orientated language has it all build.

That's unlike C where library management is not part of the language and
elaboration (that the Ada term for initialising the runtime environment)
consists of main () only. 

>> When main is written in another language then the standard demands that
>> "some form of initialisation" is provided. In GNAT this is done be:
>> 
>> void adainit (void);
>> 
>> You can request another name if you like or need.
> 
> This would make it possible to initialize several Ada libraries separately
> in a C main program.

Yes. But unless you use DLLs this is not needed. You tell the binder which
top level packages you need and the binder will recusivly elaborate
everthing needed.

With GNAT you can even control if elaboration order should be calculated
staticly at bind time or dynamicly at run time.

>> The GNAT binder will generate this procedure for you and it will init all
>> libraries involved.

> And this seems to make it necessary, at least if I don't want to expose
> the implementation details of the libraries to the extent that all used
> Ada libraries have to be bound together by GNAT before they can be bound
> to a C main as a whole (or do I get something completely wrong here?).

That's the normal way for static linking. It does have the advantage that
the binder will bind and elaborate only the packages which are actually
used.

> That is, if I have libraries libfoo and libbar written in Ada and
> installed in binary form along with appropriate C include files, can I get
> away without using GNAT if I call both adainit_foo() and adainit_bar() in
> the C main? I think it's much better for library users if they don't have
> to do a separate GNAT binding step but can ignore the fact that there's
> Ada behind the scenes except for the initialization calls.

Well, This looks you pretty much plan a DLL approach. And yes: In an DLL
environment that is what you do. Have the binder create one init per DLL
and then main() must call them one after the other.

GNAT provides the basic Ada packages also as DLL. So no duplicate code here.

With Regards

Martin


-- 
mailto://krischik@users.sourceforge.net
http://www.ada.krischik.com



^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: Libraries written in Ada
  2004-11-22 16:46     ` Alex R. Mosteo
@ 2004-11-22 19:09       ` Pascal Obry
  2004-11-23 11:12         ` Alex R. Mosteo
  0 siblings, 1 reply; 25+ messages in thread
From: Pascal Obry @ 2004-11-22 19:09 UTC (permalink / raw)



"Alex R. Mosteo" <devnull@mailinator.com> writes:

> > Does this mean every package contains its own runtime environment, or does
> > every package do some initialization on a common runtime?
> 
> At least in the DLL case, each one has its own runtime.

Not if you use a Shared Runtime. This is supported on Windows with recent GNAT
versions.

Pascal.

-- 

--|------------------------------------------------------
--| Pascal Obry                           Team-Ada Member
--| 45, rue Gabriel Peri - 78114 Magny Les Hameaux FRANCE
--|------------------------------------------------------
--|              http://www.obry.org
--| "The best way to travel is by means of imagination"
--|
--| gpg --keyserver wwwkeys.pgp.net --recv-key C1082595



^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: Libraries written in Ada
  2004-11-22 17:59     ` Martin Krischik
@ 2004-11-22 20:36       ` Thomas Lotze
  2004-11-22 21:25         ` Georg Bauhaus
  2004-11-23  9:48         ` Martin Krischik
  2004-11-22 20:45       ` Georg Bauhaus
  1 sibling, 2 replies; 25+ messages in thread
From: Thomas Lotze @ 2004-11-22 20:36 UTC (permalink / raw)


On Mon, 22 Nov 2004 18:59:16 +0100, Martin Krischik wrote:

> Actually both. The common runtime consists of packages as well and every
> package may or may not have it's own mini runtime environment. There are
> pragma instructions to controll that i.E. "pragma Pure" says that a
> package has no runtime environment and does not use another package with a
> runtime environment.

And even though it is thus possible to have an Ada package which doesn't
need a runtime environment, it is always necessary to initialize one? Is
that what you meant by "it's not an optional extra" in one of your
earlier messages?

> Please Note: you are asking very low level questions. Normaly you don't
> need to worry about it. Ada as a package orientated language has it all
> build.

Sure, but I'd like to know what implications my choice of language has for
using the library I want to write before I lean back and feel happy about
leaving these details to the language.

> That's the normal way for static linking. It does have the advantage that
> the binder will bind and elaborate only the packages which are actually
> used.

Nice.

Thanks for your explanations so far. One thing I haven't thought about
asking yet: What does adafinal() normally do? Does it things like flushing
file buffers and closing files, or is it just about cleaning up memory?
So, if it is the last function called from main(), may it just as well be
omitted?

-- 
Viele Gr��e,
Thomas




^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: Libraries written in Ada
  2004-11-22 17:59     ` Martin Krischik
  2004-11-22 20:36       ` Thomas Lotze
@ 2004-11-22 20:45       ` Georg Bauhaus
  1 sibling, 0 replies; 25+ messages in thread
From: Georg Bauhaus @ 2004-11-22 20:45 UTC (permalink / raw)


Martin Krischik <martin@krischik.com> wrote:
: Please Note: you are asking very low level questions. Normaly you don't need
: to worry about it. Ada as a package orientated language has it all build.
: 
: That's unlike C where library management is not part of the language and
: elaboration (that the Ada term for initialising the runtime environment)
: consists of main () only. 

Uhm, if inside a package

   pragma Pure;

applies and

   foo: constant Bar := <static expression>;

is elaborated, what has initialising the Ada runtime system got to do with
it? (Or do you mean something different by  "initialising the runtime
environment"?) Pragma Pure claims something about elaboration needs _at_
runtime by placing
    "sufficient restrictions on a unit to guarantee that no call
     to any subprogram in the unit can result in an elaboration
     problem"  (GNAT User's Guide)
The Ada runtime system may have to deal with elaboration at runtime.
So there has to be one, unless the (Subset-of-)Ada program has been
written such that no run time system is needed.

-- Georg



^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: Libraries written in Ada
  2004-11-22 20:36       ` Thomas Lotze
@ 2004-11-22 21:25         ` Georg Bauhaus
  2004-11-22 21:45           ` Thomas Lotze
  2004-11-23  9:48         ` Martin Krischik
  1 sibling, 1 reply; 25+ messages in thread
From: Georg Bauhaus @ 2004-11-22 21:25 UTC (permalink / raw)


Thomas Lotze <thomas@thomas-lotze.de> wrote:
 
: And even though it is thus possible to have an Ada package which doesn't
: need a runtime environment,

While it is possible to write Ada programs that do not need a runtime
system, it is probably misleading to say that because there is a
pragma Pure, a package needs no runtime environment (whatever is meant
by the term).

: Sure, but I'd like to know what implications my choice of language has for
: using the library I want to write before I lean back and feel happy about
: leaving these details to the language.

A good place to look for an answer is the compiler documentation.
For GNAT, you will find sections about creating DLLs in Ada (and
shared libraries). In particular, there is "Binding with Non-Ada
Main Programs".
ObjectAda allows the creation of DLLs as well.



-- Georg Bauhaus



^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: Libraries written in Ada
  2004-11-22 21:25         ` Georg Bauhaus
@ 2004-11-22 21:45           ` Thomas Lotze
  2004-11-22 22:07             ` Georg Bauhaus
  0 siblings, 1 reply; 25+ messages in thread
From: Thomas Lotze @ 2004-11-22 21:45 UTC (permalink / raw)


On Mon, 22 Nov 2004 21:25:08 +0000, Georg Bauhaus wrote:

> While it is possible to write Ada programs that do not need a runtime
> system, it is probably misleading to say that because there is a pragma
> Pure, a package needs no runtime environment (whatever is meant by the
> term).

I didn't mean to say that; I do understand that in order to have a package
without a runtime environment, first of all the package's functionality
must not need one.

> A good place to look for an answer is the compiler documentation. For
> GNAT, you will find sections about creating DLLs in Ada (and shared
> libraries). In particular, there is "Binding with Non-Ada Main Programs".

That'll give me something to read... thanks for the hint.

> ObjectAda allows the creation of DLLs as well.

Is my impression correct that there's no free implementation of ObjectAda?

-- 
Viele Gr��e,
Thomas




^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: Libraries written in Ada
  2004-11-22 21:45           ` Thomas Lotze
@ 2004-11-22 22:07             ` Georg Bauhaus
  2004-11-22 22:27               ` Thomas Lotze
  2004-11-23  9:55               ` Martin Krischik
  0 siblings, 2 replies; 25+ messages in thread
From: Georg Bauhaus @ 2004-11-22 22:07 UTC (permalink / raw)


Thomas Lotze <thomas@thomas-lotze.de> wrote:
: 
:> ObjectAda allows the creation of DLLs as well.
: 
: Is my impression correct that there's no free implementation of ObjectAda?

There is a free system, with some restrictions on the number of compilation
units. The compiler adds a differently flavored kind of useful diagnostic
messages to the ones you get from GNAT. You can check (some of) your files
for portability by building small subsystems using either compiler. (For
example, small test cases.)


-- Georg Bauhaus



^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: Libraries written in Ada
  2004-11-22 22:07             ` Georg Bauhaus
@ 2004-11-22 22:27               ` Thomas Lotze
  2004-11-23  9:54                 ` Adrien Plisson
  2004-11-23  9:55                 ` Martin Krischik
  2004-11-23  9:55               ` Martin Krischik
  1 sibling, 2 replies; 25+ messages in thread
From: Thomas Lotze @ 2004-11-22 22:27 UTC (permalink / raw)


On Mon, 22 Nov 2004 22:07:16 +0000, Georg Bauhaus wrote:

> There is a free system, with some restrictions on the number of
> compilation units.

Read: an intentionally limited version of the commercial compiler?

-- 
Viele Gr��e,
Thomas




^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: Libraries written in Ada
  2004-11-22 20:36       ` Thomas Lotze
  2004-11-22 21:25         ` Georg Bauhaus
@ 2004-11-23  9:48         ` Martin Krischik
  2004-11-23 11:03           ` Thomas Lotze
  1 sibling, 1 reply; 25+ messages in thread
From: Martin Krischik @ 2004-11-23  9:48 UTC (permalink / raw)


Thomas Lotze wrote:

> On Mon, 22 Nov 2004 18:59:16 +0100, Martin Krischik wrote:
> 
>> Actually both. The common runtime consists of packages as well and every
>> package may or may not have it's own mini runtime environment. There are
>> pragma instructions to controll that i.E. "pragma Pure" says that a
>> package has no runtime environment and does not use another package with
>> a runtime environment.
> 
> And even though it is thus possible to have an Ada package which doesn't
> need a runtime environment, it is always necessary to initialize one? Is
> that what you meant by "it's not an optional extra" in one of your
> earlier messages?

Consider the following package:

package body
   Test
is

  Y : Integer;

  procedure X 
  is
  begin
    Y := 1;
  end X;

begin
  X;
end Test;

In this case "Y" is the runtime environment and unless you have activated
very agressive optimization the procedure X need to called at package
elaboration.

Of corse:

package body
   Test
is

  Y : Integer := 1;

end Test;

can be preelaborated by the compiler and then no runtime elaboration is
needed.

>> Please Note: you are asking very low level questions. Normaly you don't
>> need to worry about it. Ada as a package orientated language has it all
>> build.

> Sure, but I'd like to know what implications my choice of language has for
> using the library I want to write before I lean back and feel happy about
> leaving these details to the language.

If you like low leve: I the excample above the GNAT compiler will create a
"package X init" procedure and a Boolean "package X initilized" (I could
find out the actual names - but I don't think it is needed). adainit ()
will check the boolean and call procedure when needed.

>> That's the normal way for static linking. It does have the advantage that
>> the binder will bind and elaborate only the packages which are actually
>> used.

> Nice.
 
> Thanks for your explanations so far. One thing I haven't thought about
> asking yet: What does adafinal() normally do? Does it things like flushing
> file buffers and closing files, or is it just about cleaning up memory?
> So, if it is the last function called from main(), may it just as well be
> omitted?

Ada95 is a object orientated language with some form contructor/descructor
system called controled objects. adafinal () will call the finalisation for
static controled objects.

With Regards

Martin

-- 
mailto://krischik@users.sourceforge.net
http://www.ada.krischik.com



^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: Libraries written in Ada
  2004-11-22 22:27               ` Thomas Lotze
@ 2004-11-23  9:54                 ` Adrien Plisson
  2004-11-23  9:55                 ` Martin Krischik
  1 sibling, 0 replies; 25+ messages in thread
From: Adrien Plisson @ 2004-11-23  9:54 UTC (permalink / raw)


Thomas Lotze wrote:
> On Mon, 22 Nov 2004 22:07:16 +0000, Georg Bauhaus wrote:
> 
>>There is a free system, with some restrictions on the number of
>>compilation units.
> 
> Read: an intentionally limited version of the commercial compiler?

you read it right !

-- 
rien



^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: Libraries written in Ada
  2004-11-22 22:07             ` Georg Bauhaus
  2004-11-22 22:27               ` Thomas Lotze
@ 2004-11-23  9:55               ` Martin Krischik
  1 sibling, 0 replies; 25+ messages in thread
From: Martin Krischik @ 2004-11-23  9:55 UTC (permalink / raw)


Georg Bauhaus wrote:

> Thomas Lotze <thomas@thomas-lotze.de> wrote:
> : 
> :> ObjectAda allows the creation of DLLs as well.
> : 
> : Is my impression correct that there's no free implementation of
> : ObjectAda?
> 
> There is a free system, with some restrictions on the number of
> compilation units. The compiler adds a differently flavored kind of useful
> diagnostic messages to the ones you get from GNAT. You can check (some of)
> your files for portability by building small subsystems using either
> compiler. (For example, small test cases.)

With that "some restrictions" you can't even compile the booch components
since the "number of compilation units" is 37 and that is not enough for a
package orientated language like Ada where good coding praxis is one class
per package.

With Regards

Martin

-- 
mailto://krischik@users.sourceforge.net
http://www.ada.krischik.com



^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: Libraries written in Ada
  2004-11-22 22:27               ` Thomas Lotze
  2004-11-23  9:54                 ` Adrien Plisson
@ 2004-11-23  9:55                 ` Martin Krischik
  1 sibling, 0 replies; 25+ messages in thread
From: Martin Krischik @ 2004-11-23  9:55 UTC (permalink / raw)


Thomas Lotze wrote:

> On Mon, 22 Nov 2004 22:07:16 +0000, Georg Bauhaus wrote:
> 
>> There is a free system, with some restrictions on the number of
>> compilation units.
> 
> Read: an intentionally limited version of the commercial compiler?

Yes!

With Regards

Martin
-- 
mailto://krischik@users.sourceforge.net
http://www.ada.krischik.com



^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: Libraries written in Ada
  2004-11-23  9:48         ` Martin Krischik
@ 2004-11-23 11:03           ` Thomas Lotze
  2004-11-23 11:38             ` Alex R. Mosteo
  2004-11-23 12:36             ` Martin Krischik
  0 siblings, 2 replies; 25+ messages in thread
From: Thomas Lotze @ 2004-11-23 11:03 UTC (permalink / raw)


On Tue, 23 Nov 2004 10:48:45 +0100, Martin Krischik wrote:

> can be preelaborated by the compiler and then no runtime elaboration is
> needed.

How can I find out whether the code produced by the compiler (not a
specific one, but any compiler that conforms to the spec) needs runtime
elaboration? Are there simple rules such as "this code pattern may or does
require runtime elaboration while that pattern can be safely assumed to
work without"? I'd have to dig further through the references, but I
haven't found a clear statement so far.

> If you like low leve: I the excample above the GNAT compiler will create a
> "package X init" procedure and a Boolean "package X initilized" (I could
> find out the actual names - but I don't think it is needed). adainit ()
> will check the boolean and call procedure when needed.

So it's not possible to reset a package in the midst of program execution?
If so, is it a conscious design decision, and what's the rationale? (The
solution seems to be offering reset functionality in the package.)

> Ada95 is a object orientated language with some form contructor/descructor
> system called controled objects. adafinal () will call the finalisation
> for static controled objects.

What if a package doesn't have any specific finalization code? Is there
some generic stuff that must always be run, or can finalization be omitted
in such a case?

-- 
Viele Gr��e,
Thomas




^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: Libraries written in Ada
  2004-11-22 19:09       ` Pascal Obry
@ 2004-11-23 11:12         ` Alex R. Mosteo
  0 siblings, 0 replies; 25+ messages in thread
From: Alex R. Mosteo @ 2004-11-23 11:12 UTC (permalink / raw)


Pascal Obry wrote:
> "Alex R. Mosteo" <devnull@mailinator.com> writes:
> 
> 
>>>Does this mean every package contains its own runtime environment, or does
>>>every package do some initialization on a common runtime?
>>
>>At least in the DLL case, each one has its own runtime.
> 
> 
> Not if you use a Shared Runtime. This is supported on Windows with recent GNAT
> versions.

Good to know!



^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: Libraries written in Ada
  2004-11-23 11:03           ` Thomas Lotze
@ 2004-11-23 11:38             ` Alex R. Mosteo
  2004-11-23 12:22               ` Georg Bauhaus
  2004-11-23 12:36             ` Martin Krischik
  1 sibling, 1 reply; 25+ messages in thread
From: Alex R. Mosteo @ 2004-11-23 11:38 UTC (permalink / raw)


Thomas Lotze wrote:
> On Tue, 23 Nov 2004 10:48:45 +0100, Martin Krischik wrote:
> 
> 
>>can be preelaborated by the compiler and then no runtime elaboration is
>>needed.
> 
> 
> How can I find out whether the code produced by the compiler (not a
> specific one, but any compiler that conforms to the spec) needs runtime
> elaboration? Are there simple rules such as "this code pattern may or does
> require runtime elaboration while that pattern can be safely assumed to
> work without"? I'd have to dig further through the references, but I
> haven't found a clear statement so far.

Look for the pragma No_Runtime if you're using Gnat.

And look in the Ada Reference Manual for the pragmas Pure, Preelaborate 
& Elaborate_Body for elaboration concerns. I read these from time to 
time and always manage to forget the details ;)

In particular, I'm not sure about the situation when your package can't 
have "preelaborate" and you don't specify an "elaborate_body". It's not 
the same (at least Gnat doesn't behave the same).

And then there's that "elaborate" and "elaborate_all" which I suspect 
that apply in the previous case, but I never like to use. I don't like 
the package that uses another to have to worry about such pragmas, I 
prefer to have everything self-managed when possible. But maybe I'm 
confusing something.

Finally you have that Gnat warning switch (that I don't remember now) 
which will warn you about elaboration order problems. Activating it late 
in a project will make you cry when you see the lots of "elaborate_all 
needed" it reports and you don't understand why :P

Hint to adapower and adaworld :D : Set Up an explanation for the 
elaboration misteries of Ada in non-ARM speak.





^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: Libraries written in Ada
  2004-11-23 11:38             ` Alex R. Mosteo
@ 2004-11-23 12:22               ` Georg Bauhaus
  2004-11-23 13:20                 ` Alex R. Mosteo
  0 siblings, 1 reply; 25+ messages in thread
From: Georg Bauhaus @ 2004-11-23 12:22 UTC (permalink / raw)


Alex R. Mosteo <devnull@mailinator.com> wrote:
: Hint to adapower and adaworld :D : Set Up an explanation for the 
: elaboration misteries of Ada in non-ARM speak.

It's called the GNAT User's Guide. I believe the extensive section on
elaboration is largely written/edited by Robert Dewar.
It has examples, too.

-- Georg Bauhaus



^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: Libraries written in Ada
  2004-11-23 11:03           ` Thomas Lotze
  2004-11-23 11:38             ` Alex R. Mosteo
@ 2004-11-23 12:36             ` Martin Krischik
  2004-11-23 13:53               ` Thomas Lotze
  1 sibling, 1 reply; 25+ messages in thread
From: Martin Krischik @ 2004-11-23 12:36 UTC (permalink / raw)


Thomas Lotze wrote:

> On Tue, 23 Nov 2004 10:48:45 +0100, Martin Krischik wrote:
> 
>> can be preelaborated by the compiler and then no runtime elaboration is
>> needed.
> 
> How can I find out whether the code produced by the compiler (not a
> specific one, but any compiler that conforms to the spec) needs runtime
> elaboration? Are there simple rules such as "this code pattern may or does
> require runtime elaboration while that pattern can be safely assumed to
> work without"? I'd have to dig further through the references, but I
> haven't found a clear statement so far.

You can restrict packages to not use specific elaboations:

pragma Pure ();
pragma Preelaboreate ();

The pragmas are for the Annex E where these things are more important than
in normal development.

>> If you like low leve: I the excample above the GNAT compiler will create
>> a "package X init" procedure and a Boolean "package X initilized" (I
>> could find out the actual names - but I don't think it is needed).
>> adainit () will check the boolean and call procedure when needed.
> 
> So it's not possible to reset a package in the midst of program execution?
> If so, is it a conscious design decision, and what's the rationale? (The
> solution seems to be offering reset functionality in the package.)

A conscious design decision:

package 
  Test
is

   Y : constant Integer = X (...);

end Test;
 
Do I have to explain it or do you spot it yourself ;-) .

>> Ada95 is a object orientated language with some form
>> contructor/descructor system called controled objects. adafinal () will
>> call the finalisation for static controled objects.
> 
> What if a package doesn't have any specific finalization code? Is there
> some generic stuff that must always be run, or can finalization be omitted
> in such a case?

With GNAT the binder will automaticly generate the needed code just like
with adainit ().

The code generated by the binder is stored in some b~ file. It is a normal
Ada source code. In Ada only programms the binder output is deleted
imediatly after linking - in mixed language development the binder output
is not deleted. More over: you can choose Ada or C as bind language -
whatever suits you best.

BTW: That's where I got my knowledge from: I did make an Ada library for use
with C (http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/adacl/CUnicode) and
had more then one good look at the binder output.

And to be honest: While it is possible to write Ada code that does not need
any init or term - you won't have much fun doing so. i.E.

package Interface.C is Pure but
package Interface.C.Strings is only Preelaborate and
package Ada.Text_IO is unmarked.

And if a package is unmarked then you have to expect both init and term.

With Regards

Martin
-- 
mailto://krischik@users.sourceforge.net
http://www.ada.krischik.com



^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: Libraries written in Ada
  2004-11-23 12:22               ` Georg Bauhaus
@ 2004-11-23 13:20                 ` Alex R. Mosteo
  2004-11-23 13:40                   ` Alex R. Mosteo
  0 siblings, 1 reply; 25+ messages in thread
From: Alex R. Mosteo @ 2004-11-23 13:20 UTC (permalink / raw)


Georg Bauhaus wrote:
> Alex R. Mosteo <devnull@mailinator.com> wrote:
> : Hint to adapower and adaworld :D : Set Up an explanation for the 
> : elaboration misteries of Ada in non-ARM speak.
> 
> It's called the GNAT User's Guide. I believe the extensive section on
> elaboration is largely written/edited by Robert Dewar.
> It has examples, too.

Which I must have read and forgotten too. Time for another go.



^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: Libraries written in Ada
  2004-11-23 13:20                 ` Alex R. Mosteo
@ 2004-11-23 13:40                   ` Alex R. Mosteo
  0 siblings, 0 replies; 25+ messages in thread
From: Alex R. Mosteo @ 2004-11-23 13:40 UTC (permalink / raw)


Alex R. Mosteo wrote:
> Georg Bauhaus wrote:
> 
>> Alex R. Mosteo <devnull@mailinator.com> wrote:
>> : Hint to adapower and adaworld :D : Set Up an explanation for the : 
>> elaboration misteries of Ada in non-ARM speak.
>>
>> It's called the GNAT User's Guide. I believe the extensive section on
>> elaboration is largely written/edited by Robert Dewar.
>> It has examples, too.
> 
> 
> Which I must have read and forgotten too. Time for another go.

Just re-reading it I see this paragraph which summarizes my rule of 
thumb. No surprise I got it from here even if I had forgotten it:

"The above pragmas allow a server to guarantee safe use by clients, and 
clearly this is the preferable approach. Consequently a good rule in Ada 
95 is to mark units as Pure or Preelaborate if possible, and if this is 
not possible, mark them as Elaborate_Body if possible. As we have seen, 
there are situations where neither of these three pragmas can be used. 
So we also provide methods for clients to control the order of 
elaboration of the servers on which they depend: (...)"

BTW as Georg pointed, that chapter is a very comprehensible read, highly 
recommended to every Ada programmer!



^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: Libraries written in Ada
  2004-11-23 12:36             ` Martin Krischik
@ 2004-11-23 13:53               ` Thomas Lotze
  2004-11-23 18:39                 ` Jeffrey Carter
  0 siblings, 1 reply; 25+ messages in thread
From: Thomas Lotze @ 2004-11-23 13:53 UTC (permalink / raw)


On Tue, 23 Nov 2004 13:36:02 +0100, Martin Krischik wrote:

> You can restrict packages to not use specific elaboations:
> 
> pragma Pure ();
> pragma Preelaboreate ();
> 
> The pragmas are for the Annex E where these things are more important than
> in normal development.

Ah, now I found what I was looking for. The ARM really makes for some
reading...

>> So it's not possible to reset a package in the midst of program
>> execution? If so, is it a conscious design decision, and what's the
>> rationale? (The solution seems to be offering reset functionality in the
>> package.)
> 
> A conscious design decision:
> 
> package
>   Test
> is
> 
>    Y : constant Integer = X (...);
> 
> end Test;
>  
> Do I have to explain it or do you spot it yourself ;-) .

The value of the constant might be different after a hypothetical
re-elaboration. So there would still be no problem if a constant was
understood to not change its value _after_ elaboration. In your example
I'd have a constant of unknown value anyway (or X() would have to always
yield the same value, in which case we'd be discussing a non-existing
problem), so you'd be just as fine after a re-elaboration as before
provided you treat such an event as a kind of Big Bang and never try to
connect information from after it with information from before. But I do
admit that this would be a potential well of grief.

> With GNAT the binder will automaticly generate the needed code just like
> with adainit ().
> 
> The code generated by the binder is stored in some b~ file. It is a normal
> Ada source code. In Ada only programms the binder output is deleted
> imediatly after linking - in mixed language development the binder output
> is not deleted.

Yes, I've seen such files. It is possible that adafinal() consists of just
one call to Do_Finalize. Can it be omitted in that case? Neither the ARM
nor the GNAT RM or UG seem to explain it.

> package Interface.C.Strings is only Preelaborate and package Ada.Text_IO
> is unmarked.
> 
> And if a package is unmarked then you have to expect both init and term.

Too bad.

-- 
Viele Gr��e,
Thomas




^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: Libraries written in Ada
  2004-11-23 13:53               ` Thomas Lotze
@ 2004-11-23 18:39                 ` Jeffrey Carter
  0 siblings, 0 replies; 25+ messages in thread
From: Jeffrey Carter @ 2004-11-23 18:39 UTC (permalink / raw)


It's certainly possible to write a package that can be used from C 
without worrying about runtime or initialization/finalization. Just 
follow some simple rules:

* The package must be Pure or Preelaborate

* The package cannot be generic

* Do not use any tasking constructs

* Do not propagate any exceptions

* Any initialization and finalization must be provided by operations 
that must be explicitly called by the user.

In other words, make it look just like a C library.

This is an issue that must be considered by people working on Ada OSes, 
where the interface to the OS is in Ada, and other languages must use a 
binding to the Ada version. It would be interesting to hear how they 
deal with the matter.

-- 
Jeff Carter
"We use a large, vibrating egg."
Annie Hall
44




^ permalink raw reply	[flat|nested] 25+ messages in thread

end of thread, other threads:[~2004-11-23 18:39 UTC | newest]

Thread overview: 25+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-11-22 11:32 Libraries written in Ada Thomas Lotze
2004-11-22 15:58 ` Martin Krischik
2004-11-22 16:28   ` Thomas Lotze
2004-11-22 16:46     ` Alex R. Mosteo
2004-11-22 19:09       ` Pascal Obry
2004-11-23 11:12         ` Alex R. Mosteo
2004-11-22 17:59     ` Martin Krischik
2004-11-22 20:36       ` Thomas Lotze
2004-11-22 21:25         ` Georg Bauhaus
2004-11-22 21:45           ` Thomas Lotze
2004-11-22 22:07             ` Georg Bauhaus
2004-11-22 22:27               ` Thomas Lotze
2004-11-23  9:54                 ` Adrien Plisson
2004-11-23  9:55                 ` Martin Krischik
2004-11-23  9:55               ` Martin Krischik
2004-11-23  9:48         ` Martin Krischik
2004-11-23 11:03           ` Thomas Lotze
2004-11-23 11:38             ` Alex R. Mosteo
2004-11-23 12:22               ` Georg Bauhaus
2004-11-23 13:20                 ` Alex R. Mosteo
2004-11-23 13:40                   ` Alex R. Mosteo
2004-11-23 12:36             ` Martin Krischik
2004-11-23 13:53               ` Thomas Lotze
2004-11-23 18:39                 ` Jeffrey Carter
2004-11-22 20:45       ` Georg Bauhaus

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