mallocs.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /* classes: src_files
  2. * Copyright (C) 1995,1997,1998,2000,2001, 2006 Free Software Foundation, Inc.
  3. *
  4. * This library is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU Lesser General Public License
  6. * as published by the Free Software Foundation; either version 3 of
  7. * the License, or (at your option) any later version.
  8. *
  9. * This library is distributed in the hope that it will be useful, but
  10. * WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * Lesser General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU Lesser General Public
  15. * License along with this library; if not, write to the Free Software
  16. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  17. * 02110-1301 USA
  18. */
  19. #ifdef HAVE_CONFIG_H
  20. # include <config.h>
  21. #endif
  22. #include "libguile/_scm.h"
  23. #include "libguile/ports.h"
  24. #include "libguile/smob.h"
  25. #include "libguile/mallocs.h"
  26. #ifdef HAVE_MALLOC_H
  27. #include <malloc.h>
  28. #endif
  29. #ifdef HAVE_UNISTD_H
  30. #include <unistd.h>
  31. #endif
  32. scm_t_bits scm_tc16_malloc;
  33. static int
  34. malloc_print (SCM exp, SCM port, scm_print_state *pstate SCM_UNUSED)
  35. {
  36. scm_puts("#<malloc ", port);
  37. scm_uintprint (SCM_SMOB_DATA (exp), 16, port);
  38. scm_putc('>', port);
  39. return 1;
  40. }
  41. SCM
  42. scm_malloc_obj (size_t n)
  43. {
  44. scm_t_bits mem = n ? (scm_t_bits) scm_gc_malloc (n, "malloc smob") : 0;
  45. if (n && !mem)
  46. return SCM_BOOL_F;
  47. SCM_RETURN_NEWSMOB (scm_tc16_malloc, mem);
  48. }
  49. void
  50. scm_init_mallocs ()
  51. {
  52. scm_tc16_malloc = scm_make_smob_type ("malloc", 0);
  53. scm_set_smob_print (scm_tc16_malloc, malloc_print);
  54. }
  55. /*
  56. Local Variables:
  57. c-file-style: "gnu"
  58. End:
  59. */