From: Mark Wilson <markwilson@wilsonnet.technology>
Subject: Re: Odd Behaviour
Date: Tue, 18 Jan 2022 04:27:56 -0800 (PST) [thread overview]
Message-ID: <2306ce86-b1da-4448-a77a-9be0f5cec9f6n@googlegroups.com> (raw)
In-Reply-To: <13fa1a0d-eeed-4f44-a1ec-cace658fec0dn@googlegroups.com>
On Tuesday, January 18, 2022 at 12:18:56 PM UTC, Mark Wilson wrote:
> On Tuesday, January 18, 2022 at 12:08:16 PM UTC, Mark Wilson wrote:
> > On Tuesday, January 18, 2022 at 11:51:36 AM UTC, Mark Wilson wrote:
> > > On Tuesday, January 18, 2022 at 11:48:23 AM UTC, Jeffrey R.Carter wrote:
> > > > On 2022-01-18 12:05, Mark Wilson wrote:
> > > > >
> > > > > then an error is raised: 'warning: Valued_Procedure has no effect for convention Ada [enabled by default]'
> > > > The GNAT RM says of pragma Import_Valued_Procedure
> > > >
> > > > "Note that it is important to use this pragma in conjunction with a separate
> > > > pragma Import that specifies the desired convention, since otherwise the default
> > > > convention is Ada, which is almost certainly not what is required."
> > > >
> > > > What happens if you replace the import aspects with pragma Import?
> > > > --
> > > > Jeff Carter
> > > > "Monsieur Arthur King, who has the brain of a duck, you know."
> > > > Monty Python & the Holy Grail
> > > > 09
> > > Tried pragma Import, and even pragma Convention, so, for instance,
> > > procedure SQLAllocHandle
> > > (Result : out SQLRETURN;
> > > HandleType : in SQL_HANDLE_TYPE;
> > > InputHandle : in SQLHANDLE;
> > > OutputHandlePtr : in out SQLHANDLE)
> > > with
> > > Pre => (Handletype = SQL_Handle_Env);
> > >
> > > pragma Import (C, SQLAllocHandle, "SQLAllocHandle");
> > > pragma Import_Valued_Procedure (SQLAllocHandle);
> > >
> > > Fails with the same warning. Take the 'pre' out and it works fine.
> > Even tried (which to be fair is a bit of a long shot),
> > procedure SQLAllocHandle
> > (Result : out SQLRETURN;
> > HandleType : in SQL_HANDLE_TYPE;
> > InputHandle : in SQLHANDLE;
> > OutputHandlePtr : in out SQLHANDLE);
> > -- with
> > -- Pre => (Handletype = SQL_Handle_Env);
> >
> >
> > pragma Import (C, SQLAllocHandle);
> > pragma Import_Valued_Procedure
> > (SQLAllocHandle, "SQLAllocHandle",
> > (SQLRETURN, SQL_HANDLE_TYPE, SQLHANDLE, SQLHANDLE),
> > (Reference, Value, Value, Reference));
> >
> > Do you think I should file a bug report?
> Well, this works - but feels very naughty,
>
> function SQLAllocHandle
> (HandleType : in SQL_HANDLE_TYPE;
> InputHandle : in SQLHANDLE;
> OutputHandlePtr : in SQLHANDLE)
> return SQLRETURN;
> -- with
> -- Pre => (Handletype = SQL_Handle_Env);
>
> pragma Import (C, SQLAllocHandle);
> pragma Import_Function
> (SQLAllocHandle, "SQLAllocHandle",
> (SQL_HANDLE_TYPE, SQLHANDLE, SQLHANDLE), SQLRETURN,
> (Value, Value, Reference));
>
> However, adding the precondition in results in '<artificial>:(.text+0xb7): undefined reference to `sqlallochandle'''
This works!
function SQLAllocHandle
(HandleType : in SQL_HANDLE_TYPE;
InputHandle : in SQLHANDLE;
OutputHandlePtr : in SQLHANDLE)
return SQLRETURN
with
Pre => (Handletype = SQL_Handle_Env);
pragma Import (C, SQLAllocHandle, "SQLAllocHandle");
pragma Import_Function
(SQLAllocHandle, "SQLAllocHandle",
(SQL_HANDLE_TYPE, SQLHANDLE, SQLHANDLE), SQLRETURN,
(Value, Value, Reference));
(so specified the external function name in the Import as well as the Import_Function)
Even the writing to an 'in' parameter worked,
Result := SQLAllocHandle
(HandleType => SQL_HANDLE_ENV,
InputHandle => SQL_NULL_HANDLE,
OutputHandlePtr => SQLHANDLE (Handle));
Put_Line (SQLRETURN'Image (Result));
Put_Line (Boolean'Image (SQLHANDLE(Handle) /= SQL_NULL_HANDLE));
The first Put_Line returns SQL_SUCCESS, and the second returns TRUE
Ugly as hell, though. Spark complains,
odbc.ads:100:04: warning: pragma "IMPORT_FUNCTION" ignored (not yet supported)
odbc.ads:139:04: warning: pragma "IMPORT_VALUED_PROCEDURE" ignored (not yet supported),
and there's the horrible Ada warning that,
main.adb:10:04: warning: variable "Handle" is read but never assigned [-gnatwv]
I think it is going to be much cleaner (and clearer) to abstract this away to an Ada body.
next prev parent reply other threads:[~2022-01-18 12:27 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-01-18 11:05 Odd Behaviour Mark Wilson
2022-01-18 11:16 ` Marius Amado-Alves
2022-01-18 11:21 ` Mark Wilson
2022-01-18 11:24 ` Mark Wilson
2022-01-18 11:28 ` Jeffrey R.Carter
2022-01-18 11:35 ` Mark Wilson
2022-01-18 11:48 ` Jeffrey R.Carter
2022-01-18 11:51 ` Mark Wilson
2022-01-18 12:08 ` Mark Wilson
2022-01-18 12:18 ` Mark Wilson
2022-01-18 12:27 ` Mark Wilson [this message]
2022-01-18 13:50 ` Mark Wilson
2022-01-18 12:25 ` Jeffrey R.Carter
2022-01-18 12:30 ` Mark Wilson
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox