Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

handling errors in the implementation #20

Closed
chrisosaurus opened this issue Jun 21, 2016 · 2 comments
Closed

handling errors in the implementation #20

chrisosaurus opened this issue Jun 21, 2016 · 2 comments

Comments

@chrisosaurus
Copy link
Contributor

chrisosaurus commented Jun 21, 2016

Looking at the implementation for obj_new we see

Obj *obj_new(char tag) {                                                                                                                                                                                          
  Obj *o = malloc(sizeof(Obj));                                                                                                                                                                                   
  o->prev = obj_latest;                                                                                                                                                                                           
  o->alive = false;                                                                                                                                                                                               
  o->given_to_ffi = false;                                                                                                                                                                                        
  o->tag = tag;                                                                                                                                                                                                   
  o->meta = NULL;                                                                                                                                                                                                 
  obj_latest = o;                                                                                                                                                                                                 
  obj_total++;                                                                                                                                                                                                    
  if(LOG_ALLOCS) {                                                                                                                                                                                                
    printf("alloc %p %c\n", o, o->tag);                                                                                                                                                                           
  }                                                                                                                                                                                                               
  return o;                                                                                                                                                                                                       
}     

a call to malloc can fail

I would like to add some error handling here, if that suits you.

How would you like errors of this nature to be handled?
I am happy to just print error and exit the program (probably something stronger than an assert - as asserts can be compiled out).

@eriksvedang
Copy link
Collaborator

There is an ettor handling mechanism, you can see it used in primops.c a lot. The macros used for error handling are in assertions.h. They allocate themselves though so maybe better to exit, like you say.

@eriksvedang
Copy link
Collaborator

Please go ahead and add the code if you feel like it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants