mallocs.c 1.7 KB

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