mallocs.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /* classes: src_files
  2. * Copyright (C) 1995,1997,1998,2000,2001, 2006, 2011 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 <stdlib.h>
  23. #include "libguile/_scm.h"
  24. #include "libguile/ports.h"
  25. #include "libguile/smob.h"
  26. #include "libguile/mallocs.h"
  27. #ifdef HAVE_UNISTD_H
  28. #include <unistd.h>
  29. #endif
  30. scm_t_bits scm_tc16_malloc;
  31. static int
  32. malloc_print (SCM exp, SCM port, scm_print_state *pstate SCM_UNUSED)
  33. {
  34. scm_puts_unlocked("#<malloc ", port);
  35. scm_uintprint (SCM_SMOB_DATA (exp), 16, port);
  36. scm_putc_unlocked('>', port);
  37. return 1;
  38. }
  39. SCM
  40. scm_malloc_obj (size_t n)
  41. {
  42. scm_t_bits mem = n ? (scm_t_bits) scm_gc_malloc (n, "malloc smob") : 0;
  43. if (n && !mem)
  44. return SCM_BOOL_F;
  45. SCM_RETURN_NEWSMOB (scm_tc16_malloc, mem);
  46. }
  47. void
  48. scm_init_mallocs ()
  49. {
  50. scm_tc16_malloc = scm_make_smob_type ("malloc", 0);
  51. scm_set_smob_print (scm_tc16_malloc, malloc_print);
  52. }
  53. /*
  54. Local Variables:
  55. c-file-style: "gnu"
  56. End:
  57. */