9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
* [9fans] making emalloc a library function
@ 2004-03-07 11:32 Einar Karttunen
  2004-03-07 12:56 ` David Presotto
                   ` (2 more replies)
  0 siblings, 3 replies; 14+ messages in thread
From: Einar Karttunen @ 2004-03-07 11:32 UTC (permalink / raw)
  To: Plan9 ML

Hello

Quite many programs define emalloc, which does the same thing. I was
thinking of ripping these out and replacing with a library.

I have two alternative routes. Either make libemalloc which contains
emalloc, estrdup and so on or add a flag which makes libc malloc behave
like emalloc. 

The first way would give programs freedom, but library code would still
use raw malloc instead of the emalloc. The second solution would be
harder for programs wishing to use both emalloc and malloc (of course
this would be still possible), but it would be more general... 
The changes would break no existing code in either case. 
Should I go forward with either idea?

- Einar Karttunen


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [9fans] making emalloc a library function
  2004-03-07 11:32 [9fans] making emalloc a library function Einar Karttunen
@ 2004-03-07 12:56 ` David Presotto
  2004-03-07 15:37 ` andrey mirtchovski
  2004-03-08 10:25 ` Douglas A. Gwyn
  2 siblings, 0 replies; 14+ messages in thread
From: David Presotto @ 2004-03-07 12:56 UTC (permalink / raw)
  To: 9fans

[-- Attachment #1: Type: text/plain, Size: 274 bytes --]

If its just a flag, some libraries will start to depend on the
behavior and noone will be able to write programs that use the
libraries and still can survive running out of memory.  I think
we should just bite the bullet and add e(malloc,realloc,mallocz)
to the library.

[-- Attachment #2: Type: message/rfc822, Size: 3023 bytes --]

From: Einar Karttunen <ekarttun@cs.helsinki.fi>
To: Plan9 ML <9fans@cse.psu.edu>
Subject: [9fans] making emalloc a library function
Date: Sun, 7 Mar 2004 13:32:09 +0200
Message-ID: <20040307113209.GA18849@melkki.cs.Helsinki.FI>

Hello

Quite many programs define emalloc, which does the same thing. I was
thinking of ripping these out and replacing with a library.

I have two alternative routes. Either make libemalloc which contains
emalloc, estrdup and so on or add a flag which makes libc malloc behave
like emalloc. 

The first way would give programs freedom, but library code would still
use raw malloc instead of the emalloc. The second solution would be
harder for programs wishing to use both emalloc and malloc (of course
this would be still possible), but it would be more general... 
The changes would break no existing code in either case. 
Should I go forward with either idea?

- Einar Karttunen

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [9fans] making emalloc a library function
  2004-03-07 11:32 [9fans] making emalloc a library function Einar Karttunen
  2004-03-07 12:56 ` David Presotto
@ 2004-03-07 15:37 ` andrey mirtchovski
  2004-03-07 17:06   ` Rob Pike
  2004-03-07 19:34   ` boyd, rounin
  2004-03-08 10:25 ` Douglas A. Gwyn
  2 siblings, 2 replies; 14+ messages in thread
From: andrey mirtchovski @ 2004-03-07 15:37 UTC (permalink / raw)
  To: 9fans

deja vu...  anyone looking to add e* functions to a library should
read the 'same functions everywhere' thread started almost exactly
a year ago.  contains some good arguments against it.

andrey



^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [9fans] making emalloc a library function
  2004-03-07 17:25     ` Einar Karttunen
@ 2004-03-07 16:47       ` andrey mirtchovski
  2004-03-07 23:05         ` Geoff Collyer
  2004-03-07 18:45       ` 9nut
  1 sibling, 1 reply; 14+ messages in thread
From: andrey mirtchovski @ 2004-03-07 16:47 UTC (permalink / raw)
  To: 9fans


> Well it seems that many programs in the source tree want the same
> behaviour as it is. And no-one would be forced to use the library.

Isn't that the reverse of 'whoever wants it, could write it in their
own code'?  Less than 50% of all Plan 9 programs use emalloc so there
isn't a majority rule you can apply.

> 
> The functions lib9p seem to do this (at least close). Would it 
> be possible to start from there? 
> 

The exceptions that prove the rule?  See how they aren't called
'emalloc' :)

Have you considered at the problem from all sides?  What are your
suggested implementations for eallocimage() and egetwindow()?

> So why are part of the emalloc implementations missing e.g.
> setmalloctag? Of course it is quite trivial to write, but in my
> opinion having dozens of definitions for the same function is
> not exactly sane. 

TPOP was the first to mention emalloc (not that it wasn't used
before), its authors were wise not to suggest default behavior.

> Also if one writes a malloc wrapper which 
> behaves unlike the emallocs naming it emalloc is quite confusing.

Again, you assume emalloc has a well defined behaviour.  It doesn't.
The fact that everybody uses it the same way means that they haven't
really thought out how their programs should behave after malloc has
returned an error.  Would you be happy if fossil called the library
emalloc and sysfatal()-ed after some user process has allocated too
much memory "just for fun"?  What should fossil do, define
eemalloc()?

andrey



^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [9fans] making emalloc a library function
  2004-03-07 15:37 ` andrey mirtchovski
@ 2004-03-07 17:06   ` Rob Pike
  2004-03-07 17:25     ` Einar Karttunen
                       ` (2 more replies)
  2004-03-07 19:34   ` boyd, rounin
  1 sibling, 3 replies; 14+ messages in thread
From: Rob Pike @ 2004-03-07 17:06 UTC (permalink / raw)
  To: 9fans

> deja vu...  anyone looking to add e* functions to a library should
> read the 'same functions everywhere' thread started almost exactly
> a year ago.  contains some good arguments against it.

right.  my main objection is that the specification of what to do in the
case of errors is so application-dependent that making a library for it
will either fail to capture many cases or encourage programs to fail
poorly.

plus, i mean really, how hard is emalloc to write?  the  part you'd
put in a library is trivial.  the part that matters is still up to you.

-rob



^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [9fans] making emalloc a library function
  2004-03-07 17:06   ` Rob Pike
@ 2004-03-07 17:25     ` Einar Karttunen
  2004-03-07 16:47       ` andrey mirtchovski
  2004-03-07 18:45       ` 9nut
  2004-03-07 18:48     ` 9nut
  2004-03-07 19:39     ` boyd, rounin
  2 siblings, 2 replies; 14+ messages in thread
From: Einar Karttunen @ 2004-03-07 17:25 UTC (permalink / raw)
  To: 9fans

On 07.03 09:06, Rob Pike wrote:
> right.  my main objection is that the specification of what to do in the
> case of errors is so application-dependent that making a library for it
> will either fail to capture many cases or encourage programs to fail
> poorly.

Well it seems that many programs in the source tree want the same
behaviour as it is. And no-one would be forced to use the library.

The functions lib9p seem to do this (at least close). Would it 
be possible to start from there? 
 
> plus, i mean really, how hard is emalloc to write?  the  part you'd
> put in a library is trivial.  the part that matters is still up to you.

So why are part of the emalloc implementations missing e.g.
setmalloctag? Of course it is quite trivial to write, but in my
opinion having dozens of definitions for the same function is
not exactly sane. Also if one writes a malloc wrapper which 
behaves unlike the emallocs naming it emalloc is quite confusing.

- Einar Karttunen


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [9fans] making emalloc a library function
  2004-03-07 17:25     ` Einar Karttunen
  2004-03-07 16:47       ` andrey mirtchovski
@ 2004-03-07 18:45       ` 9nut
  1 sibling, 0 replies; 14+ messages in thread
From: 9nut @ 2004-03-07 18:45 UTC (permalink / raw)
  To: 9fans

> Also if one writes a malloc wrapper which 
> behaves unlike the emallocs naming it emalloc is quite confusing.

Not if emalloc is in the application in every instance.



^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [9fans] making emalloc a library function
  2004-03-07 17:06   ` Rob Pike
  2004-03-07 17:25     ` Einar Karttunen
@ 2004-03-07 18:48     ` 9nut
  2004-03-07 19:39     ` boyd, rounin
  2 siblings, 0 replies; 14+ messages in thread
From: 9nut @ 2004-03-07 18:48 UTC (permalink / raw)
  To: 9fans

> plus, i mean really, how hard is emalloc to write?  the  part you'd
> put in a library is trivial.  the part that matters is still up to you.

"I'm with you, captain" -- boyd



^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [9fans] making emalloc a library function
  2004-03-07 15:37 ` andrey mirtchovski
  2004-03-07 17:06   ` Rob Pike
@ 2004-03-07 19:34   ` boyd, rounin
  1 sibling, 0 replies; 14+ messages in thread
From: boyd, rounin @ 2004-03-07 19:34 UTC (permalink / raw)
  To: 9fans

> deja vu...

déjà ;)



^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [9fans] making emalloc a library function
  2004-03-07 17:06   ` Rob Pike
  2004-03-07 17:25     ` Einar Karttunen
  2004-03-07 18:48     ` 9nut
@ 2004-03-07 19:39     ` boyd, rounin
  2 siblings, 0 replies; 14+ messages in thread
From: boyd, rounin @ 2004-03-07 19:39 UTC (permalink / raw)
  To: 9fans

> right.  my main objection is that the specification of what to do in the
> case of errors is so application-dependent that making a library for it
> will either fail to capture many cases or encourage programs to fail
> poorly.

exactly, unless you add yet another two arguments (which i'd be
loathed to do):

   - function to call on failure
   - arg to function

but i'd guess that this would degenerate to:

    - exits
    - "ran out of memory"

so i'd be against it.

malloc failing is not always fatal.



^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [9fans] making emalloc a library function
  2004-03-07 16:47       ` andrey mirtchovski
@ 2004-03-07 23:05         ` Geoff Collyer
  2004-03-07 23:10           ` boyd, rounin
  0 siblings, 1 reply; 14+ messages in thread
From: Geoff Collyer @ 2004-03-07 23:05 UTC (permalink / raw)
  To: 9fans

> TPOP was the first to mention emalloc (not that it wasn't used before)

Actually emalloc was mentioned in publications at least as early as
1984, in The UNIX Programming Environment.



^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [9fans] making emalloc a library function
  2004-03-07 23:05         ` Geoff Collyer
@ 2004-03-07 23:10           ` boyd, rounin
  2004-03-08 10:26             ` Douglas A. Gwyn
  0 siblings, 1 reply; 14+ messages in thread
From: boyd, rounin @ 2004-03-07 23:10 UTC (permalink / raw)
  To: 9fans

> Actually emalloc was mentioned in publications at least as early as
> 1984, in The UNIX Programming Environment.

at basser we called it salloc(), back in 82.



^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [9fans] making emalloc a library function
  2004-03-07 11:32 [9fans] making emalloc a library function Einar Karttunen
  2004-03-07 12:56 ` David Presotto
  2004-03-07 15:37 ` andrey mirtchovski
@ 2004-03-08 10:25 ` Douglas A. Gwyn
  2 siblings, 0 replies; 14+ messages in thread
From: Douglas A. Gwyn @ 2004-03-08 10:25 UTC (permalink / raw)
  To: 9fans

Einar Karttunen wrote:
> I have two alternative routes. Either make libemalloc which contains
> emalloc, estrdup and so on or add a flag which makes libc malloc behave
> like emalloc. 

It is a *very* bad idea to change the behavior of malloc().
Your program might link with some library that knows how to
recover when malloc() reports failure, and if you change
malloc() to act like emalloc() you will break that library.

There should be no problem adding emalloc() to the system C
library.


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [9fans] making emalloc a library function
  2004-03-07 23:10           ` boyd, rounin
@ 2004-03-08 10:26             ` Douglas A. Gwyn
  0 siblings, 0 replies; 14+ messages in thread
From: Douglas A. Gwyn @ 2004-03-08 10:26 UTC (permalink / raw)
  To: 9fans

boyd, rounin wrote:
>>Actually emalloc was mentioned in publications at least as early as
>>1984, in The UNIX Programming Environment.
> at basser we called it salloc(), back in 82.

And xmalloc() harks back to PWB, circa 1976.
My own malloc implementation supports throwing an
exception if you want to use it in a suitable
environment where that is the general scheme.


^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2004-03-08 10:26 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-03-07 11:32 [9fans] making emalloc a library function Einar Karttunen
2004-03-07 12:56 ` David Presotto
2004-03-07 15:37 ` andrey mirtchovski
2004-03-07 17:06   ` Rob Pike
2004-03-07 17:25     ` Einar Karttunen
2004-03-07 16:47       ` andrey mirtchovski
2004-03-07 23:05         ` Geoff Collyer
2004-03-07 23:10           ` boyd, rounin
2004-03-08 10:26             ` Douglas A. Gwyn
2004-03-07 18:45       ` 9nut
2004-03-07 18:48     ` 9nut
2004-03-07 19:39     ` boyd, rounin
2004-03-07 19:34   ` boyd, rounin
2004-03-08 10:25 ` Douglas A. Gwyn

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).