dstep
dstep copied to clipboard
_IOR and _IOW issues, or something else…
I spotted that there had been a change to _IOR ans _IOW processing so I thought I'd try running dstep on the libdvbv5 library again. I compiled dstep from master resulting in:
|> dstep --version
v0.2.3-9-g50919b6
and ran it over the C files. There were no errors, and the D files looked fine at first sight. However when I compiled I got a parsing error. The first one is on the line:
enum FE_READ_BER = _IOR('o', 70, uint);
which results in:
../../Repositories/Git/Masters/Libdvbv5_D/source/libdvbv5/dvb_frontend.d(655): Error: found `)` when expecting `.` following uint
../../Repositories/Git/Masters/Libdvbv5_D/source/libdvbv5/dvb_frontend.d(655): Error: found `;` when expecting identifier following `uint`.
``
Hmm, it should have been translated to _IOR!uint('o', 70)
. I'll take a look when I have some spare time.
Actually, can you share the full dstep invocation that you've used for translation.
I changed uint
to __u32
and ushort
to __u16
and no parse error.
I use the following shell script:
#!/bin/sh
location=source/libdvbv5
mkdir -p $location
rm -rf $location/*
paths=$(ls -1 /usr/include/libdvbv5/*.h)
for p in $paths
do
dstep -o $location/$(basename $p .h | sed 's/-/_/g').d $p
done
I also get:
ldc2 -I=source/libdvbv5 -I=source/linux -I=source/linux_dvb -O -release -c -relocation-model=pic -of=Build/Release/source/libdvbv5/dvb_frontend.o source/libdvbv5/dvb_frontend.d
source/libdvbv5/dvb_frontend.d(631): Error: undefined identifier `_IOW`
source/libdvbv5/dvb_frontend.d(632): Error: undefined identifier `_IOR`
source/libdvbv5/dvb_frontend.d(643): Error: undefined identifier `_IOR`
source/libdvbv5/dvb_frontend.d(645): Error: undefined identifier `_IO`
source/libdvbv5/dvb_frontend.d(646): Error: undefined identifier `_IOW`
source/libdvbv5/dvb_frontend.d(647): Error: undefined identifier `_IOR`
source/libdvbv5/dvb_frontend.d(648): Error: undefined identifier `_IO`
source/libdvbv5/dvb_frontend.d(650): Error: undefined identifier `_IO`
source/libdvbv5/dvb_frontend.d(651): Error: undefined identifier `_IO`
source/libdvbv5/dvb_frontend.d(652): Error: undefined identifier `_IO`
source/libdvbv5/dvb_frontend.d(654): Error: undefined identifier `_IOR`
source/libdvbv5/dvb_frontend.d(655): Error: undefined identifier `_IOR`
source/libdvbv5/dvb_frontend.d(656): Error: undefined identifier `_IOR`
source/libdvbv5/dvb_frontend.d(657): Error: undefined identifier `_IOR`
source/libdvbv5/dvb_frontend.d(658): Error: undefined identifier `_IOR`
source/libdvbv5/dvb_frontend.d(660): Error: undefined identifier `_IOW`
source/libdvbv5/dvb_frontend.d(661): Error: undefined identifier `_IOR`
source/libdvbv5/dvb_frontend.d(662): Error: undefined identifier `_IO`
source/libdvbv5/dvb_frontend.d(663): Error: undefined identifier `_IOR`
source/libdvbv5/dvb_frontend.d(665): Error: undefined identifier `_IO`
which I have to admit surprised me. I suspect I am missing something.
Yes, this is surprising. Maybe _IOR and _IOW's are build-in in the gcc in linux and corresponding headers aren't explicitly included? (I remember there was something strange with regard to this but I haven't worked on it for a rew months so I don't know precisely what)
Ah, it's on D-side. If you have some time you can try to temporarily include the ioctl header.
You can try to import https://github.com/dlang/druntime/blob/master/src/core/sys/posix/sys/ioctl.d in D code as well but without hints from the header dstep will not be able to guess the correct signature for _IO* functions...
Importing ioctl.d got things moving.
I had to manually add a collection of other imports but I now have a build.
I had to change all the _IOx to _IOx!… to remove the third argument where it was. Also there are a number of cross module references that had to have imports done manually.
I had to change all the _IOx to _IOx!… to remove the third argument where it was. Also there are a number of cross module references that had to have imports done manually.
The <sys/ioctl.h>
header isn't included in dvb-frontent.h
, that's why dstep doesn't see the declaration of _IOx
macros. After I added #include <sys/ioctl.h>
to dvb-frontent.h
it starts to correctly translate the functions.
We need to find some solution for this. Maybe analyze all passed files for macro definitions, the C preprocessor is too forgiving : (
I guess the question has to be how does C ever compile it.
If we get very confident that the #include is definitely missing, I will create a pull request to the V4L_Utils project, which is where the libdvbv5 code is hosted.
@russel it is a very common issue I have with C projects when trying dstep. Many (probably too many) C libraries rely on order of includes:
// this is header3.h
#include "header1.h" // defines ABC
#include "header2.h" // uses ABC
With such projects it is pretty much impossible to reproduce header structure as D modules - header2
only ever works if you include header1
before it in specific translation unit.
@mihails-strasuns-sociomantic Indeed. The whole C #include thing was sort of fine in 1979, but we have moved on since. :-) I am gearing up to tackling creating a pull request for Mauro whose library libdvbv5 effectively is.
@russel please have a look at the bottom of the readme in the Limitations/Known issues section, the last point.