Erlang Mailing Lists

Author Message

<  Erlang bugs mailing list  ~  Compile errors in beam/io.c on IRIX

Guest
Posted: Fri Oct 29, 2010 12:50 pm Reply with quote
Guest
Here's another problem I found when compiling beam/io.c for IRIX.
Since The OpenGroup defines the struct iovec::iov_base field to be a
void*, it is illegal to perform pointer arithmetic on it. I'm really
surprised this didn't show up in GCC or any other compiler.

Specifically, I get these errors.

cc-3316 c99: ERROR File = beam/io.c, Line = 3343
The expression must be a pointer to a complete object type.
iov->iov_base += skip;
^

cc-3316 c99: ERROR File = beam/io.c, Line = 3795
The expression must be a pointer to a complete object type.
iov->iov_base += skip;
^

cc-3316 c99: ERROR File = beam/io.c, Line = 3858
The expression must be a pointer to a complete object type.
iov->iov_base += skip;
^

cc-3316 c99: ERROR File = beam/io.c, Line = 3918
The expression must be a pointer to a complete object type.
q->v_head->iov_base += size;

-----
The implied goal here is to increment an address by a certain number
of bytes, so casting to a char* as follows will allow the compile to
succeed:

iov->iov_base = (char*)iov->iov_base + skip;


[I had sent a message a long time ago <sys/uio.h> not being
functional, but I was mistaken. Fortunately, it looks like nobody
implemented what I said, so there isn't anything to revert.]

________________________________________________________________
erlang-bugs (at) erlang.org mailing list.
See http://www.erlang.org/faq.html
To unsubscribe; mailto:erlang-bugs-unsubscribe@erlang.org

Post received from mailinglist
Guest
Posted: Fri Oct 29, 2010 1:22 pm Reply with quote
Guest
On Fri, Oct 29, 2010 at 2:50 PM, Patrick Baggett
<baggett.patrick@gmail.com> wrote:
> Here's another problem I found when compiling beam/io.c for IRIX.
> Since The OpenGroup defines the struct iovec::iov_base field to be a
> void*, it is illegal to perform pointer arithmetic on it. I'm really
> surprised this didn't show up in GCC or any other compiler.

Good catch!

> -----
> The implied goal here is to increment an address by a certain number
> of bytes, so casting to a char* as follows will allow the compile to
> succeed:
>
>            iov->iov_base = (char*)iov->iov_base + skip;
>

This change looks reasonable to me. I might be wrong, but I think this
is what GCC is doing: assuming that void* aritmetic are 1-byte
increments. If not, the code would probably not have worked as
expected. I like the explicit behaviour. If Tuncer Ayaz or one of the
Erlang/OTP devs does not change this into a topic branch, I'd happily
volunteer to make it a topic branch on github.

--
J.

________________________________________________________________
erlang-bugs (at) erlang.org mailing list.
See http://www.erlang.org/faq.html
To unsubscribe; mailto:erlang-bugs-unsubscribe@erlang.org

Post received from mailinglist
Guest
Posted: Fri Oct 29, 2010 1:56 pm Reply with quote
Guest
On Fri, Oct 29, 2010 at 3:21 PM, Jesper Louis Andersen
<jesper.louis.andersen@gmail.com> wrote:
>
> This change looks reasonable to me. I might be wrong, but I think this
> is what GCC is doing: assuming that void* aritmetic are 1-byte
> increments. If not, the code would probably not have worked as
> expected. I like the explicit behaviour. If Tuncer Ayaz or one of the
> Erlang/OTP devs does not change this into a topic branch, I'd happily
> volunteer to make it a topic branch on github.
>

It is a GCC extension, see

http://gcc.gnu.org/onlinedocs/gcc-4.5.1/gcc/Pointer-Arith.html#Pointer-Arith

which really sets the size of the pointer to 1 byte (thus also
enabling the use of sizeof() in the same vein). It can be made into a
warning with -Wpointer-arith if so desired.

Tuncer suggested that I go ahead, so unless you want to do it, ...



--
J.

________________________________________________________________
erlang-bugs (at) erlang.org mailing list.
See http://www.erlang.org/faq.html
To unsubscribe; mailto:erlang-bugs-unsubscribe@erlang.org

Post received from mailinglist

Display posts from previous:  

All times are GMT
Page 1 of 1
This forum is locked: you cannot post, reply to, or edit topics.

Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum