The Sol Programming Language!
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

gc.c 842B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #include <stdlib.h>
  2. #include "sol.h"
  3. #ifdef DEBUG_GC
  4. #else
  5. sol_object_t *sol_alloc_object(sol_state_t *state) {
  6. sol_object_t *res = malloc(sizeof(sol_object_t));
  7. if(!res) {
  8. sol_set_error(state, state->OutOfMemory);
  9. return sol_incref(state->None);
  10. }
  11. res->refcnt = 0;
  12. res->ops = &(state->NullOps);
  13. return sol_incref(res);
  14. }
  15. sol_object_t *sol_obj_acquire(sol_object_t *obj) {
  16. return sol_incref(obj);
  17. }
  18. void sol_obj_free(sol_object_t *obj) {
  19. if(!obj) {
  20. printf("WARNING: Attempt to free NULL\n");
  21. return;
  22. }
  23. if(sol_decref(obj) <= 0) {
  24. if(obj->refcnt < 0) {
  25. printf("WARNING: Encountered refcnt < 0!\nObject %p type %d ref %d\n", obj, obj->type, obj->refcnt);
  26. } else {
  27. sol_obj_release(obj);
  28. }
  29. }
  30. }
  31. void sol_obj_release(sol_object_t *obj) {
  32. if(obj->ops->free) obj->ops->free(NULL, obj);
  33. free(obj);
  34. }
  35. #endif