Unix Programming - Best way to fix this build problem

This is Interesting: Free IT Magazines  
Home > Archive > Unix Programming > April 2004 > Best way to fix this build problem





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Best way to fix this build problem
Andrew Falanga

2004-04-27, 10:34 pm

Ok everybody, here's what I've got. I'm trying to get xfm (X file
manager) compiled for use with my OpenBSD machine. If you're not
familiar with it, it a freely available file manager program that I
stumbled across while reading the fvwm web site. (I'm using fvwm
because I've only got 8bit color depth on this sparc.)

Anyway, the program seems to be "old". The copy I managed to get a hold
of (the latest too by the way) was last modified in 2000. The make
program bombs while compliling on the inability to find the alloca.h
file. This file does not exist in OpenBSD 3.4.

However, due to chance (I was compiling PostgreSQL at the time) I found
that OpenBSD does support the memory allocation function that this
program is looking for, alloca(). However, in OBSD 3.4 the function is
defined in stdlib.h vs. alloca.h.

So, now the question, would it be better to

1) Find the #include's in the source code, and change them from #include
<alloca.h> to #include <stdlib.h> (which this file is probably already
included)?

2) Wade through the source code and change all instances of alloca() to
malloc() adding a corresponding free() statement as well?

3) Make a symbolic link in /usr/include named alloca.h and point it to
stdlib.h?


If choice 2 is desirable, I want to make sure I understand alloca's
workings. The manual page says it allocates memory in the address space
of the caller which is automatically deallocated when the caller exits.
Is my understanding correct?

If I've not thought of the optimum solution, someone please inform me.

Andy

-----------
A common mistake that people make when trying to design something
completely foolproof is to underestimate the ingenuity of complete
fools. -Douglas Adams


-----= Posted via mcse.ms, Uncensored Usenet News =-----
http://www.mcse.ms - The #1 Newsgroup Service in the World!
-----== Over 100,000 Newsgroups - 19 Different Servers! =-----
Jens.Toerring@physik.fu-berlin.de

2004-04-28, 5:34 am

Andrew Falanga <andy@spam.me.not> wrote:
> Ok everybody, here's what I've got. I'm trying to get xfm (X file
> manager) compiled for use with my OpenBSD machine. If you're not
> familiar with it, it a freely available file manager program that I
> stumbled across while reading the fvwm web site. (I'm using fvwm
> because I've only got 8bit color depth on this sparc.)


> Anyway, the program seems to be "old". The copy I managed to get a hold
> of (the latest too by the way) was last modified in 2000. The make
> program bombs while compliling on the inability to find the alloca.h
> file. This file does not exist in OpenBSD 3.4.


> However, due to chance (I was compiling PostgreSQL at the time) I found
> that OpenBSD does support the memory allocation function that this
> program is looking for, alloca(). However, in OBSD 3.4 the function is
> defined in stdlib.h vs. alloca.h.


> So, now the question, would it be better to


> 1) Find the #include's in the source code, and change them from #include
> <alloca.h> to #include <stdlib.h> (which this file is probably already
> included)?


> 2) Wade through the source code and change all instances of alloca() to
> malloc() adding a corresponding free() statement as well?


> 3) Make a symbolic link in /usr/include named alloca.h and point it to
> stdlib.h?


Depends on how lazy you are;-) Choice 3 is the the easiest way because
it just needs a single command. 1 takes a bit longer but shouldn't take
too much time. But if you want to make it easier for other people to
also use the program in the future under OpenBSD it probably would be
good if you would not simply delete and replace the <alloca.h> includes
but put an "#ifndef" around them, so they only get skipped (or replaced
by <stdlib.h> ) for OpenBSD 3.4 and will still be seen on other systems.
Then you can send back your improved version to the original authors.
Choice 2 will take the longest and might introduce new bugs unless you
know exactly what you're doing.On the other hand, there are systems which
don't have an alloca() at all, so if you pick choice 2 it you might also
help people using such systems by making the program more portable.

> If choice 2 is desirable, I want to make sure I understand alloca's
> workings. The manual page says it allocates memory in the address space
> of the caller which is automatically deallocated when the caller exits.
> Is my understanding correct?


I think that's not the whole picture - the memory allocated by alloca()
gets deallocated automatically at the end of the function it was called
in, not only when the program exits. Here's a bit from the glibc
info pages:

- Function: void * alloca (size_t SIZE);
The return value of `alloca' is the address of a block of SIZE
bytes of memory, allocated in the stack frame of the calling
function.

Since the stack frame vanishes when the function is left the memory
you allocated via alloca() also disappears at that moment.

Regards, Jens
--
\ Jens Thoms Toerring ___ Jens.Toerring@physik.fu-berlin.de
\__________________________ http://www.toerring.de
Fred L. Kleinschmidt

2004-04-28, 12:34 pm



Andrew Falanga wrote:
>
> Ok everybody, here's what I've got. I'm trying to get xfm (X file
> manager) compiled for use with my OpenBSD machine. If you're not
> familiar with it, it a freely available file manager program that I
> stumbled across while reading the fvwm web site. (I'm using fvwm
> because I've only got 8bit color depth on this sparc.)
>
> Anyway, the program seems to be "old". The copy I managed to get a hold
> of (the latest too by the way) was last modified in 2000. The make
> program bombs while compliling on the inability to find the alloca.h
> file. This file does not exist in OpenBSD 3.4.
>
> However, due to chance (I was compiling PostgreSQL at the time) I found
> that OpenBSD does support the memory allocation function that this
> program is looking for, alloca(). However, in OBSD 3.4 the function is
> defined in stdlib.h vs. alloca.h.
>
> So, now the question, would it be better to
>
> 1) Find the #include's in the source code, and change them from #include
> <alloca.h> to #include <stdlib.h> (which this file is probably already
> included)?
>
> 2) Wade through the source code and change all instances of alloca() to
> malloc() adding a corresponding free() statement as well?
>
> 3) Make a symbolic link in /usr/include named alloca.h and point it to
> stdlib.h?
>
> If choice 2 is desirable, I want to make sure I understand alloca's
> workings. The manual page says it allocates memory in the address space
> of the caller which is automatically deallocated when the caller exits.
> Is my understanding correct?
>
> If I've not thought of the optimum solution, someone please inform me.
>
> Andy
>
> -----------
> A common mistake that people make when trying to design something
> completely foolproof is to underestimate the ingenuity of complete
> fools. -Douglas Adams
>
> -----= Posted via mcse.ms, Uncensored Usenet News =-----
> http://www.mcse.ms - The #1 Newsgroup Service in the World!
> -----== Over 100,000 Newsgroups - 19 Different Servers! =-----


An even better solution is modify the source code and get rid of the
usage of alloca().
From the alloca man page:
The implementation of this routine is system
dependent and its use is discouraged.

--
Fred L. Kleinschmidt
Boeing Associate Technical Fellow
Technical Architect, Common User Interface Services
M/S 2R-94 (206)544-5225
Allin Cottrell

2004-04-30, 1:35 pm

Andrew Falanga wrote:
> Ok everybody, here's what I've got. I'm trying to get xfm (X file
> manager) compiled for use with my OpenBSD machine. If you're not
> familiar with it, it a freely available file manager program that I
> stumbled across while reading the fvwm web site. (I'm using fvwm
> because I've only got 8bit color depth on this sparc.)
>
> Anyway, the program seems to be "old". The copy I managed to get a hold
> of (the latest too by the way) was last modified in 2000. The make
> program bombs while compliling on the inability to find the alloca.h
> file. This file does not exist in OpenBSD 3.4.
>
> However, due to chance (I was compiling PostgreSQL at the time) I found
> that OpenBSD does support the memory allocation function that this
> program is looking for, alloca(). However, in OBSD 3.4 the function is
> defined in stdlib.h vs. alloca.h.
>
> So, now the question, would it be better to
>
> 1) Find the #include's in the source code, and change them from #include
> <alloca.h> to #include <stdlib.h> (which this file is probably already
> included)?
>
> 2) Wade through the source code and change all instances of alloca() to
> malloc() adding a corresponding free() statement as well?
>
> 3) Make a symbolic link in /usr/include named alloca.h and point it to
> stdlib.h?
>
>
> If choice 2 is desirable, I want to make sure I understand alloca's
> workings. The manual page says it allocates memory in the address space
> of the caller which is automatically deallocated when the caller exits.
> Is my understanding correct?


I'd say that 2) is the Right Thing to do, producing portable code as a
result. I think you have the interpretation of alloca() right. My
(Linux) man page says:

The alloca function allocates size bytes of space in the
stack frame of the caller. This temporary space is auto-
matically freed on return.

Note, "on return" is more precise than "when the caller exits":
functions return, programs exit.

Allin Cottrell
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com