luamem.c 749 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /*
  2. ** mem.c
  3. ** TecCGraf - PUC-Rio
  4. */
  5. char *rcs_mem = "$Id: mem.c,v 1.4 1995/01/13 22:11:12 roberto Exp roberto $";
  6. #include <stdlib.h>
  7. #include <string.h>
  8. #include "mem.h"
  9. #include "lua.h"
  10. void luaI_free (void *block)
  11. {
  12. *((int *)block) = -1; /* to catch errors */
  13. free(block);
  14. }
  15. void *luaI_malloc (unsigned long size)
  16. {
  17. void *block = malloc((size_t)size);
  18. if (block == NULL)
  19. lua_error("not enough memory");
  20. return block;
  21. }
  22. void *luaI_realloc (void *oldblock, unsigned long size)
  23. {
  24. void *block = realloc(oldblock, (size_t)size);
  25. if (block == NULL)
  26. lua_error("not enough memory");
  27. return block;
  28. }
  29. char *luaI_strdup (char *str)
  30. {
  31. char *newstr = luaI_malloc(strlen(str)+1);
  32. strcpy(newstr, str);
  33. return newstr;
  34. }