* How pass a "null" as a parameter of anonymous access type @ 2001-03-22 20:04 Freddy 2001-03-22 21:02 ` tmoran ` (2 more replies) 0 siblings, 3 replies; 13+ messages in thread From: Freddy @ 2001-03-22 20:04 UTC (permalink / raw) Hello ! I want call a C-binding procedure which is defined as "procedure p (a : access X; b : access Y);" Both a or b may be a null pointer, but Ada say "null not allowed for anonymous access type". Any idea what to do ? ^ permalink raw reply [flat|nested] 13+ messages in thread
* How pass a "null" as a parameter of anonymous access type 2001-03-22 20:04 How pass a "null" as a parameter of anonymous access type Freddy @ 2001-03-22 21:02 ` tmoran 2001-03-25 21:32 ` Freddy 2001-03-23 9:05 ` How pass a "null" as a parameter of anonymous access type Thierry Lelegard 2001-03-26 13:44 ` Marc A. Criley 2 siblings, 1 reply; 13+ messages in thread From: tmoran @ 2001-03-22 21:02 UTC (permalink / raw) > Both a or b may be a null pointer, but Ada say "null not allowed for > anonymous access type". > Any idea what to do ? Make them non-anonymous access types. > I want call a C-binding procedure which is defined as "procedure p (a : > access X; b : access Y);" Instead use type a1 is access X; type b1 is access Y; procedure p(a : a1; b : b1); A variable of type a1 or b1 can be null. ^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: How pass a "null" as a parameter of anonymous access type 2001-03-22 21:02 ` tmoran @ 2001-03-25 21:32 ` Freddy 2001-03-26 14:31 ` How pass a Ted Dennison 0 siblings, 1 reply; 13+ messages in thread From: Freddy @ 2001-03-25 21:32 UTC (permalink / raw) As I stated, this is a C-binding (a library package we've got from elsewhere) and I'm not allowed to modify it. ^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: How pass a 2001-03-25 21:32 ` Freddy @ 2001-03-26 14:31 ` Ted Dennison 0 siblings, 0 replies; 13+ messages in thread From: Ted Dennison @ 2001-03-26 14:31 UTC (permalink / raw) In article <3ABE63F7.3E088F9D@t-online.de>, Freddy says... > >As I stated, this is a C-binding (a library package we've got from >elsewhere) and I'm not allowed to modify it. Perhaps, but nothing's stopping you from making your own "pragma interface"'d routine based on theirs, but with the proper arguments. --- T.E.D. homepage - http://www.telepath.com/dennison/Ted/TED.html home email - mailto:dennison@telepath.com ^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: How pass a "null" as a parameter of anonymous access type 2001-03-22 20:04 How pass a "null" as a parameter of anonymous access type Freddy 2001-03-22 21:02 ` tmoran @ 2001-03-23 9:05 ` Thierry Lelegard 2001-03-25 21:33 ` Freddy 2001-03-26 13:44 ` Marc A. Criley 2 siblings, 1 reply; 13+ messages in thread From: Thierry Lelegard @ 2001-03-23 9:05 UTC (permalink / raw) [-- Attachment #1: Type: text/plain, Size: 846 bytes --] > I want call a C-binding procedure which is defined as "procedure p (a : > access X; b : access Y);" > Both a or b may be a null pointer, but Ada say "null not allowed for > anonymous access type". > Any idea what to do ? A hack (it works with GNAT, but may not with others, not defined by the language): Null_Access : aliased X; -- don't access it !! for Null_Access'Address use System.Null_Address; .... P (Null_Access'Access, ...); -Thierry ____________________________________________________________________________ Thierry Lelegard, "The Jazzing Troll", Email: thierry.lelegard@canal-plus.fr CANAL+ Technologies, 34 place Raoul Dautry, 75516 Paris Cedex 15, France Tel: +33 1 71 71 54 30 Fax: +33 1 71 71 52 08 Mobile: +33 6 03 00 65 75 ____________________________________________________________________________ [-- Warning: decoded text below may be mangled, UTF-8 assumed --] [-- Attachment #2: Carte pour Thierry Lelegard --] [-- Type: text/x-vcard; charset=us-ascii; name="thierry.lelegard.vcf", Size: 333 bytes --] begin:vcard n:Lel�gard;Thierry tel;cell:+33 6 03 00 65 75 tel;fax:+33 1 71 71 52 08 tel;work:+33 1 71 71 54 30 x-mozilla-html:FALSE url:www.canalplus-technologies.com org:Canal+ Technologies adr:;;34, Place Raoul Dautry;Paris;;75516;France version:2.1 email;internet:thierry.lelegard@canal-plus.fr fn:Thierry Lel�gard end:vcard ^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: How pass a "null" as a parameter of anonymous access type 2001-03-23 9:05 ` How pass a "null" as a parameter of anonymous access type Thierry Lelegard @ 2001-03-25 21:33 ` Freddy 2001-03-26 19:17 ` Mark Lundquist 0 siblings, 1 reply; 13+ messages in thread From: Freddy @ 2001-03-25 21:33 UTC (permalink / raw) Thanks. I've tried it, but at runtime I always get a constraint_error (GNAT seems to check the passing of "null" values). ^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: How pass a "null" as a parameter of anonymous access type 2001-03-25 21:33 ` Freddy @ 2001-03-26 19:17 ` Mark Lundquist 2001-03-27 16:13 ` Alfred Hilscher 2001-03-27 16:53 ` Thierry Lelegard 0 siblings, 2 replies; 13+ messages in thread From: Mark Lundquist @ 2001-03-26 19:17 UTC (permalink / raw) Freddy <Alfred.Hilscher.X@t-online.de> wrote in message news:3ABE6443.4119AB52@t-online.de... > Thanks. I've tried it, but at runtime I always get a constraint_error > (GNAT seems to check the passing of "null" values). Yes -- as any correct Ada compiler must do! The value "null" just does not exist for the type of the parameter. Now, you might be able use "pragma Suppress (Access_Check)" to defeat this. But it seems like any Ada binding to C that uses access parameters for things that you are supposed to be able to pass a null value is in error, plain and simple! Why can't you write your own corrected version of the subprogram declaration, write your own "pragma Import (C, ..." for it, and use the corrected version instead of the erroneous one? Then you're not actually "changing" it, just not using it... and instead using something else that is very similar... :-) Mark Lundquist Rational Software ^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: How pass a "null" as a parameter of anonymous access type 2001-03-26 19:17 ` Mark Lundquist @ 2001-03-27 16:13 ` Alfred Hilscher 2001-03-27 16:53 ` Thierry Lelegard 1 sibling, 0 replies; 13+ messages in thread From: Alfred Hilscher @ 2001-03-27 16:13 UTC (permalink / raw) Mark Lundquist wrote: > > Freddy <Alfred.Hilscher.X@t-online.de> wrote in message > news:3ABE6443.4119AB52@t-online.de... > > Thanks. I've tried it, but at runtime I always get a constraint_error > > (GNAT seems to check the passing of "null" values). > > Yes -- as any correct Ada compiler must do! > > The value "null" just does not exist for the type of the parameter. > > Now, you might be able use "pragma Suppress (Access_Check)" to defeat this. Does that prgma supress checks for the entire package or can it switched on/off by statement ? ^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: How pass a "null" as a parameter of anonymous access type 2001-03-26 19:17 ` Mark Lundquist 2001-03-27 16:13 ` Alfred Hilscher @ 2001-03-27 16:53 ` Thierry Lelegard 1 sibling, 0 replies; 13+ messages in thread From: Thierry Lelegard @ 2001-03-27 16:53 UTC (permalink / raw) [-- Attachment #1: Type: text/plain, Size: 1582 bytes --] > Freddy <Alfred.Hilscher.X@t-online.de> wrote in message > news:3ABE6443.4119AB52@t-online.de... > > Thanks. I've tried it, but at runtime I always get a constraint_error > > (GNAT seems to check the passing of "null" values). > > Yes -- as any correct Ada compiler must do! > > The value "null" just does not exist for the type of the parameter. > > Now, you might be able use "pragma Suppress (Access_Check)" to defeat this. I don't agree. I don't use the value "null". I use a variable which pretends to be at address zero. The following example works with GNAT 3.15w (20010305) on Sun Solaris. But, again, this is a hack, unsupported non-standard Ada. $ cat tnull.adb with System; procedure Tnull is Null_Access : aliased Integer; for Null_Access'Address use System.Null_Address; procedure Tnull_C (X : access Integer); pragma Import (C, Tnull_C, "tnull_c"); begin Tnull_C (Null_Access'Access); end Tnull; $ $ cat tnull_c.c #include <stdio.h> void tnull_c (int *x) { printf ("x add = %08X\n", x); } $ $ gcc -c tnull_c.c $ gnatmake tnull -largs tnull_c.o gcc -c tnull.adb gnatbind -x tnull.ali gnatlink tnull_c.o tnull.ali $ tnull x add = 00000000 $ -Thierry ____________________________________________________________________________ Thierry Lelegard, "The Jazzing Troll", Email: thierry.lelegard@canal-plus.fr CANAL+ Technologies, 34 place Raoul Dautry, 75516 Paris Cedex 15, France Tel: +33 1 71 71 54 30 Fax: +33 1 71 71 52 08 Mobile: +33 6 03 00 65 75 ____________________________________________________________________________ [-- Warning: decoded text below may be mangled, UTF-8 assumed --] [-- Attachment #2: Carte pour Thierry Lelegard --] [-- Type: text/x-vcard; charset=us-ascii; name="thierry.lelegard.vcf", Size: 333 bytes --] begin:vcard n:Lel�gard;Thierry tel;cell:+33 6 03 00 65 75 tel;fax:+33 1 71 71 52 08 tel;work:+33 1 71 71 54 30 x-mozilla-html:FALSE url:www.canalplus-technologies.com org:Canal+ Technologies adr:;;34, Place Raoul Dautry;Paris;;75516;France version:2.1 email;internet:thierry.lelegard@canal-plus.fr fn:Thierry Lel�gard end:vcard ^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: How pass a "null" as a parameter of anonymous access type 2001-03-22 20:04 How pass a "null" as a parameter of anonymous access type Freddy 2001-03-22 21:02 ` tmoran 2001-03-23 9:05 ` How pass a "null" as a parameter of anonymous access type Thierry Lelegard @ 2001-03-26 13:44 ` Marc A. Criley 2001-03-26 19:35 ` Mark Lundquist 2 siblings, 1 reply; 13+ messages in thread From: Marc A. Criley @ 2001-03-26 13:44 UTC (permalink / raw) Freddy wrote: > > Hello ! > > I want call a C-binding procedure which is defined as "procedure p (a : > access X; b : access Y);" > Both a or b may be a null pointer, but Ada say "null not allowed for > anonymous access type". > Any idea what to do ? Here's another approach, which worked with JGNAT both at compile-time and run-time: type X_Access is access all X; type Y_Access is access all Y; Null_X : constant X_Access := null; Null_Y : constant Y_Access := null; ... P(Null_X'access, Null_Y'access); Even if this works (which it shouldn't), you should submit a bug report to the providers of the binding stating that the C routine can accept a null value, which their binding does not support. Marc A. Criley Senior Staff Engineer Quadrus Corporation www.quadruscorp.com ^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: How pass a "null" as a parameter of anonymous access type 2001-03-26 13:44 ` Marc A. Criley @ 2001-03-26 19:35 ` Mark Lundquist 2001-03-27 12:59 ` Marc A. Criley 0 siblings, 1 reply; 13+ messages in thread From: Mark Lundquist @ 2001-03-26 19:35 UTC (permalink / raw) Marc A. Criley <mcqada@earthlink.net> wrote in message news:3ABF3A34.D961881E@earthlink.net... > Freddy wrote: > > > > Hello ! > > > > I want call a C-binding procedure which is defined as "procedure p (a : > > access X; b : access Y);" > > Both a or b may be a null pointer, but Ada say "null not allowed for > > anonymous access type". > > Any idea what to do ? > > Here's another approach, which worked with JGNAT both at compile-time > and run-time: > > type X_Access is access all X; > type Y_Access is access all Y; > > Null_X : constant X_Access := null; > Null_Y : constant Y_Access := null; > > ... > > P(Null_X'access, Null_Y'access); Hokey Smokes, Bullwinkle! :-) > > > Even if this works (which it shouldn't), No kidding... :-) > you should submit a bug report > to the providers of the binding And to your Ada vendor... Null_X is not aliased, so Null_X'Access is illegal. Make it aliased, then you can take the 'Access... but then, Null_X'Access should *not* yield a null value (the fact that Null_X itself *has* a null value is irrelevant, the value of Null_X makes no difference). Null_X'Access by definition yields an access value that denotes the object Null_X (and a null value does not denote anything... that's why it's called "null" :-). And even if there is some compiler bug that would cause Null_X'Access to yield a null value, that should cause Constraint_Error to be raised when it's passed to P (it doesn't matter where the null value came from). For that cr@p to compile *and* run would require an incredible conjunction of bugs in the Ada implementation. -- mark ^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: How pass a "null" as a parameter of anonymous access type 2001-03-26 19:35 ` Mark Lundquist @ 2001-03-27 12:59 ` Marc A. Criley 2001-03-27 16:12 ` Alfred Hilscher 0 siblings, 1 reply; 13+ messages in thread From: Marc A. Criley @ 2001-03-27 12:59 UTC (permalink / raw) Mark Lundquist wrote: > <snips> > > Null_X is not aliased, so Null_X'Access is illegal. Mea culpa, I mistyped. Yes, it is not Null_X'Access that was used, merely Null_X. > > Make it aliased, then you can take the 'Access... but then, Null_X'Access > should *not* yield a null value (the fact that Null_X itself *has* a null > value is irrelevant, the value of Null_X makes no difference). > Null_X'Access by definition yields an access value that denotes the object > Null_X (and a null value does not denote anything... that's why it's called > "null" :-). > > And even if there is some compiler bug that would cause Null_X'Access to > yield a null value, that should cause Constraint_Error to be raised when > it's passed to P (it doesn't matter where the null value came from). > Well, not necessarily... I ran into this same problem when using JGNAT and the bindings that product produces for interfacing to the JDK. As I mentioned, the way I got around this was by using a (correctly formed) constant null pointer. That suggestion was made in response to a posting I made in this group about 3 weeks ago. There was some follow-up discussion, and Tucker Taft chimed in with the reason that this approach was allowable with JGNAT: From: Tucker Taft (stt@averstar.com) Subject: Re: JGNAT and Null references Newsgroups: comp.lang.ada Date: 2001-03-07 08:04:05 PST Randy Brukardt wrote: > > Marc A. Criley wrote in message <3AA151BF.C9193700@earthlink.net>... > >Uh...it did work. Cleared up the problem just fine. That it works > >doesn't totally sit well with me, since my purist mental picture of a > >"constant" involves only a value, and not storage. Nonetheless, > > > > Null_Icon : constant Javax.swing.TabbedPanel.ref := null; > > > >was accepted by the AddTab procedure call. > > But does it run? The RM 4.6(49) says that an access parameter cannot be > null, and must raise Constraint_Error. If it does run, you're using a > compiler bug (or "feature"); your code won't be portable... There was discussion of avoiding the null check when interfacing with code from some other language (e.g. C or Java). Given that the rules for making Java-convention calls are not standardized at this point, so long as there is an explicit (or implicit?) Java convention on the routines, JGNAT can do what it wants at this point. > > Randy. -- -Tucker Taft stt@avercom.net http://www.averstar.com/~stt/ ^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: How pass a "null" as a parameter of anonymous access type 2001-03-27 12:59 ` Marc A. Criley @ 2001-03-27 16:12 ` Alfred Hilscher 0 siblings, 0 replies; 13+ messages in thread From: Alfred Hilscher @ 2001-03-27 16:12 UTC (permalink / raw) "Marc A. Criley" wrote: > > Mark Lundquist wrote: > > > <snips> > > > > Null_X is not aliased, so Null_X'Access is illegal. > > Mea culpa, I mistyped. Yes, it is not Null_X'Access that was used, > merely Null_X. I tried this, and GNAT (for Windows) raises CONSTRAINT_ERROR, too. ^ permalink raw reply [flat|nested] 13+ messages in thread
end of thread, other threads:[~2001-03-27 16:53 UTC | newest] Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2001-03-22 20:04 How pass a "null" as a parameter of anonymous access type Freddy 2001-03-22 21:02 ` tmoran 2001-03-25 21:32 ` Freddy 2001-03-26 14:31 ` How pass a Ted Dennison 2001-03-23 9:05 ` How pass a "null" as a parameter of anonymous access type Thierry Lelegard 2001-03-25 21:33 ` Freddy 2001-03-26 19:17 ` Mark Lundquist 2001-03-27 16:13 ` Alfred Hilscher 2001-03-27 16:53 ` Thierry Lelegard 2001-03-26 13:44 ` Marc A. Criley 2001-03-26 19:35 ` Mark Lundquist 2001-03-27 12:59 ` Marc A. Criley 2001-03-27 16:12 ` Alfred Hilscher
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox