H2pas tool vs others, C header translation

classic Classic list List threaded Threaded
40 messages Options
12
Reply | Threaded
Open this post in threaded view
|

H2pas tool vs others, C header translation

noreply
Forgive me, I have forgotten, this may have been discussed before..

Is h2pas the latest tool to convert C headers to pas files?

Is there a competing tool that does more, or is updated more?

I remember Bob Swart AFAIR had a popular tool for delphi.

And some people use multiple tools if one tool is giving them issues.

Is h2pas for example the one that is used for Mysql header translations
and other major C headers?

I am looking to convert the GNU MPFR library header files, or hire
someone on a bounty to do it if header translation is not so easy with
h2pas and requires lots of hand work, and close checking.

The issue I see with header translation is there is no way to prove that
the header translation is 100 percent correct, as the compiler will not
tell you if it found an issue, it will just link the DLL as you stated
to link it. Too bad DLL/DSO libraries could not export some sort of
correctness or type verification when you link against the library.
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: H2pas tool vs others, C header translation

Graeme Geldenhuys-6
On 2017-08-20 22:37, [hidden email] wrote:
> Is there a competing tool that does more, or is updated more?

Recently somebody told me about the following project...

   https://github.com/DrDiettrich/CtoPas/

It's specific to Delphi I think. I haven't tried it or looked at the
code, so can't say how easy or not it will be to port to say FPC.

Regards,
   Graeme

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: H2pas tool vs others, C header translation

Michael Van Canneyt
In reply to this post by noreply


On Sun, 20 Aug 2017, [hidden email] wrote:

> Forgive me, I have forgotten, this may have been discussed before..
>
> Is h2pas the latest tool to convert C headers to pas files?

For FPC, yes.

>
> Is there a competing tool that does more, or is updated more?
>
> I remember Bob Swart AFAIR had a popular tool for delphi.
>
> And some people use multiple tools if one tool is giving them issues.
>
> Is h2pas for example the one that is used for Mysql header translations
> and other major C headers?

Yes.

>
> I am looking to convert the GNU MPFR library header files, or hire
> someone on a bounty to do it if header translation is not so easy with
> h2pas and requires lots of hand work, and close checking.

I do all header translations with h2pas. Most of the time, I run the code
first through gcc -E, which will take care of all macro magic. Usually h2pas
has little trouble with the result.

Michael.
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: H2pas tool vs others, C header translation

Marco van de Voort
In our previous episode, Michael Van Canneyt said:
> > I am looking to convert the GNU MPFR library header files, or hire
> > someone on a bounty to do it if header translation is not so easy with
> > h2pas and requires lots of hand work, and close checking.
>
> I do all header translations with h2pas. Most of the time, I run the code
> first through gcc -E, which will take care of all macro magic. Usually h2pas
> has little trouble with the result.

Before everything I do a couple of substs with an editor, then instead of
gcc -E I use small pascal filterprograms to sort the symbols based on
heuristics.  Usually "clean" defines, structs, function calls and "rest".

The clear files I translate by h2pas, the rest manually or with pascal
programs, and then I stitch them together again. I try to preserve comments
as much as possible.

In the past, with very large headers, I did this restitching
semiautomatically, by inserting marker comments while splitting.

I tried all other headerconvertors, and didn't have a better result.
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: H2pas tool vs others, C header translation

dmitry boyarintsev
In reply to this post by noreply
On Sun, Aug 20, 2017 at 5:37 PM, <[hidden email]> wrote:
Is h2pas for example the one that is used for Mysql header translations and other major C headers?

I'm using Chelper.  (http://wiki.freepascal.org/Chelper)
It's my choice, because it preserves comments (which is usually an important part of open-source libs)
plus, can be configured to handle library header-specific defines.
Naturally, the process is semi-automatic, but get be done quite quickly.
 
I am looking to convert the GNU MPFR library header files, or hire someone on a bounty to do it if header translation is not so easy with h2pas and requires lots of hand work, and close checking.

Speaking of bounties.
There was a bounty (http://wiki.freepascal.org/Bounties#Linux_bounties) for converting libwebsockets to fpc.
I took it and did the conversion using Chelper.

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: H2pas tool vs others, C header translation

dmitry boyarintsev
In reply to this post by noreply


On Sun, Aug 20, 2017 at 5:37 PM, <[hidden email]> wrote:

Is there a competing tool that does more, or is updated more?

How about this list?

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: H2pas tool vs others, C header translation

noreply
On 2017-08-21 20:34, Dmitry Boyarintsev wrote:
> On Sun, Aug 20, 2017 at 5:37 PM, <[hidden email]> wrote:
>
>> Is there a competing tool that does more, or is updated more?
>
> How about this list?
> http://wiki.freepascal.org/C_to_Pascal

That's a good one, I missed that.. could not find it previously when
searching google

Did you write CHelper because H2pas was not to your satisfaction?
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: H2pas tool vs others, C header translation

Marco van de Voort
In reply to this post by dmitry boyarintsev
In our previous episode, Dmitry Boyarintsev said:
>
> I'm using Chelper.  (http://wiki.freepascal.org/Chelper)
> It's my choice, because it preserves comments (which is usually an
> important part of open-source libs)
> plus, can be configured to handle library header-specific defines.
> Naturally, the process is semi-automatic, but get be done quite quickly.

Note that to convert C (as in source code, not headers), I did use other
tools in the past. Can't remember which though.
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: H2pas tool vs others, C header translation

noreply
In reply to this post by Marco van de Voort
On 2017-08-21 13:08, [hidden email] wrote:

> In our previous episode, Michael Van Canneyt said:
>> > I am looking to convert the GNU MPFR library header files, or hire
>> > someone on a bounty to do it if header translation is not so easy with
>> > h2pas and requires lots of hand work, and close checking.
>>
>> I do all header translations with h2pas. Most of the time, I run the
>> code
>> first through gcc -E, which will take care of all macro magic. Usually
>> h2pas
>> has little trouble with the result.
>
> Before everything I do a couple of substs with an editor,


What do you mean by substs..

Search/replace, (substitutions? regex?)

> gcc -E I use small pascal filterprograms to sort the symbols based on
> heuristics.  Usually "clean" defines, structs, function calls and
> "rest".

A custom filter program for each case by case basis, or one major filter
program you wrote for all header files?

Thanks for the tips.
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: H2pas tool vs others, C header translation

noreply
In reply to this post by Marco van de Voort
On 2017-08-22 04:04, [hidden email] wrote:

> In our previous episode, Dmitry Boyarintsev said:
>>
>> I'm using Chelper.  (http://wiki.freepascal.org/Chelper)
>> It's my choice, because it preserves comments (which is usually an
>> important part of open-source libs)
>> plus, can be configured to handle library header-specific defines.
>> Naturally, the process is semi-automatic, but get be done quite
>> quickly.
>
> Note that to convert C (as in source code, not headers), I did use
> other
> tools in the past. Can't remember which though.


I did mean headers, not C source... But C source is also interesting to
convert of course
I wonder if the Quake to Delphi and Doom To Delphi folks wrote tools for
conversion, or used existing ones to do the bulk of the work.  If
superman was involved, they likely did it by hand 100 percent the hard
way, but if they are A.I. then they have no hands, likely.
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: H2pas tool vs others, C header translation

Martok
In reply to this post by noreply
If your header looks enough like IDL (which is essentially C++ with
annotations), you may also be able to use one of the available IDL compilers.
There are a few dialect issues though, so YMMV. I'd say MPFR has a few defines
too many for my idlproc (https://github.com/martok/idlproc), but may come closer
for others.

As a heads-up: whatever tool you end up using, make sure you do NOT translate
the C enums in mpfr.h as enumerations. It will work, but create unpredictable
codegen on the FPC side. Use plain constants.

--
Martok

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: H2pas tool vs others, C header translation

LacaK
In reply to this post by Marco van de Voort

>> I'm using Chelper.  (http://wiki.freepascal.org/Chelper)
>> It's my choice, because it preserves comments (which is usually an
>> important part of open-source libs)
>> plus, can be configured to handle library header-specific defines.
>> Naturally, the process is semi-automatic, but get be done quite quickly.
> Note that to convert C (as in source code, not headers), I did use other
> tools in the past. Can't remember which though.
I have used many times C2Pas32 (for translation C source files not only
headers) ... it gives good results for me, but some parts I must edit
manually of course ...
-Laco.

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: H2pas tool vs others, C header translation

Florian Klämpfl
In reply to this post by Martok
Am 22.08.2017 um 15:59 schrieb Martok:
> If your header looks enough like IDL (which is essentially C++ with
> annotations), you may also be able to use one of the available IDL compilers.
> There are a few dialect issues though, so YMMV. I'd say MPFR has a few defines
> too many for my idlproc (https://github.com/martok/idlproc), but may come closer
> for others.
>
> As a heads-up: whatever tool you end up using, make sure you do NOT translate
> the C enums in mpfr.h as enumerations. It will work, but create unpredictable
> codegen on the FPC side.

It is perfectly predictable. Just do not store invalid values in enumeration variables. And invalid
is everything not being declared. This is how FPC works and will work.
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: H2pas tool vs others, C header translation

Martok
> It is perfectly predictable. Just do not store invalid values in enumeration variables. And invalid
> is everything not being declared. This is how FPC works and will work.
Aye. The point being, if the store operation is in a library (a getter, such as
mpfr_get_default_rounding_mode), there is just no way of absolutely enforcing
that - so the FPC side must be defensive. As you say, enums already contain
typing assumptions and are not meant to be defensive, so they can't be used
here. That's all I wanted to point out.

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: H2pas tool vs others, C header translation

dmitry boyarintsev
In reply to this post by Florian Klämpfl
On Wed, Aug 23, 2017 at 3:50 AM, Florian Klämpfl <[hidden email]> wrote:
Am 22.08.2017 um 15:59 schrieb Martok:
> As a heads-up: whatever tool you end up using, make sure you do NOT translate
> the C enums in mpfr.h as enumerations. It will work, but create unpredictable
> codegen on the FPC side.

It is perfectly predictable. Just do not store invalid values in enumeration variables. And invalid
is everything not being declared. This is how FPC works and will work.

Never saw FPC acting unpredictably.
(There was an issue back in the days with Delphi. But it's only because delphi packs enumerations to 1 byte, where FPC packs them to 4 bytes in objfpc mode)

Instead, I saw C-enumarations used as non-Pascal-enumerations. (which is actually expected C<>Pascal).

For instance, it's common for C enumerations to be used used in bitwise operations.
ENUM1 | ENUM2 
not available in Pascal, unless an explicit type casting or sets are used.

So, in the end it's better to declare enumeration type elements as constant
and the type itself as an alias to integer (or cint)

thanks,
Dmitry

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: H2pas tool vs others, C header translation

noreply
In reply to this post by Martok
What about the BOOL issue..

We know that Boolean in fpc/delphi is not compatible with a C bool

But it gets worse than that: even fpc/delphi's bool is not always
compatible (but is sometimes).

For example:
http://blog.delphi-jedi.net/2008/09/25/bool-boolean-and-integer/

When one must use Integers to do boolean related programming tasks, it
makes me want to quit programming ;)

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: H2pas tool vs others, C header translation

Free Pascal - General mailing list

Am 26.08.2017 07:25 schrieb <[hidden email]>:
>
> What about the BOOL issue..
>
> We know that Boolean in fpc/delphi is not compatible with a C bool
>
> But it gets worse than that: even fpc/delphi's bool is not always compatible (but is sometimes).
>
> For example:
> http://blog.delphi-jedi.net/2008/09/25/bool-boolean-and-integer/
>
> When one must use Integers to do boolean related programming tasks, it makes me want to quit programming ;)
>

In FPC you can use the types Boolean16, Boolean32 and Boolean64 to get a type that behaves like Boolean, but has a different size.

Regards,
Sven


_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: H2pas tool vs others, C header translation

Michael Van Canneyt


On Sat, 26 Aug 2017, Sven Barth via fpc-pascal wrote:

> Am 26.08.2017 07:25 schrieb <[hidden email]>:
>>
>> What about the BOOL issue..
>>
>> We know that Boolean in fpc/delphi is not compatible with a C bool
>>
>> But it gets worse than that: even fpc/delphi's bool is not always
> compatible (but is sometimes).
>>
>> For example:
>> http://blog.delphi-jedi.net/2008/09/25/bool-boolean-and-integer/
>>
>> When one must use Integers to do boolean related programming tasks, it
> makes me want to quit programming ;)
>>
>
> In FPC you can use the types Boolean16, Boolean32 and Boolean64 to get a
> type that behaves like Boolean, but has a different size.

Sorry for being naive. Why not simply use a boolean ?

I thought all this BOOL mess was just meant to be able to interface with C
libs slightly easier.

Instead of

If (SomeCfunction()<>0) then
   DoSomethingStupid;

it allows you to write - in appropriate cases - the following:

if (SomeCfunction()) then
   DoSomethingStupid;

I don't think we should promote BOOL and friends too much.
They are a convenience (which IMHO should not have been introduced in the first place).

Promoting them to first-class Pascal citizens is IMHO a bad idea.

Michael.
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: H2pas tool vs others, C header translation

Free Pascal - General mailing list

Am 26.08.2017 09:50 schrieb "Michael Van Canneyt" <[hidden email]>:
>
>
>
> On Sat, 26 Aug 2017, Sven Barth via fpc-pascal wrote:
>
>> Am 26.08.2017 07:25 schrieb <[hidden email]>:
>>>
>>>
>>> What about the BOOL issue..
>>>
>>> We know that Boolean in fpc/delphi is not compatible with a C bool
>>>
>>> But it gets worse than that: even fpc/delphi's bool is not always
>>
>> compatible (but is sometimes).
>>>
>>>
>>> For example:
>>> http://blog.delphi-jedi.net/2008/09/25/bool-boolean-and-integer/
>>>
>>> When one must use Integers to do boolean related programming tasks, it
>>
>> makes me want to quit programming ;)
>>>
>>>
>>
>> In FPC you can use the types Boolean16, Boolean32 and Boolean64 to get a
>> type that behaves like Boolean, but has a different size.
>
>
> Sorry for being naive. Why not simply use a boolean ?
>
> I thought all this BOOL mess was just meant to be able to interface with C
> libs slightly easier.
>
> Instead of
>
> If (SomeCfunction()<>0) then
>   DoSomethingStupid;
>
> it allows you to write - in appropriate cases - the following:
>
> if (SomeCfunction()) then
>   DoSomethingStupid;
>
> I don't think we should promote BOOL and friends too much. They are a convenience (which IMHO should not have been introduced in the first place).
>
> Promoting them to first-class Pascal citizens is IMHO a bad idea.

Did you read the article that had been linked? That's an important point that is raised in there.
These types as well as the Byte-, Word-, Long- and QWordBool types are mainly for interfacing with C-based interfaces, either on Windows or *nix and there they should definitely be used so that a Pascal user of them can simply use True and False and does not need to worry about the details (but of course the correct type needs to be used as the article shows).

Regards,
Sven


_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: H2pas tool vs others, C header translation

Michael Van Canneyt


On Sat, 26 Aug 2017, Sven Barth wrote:

>>
>> Sorry for being naive. Why not simply use a boolean ?
>>
>> I thought all this BOOL mess was just meant to be able to interface with C
>> libs slightly easier.
>>
>> Instead of
>>
>> If (SomeCfunction()<>0) then
>>   DoSomethingStupid;
>>
>> it allows you to write - in appropriate cases - the following:
>>
>> if (SomeCfunction()) then
>>   DoSomethingStupid;
>>
>> I don't think we should promote BOOL and friends too much. They are a
> convenience (which IMHO should not have been introduced in the first place).
>>
>> Promoting them to first-class Pascal citizens is IMHO a bad idea.
>
> Did you read the article that had been linked? That's an important point
> that is raised in there.

I did read it.

I think the programmer *must* worry about the details and must definitely
NOT use the booleans for anything C related. That was my point.

Attempting to cater for C code using BOOL or whatever type is misplaced.
C does not have a boolean type.

The standard says for "if" :

"In both forms, the first substatement is executed if the expression compares unequal to 0."

Treat it as such.

Michael.
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
12