mallocs.c 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /* Copyright 1995-1998,2000-2001,2006,2011,2014,2018
  2. Free Software Foundation, Inc.
  3. This file is part of Guile.
  4. Guile is free software: you can redistribute it and/or modify it
  5. under the terms of the GNU Lesser General Public License as published
  6. by the Free Software Foundation, either version 3 of the License, or
  7. (at your option) any later version.
  8. Guile is distributed in the hope that it will be useful, but WITHOUT
  9. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10. FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
  11. License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with Guile. If not, see
  14. <https://www.gnu.org/licenses/>. */
  15. #ifdef HAVE_CONFIG_H
  16. # include <config.h>
  17. #endif
  18. #include <stdlib.h>
  19. #include <unistd.h>
  20. #include "ports.h"
  21. #include "smob.h"
  22. #include "mallocs.h"
  23. scm_t_bits scm_tc16_malloc;
  24. static int
  25. malloc_print (SCM exp, SCM port, scm_print_state *pstate SCM_UNUSED)
  26. {
  27. scm_puts ("#<malloc ", port);
  28. scm_uintprint (SCM_SMOB_DATA (exp), 16, port);
  29. scm_putc ('>', port);
  30. return 1;
  31. }
  32. SCM
  33. scm_malloc_obj (size_t n)
  34. {
  35. scm_t_bits mem = n ? (scm_t_bits) scm_gc_malloc (n, "malloc smob") : 0;
  36. if (n && !mem)
  37. return SCM_BOOL_F;
  38. SCM_RETURN_NEWSMOB (scm_tc16_malloc, mem);
  39. }
  40. void
  41. scm_init_mallocs ()
  42. {
  43. scm_tc16_malloc = scm_make_smob_type ("malloc", 0);
  44. scm_set_smob_print (scm_tc16_malloc, malloc_print);
  45. }