home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / os / linux / 17471 < prev    next >
Encoding:
Text File  |  1992-11-21  |  1.8 KB  |  53 lines

  1. Path: sparky!uunet!cis.ohio-state.edu!zaphod.mps.ohio-state.edu!uwm.edu!ogicse!news.u.washington.edu!serval!hlu
  2. From: hlu@eecs.wsu.edu (H.J. Lu)
  3. Newsgroups: comp.os.linux
  4. Subject: Re: malloc (0) ( Re: function-->macro bugs.)
  5. Message-ID: <1992Nov21.181345.19607@serval.net.wsu.edu>
  6. Date: 21 Nov 92 18:13:45 GMT
  7. Article-I.D.: serval.1992Nov21.181345.19607
  8. References: <By0ows.95I@news.cso.uiuc.edu> <1992Nov21.000241.9744@klaava.Helsinki.FI> <1992Nov21.102153.15162@serval.net.wsu.edu> <1992Nov21.124529.10725@klaava.Helsinki.FI>
  9. Sender: news@serval.net.wsu.edu (USENET News System)
  10. Organization: School of EECS, Washington State University
  11. Lines: 40
  12.  
  13. In article <1992Nov21.124529.10725@klaava.Helsinki.FI>, wirzeniu@klaava.Helsinki.FI (Lars Wirzenius) writes:
  14. |> hlu@yoda.eecs.wsu.edu (H.J. Lu) writes:
  15.  
  16. [....]
  17.  
  18. |> 
  19. |> >If you can come up with a better idea to deal with
  20. |> >
  21. |> >    p = malloc (len); /* len may be 0. */
  22. |> >    if (!p) fatal ("Out of memory");
  23. |> >
  24. |> >I'd like to hear from you.
  25. |> 
  26. |> There are programs which assume that malloc(0)==NULL, and programs
  27. |> which assume malloc(0)!=NULL.  We can't support both types at the same
  28. |> time without some kinds of hacks, something will surely break.
  29. |> 
  30. |> I have no problems with the current scheme (except for some naming
  31. |> choices, I'd prefer __MALLOC_0_IS_NON_NULL instead of NO_FIX_MALLOC).
  32.  
  33. X11R5 uses MALLOC_0_RETURNS_NULL. I have changed stdlib.h to 
  34.  
  35. /* fix malloc (0) only if you include stdlib.h */
  36.  
  37. /* For compatibilities */
  38. #if defined(NO_FIX_MALLOC) && !defined(MALLOC_0_RETURNS_NULL)
  39. #define MALLOC_0_RETURNS_NULL
  40. #endif
  41.  
  42. #ifndef MALLOC_0_RETURNS_NULL
  43. ...... malloc macros
  44. #endif
  45.  
  46. |> Fixing programs that try to substitute their own malloc shouldn't be
  47. |> that hard.  We'll never achieve total compatibility with all current
  48. |> source code anyway.
  49. |> 
  50.  
  51.  
  52. H.J.
  53.