Closed FSMaxB closed 8 years ago
Just a crazy idea on how the C preprocessor could be abused. Right now molch has the throw_on_failed_alloc macro, see #78. Let's take a look at some example:
throw_on_failed_alloc
buffer_t *header_key = buffer_create_on_heap(HEADER_KEY_SIZE, 0); throw_on_failed_alloc(header_key); buffer_t *message_key = buffer_create_on_heap(MESSAGE_KEY_SIZE, 0); throw_on_failed_alloc(message_key);
But that could be better, right?
check_allocations(header_key, message_key, buffer_t *header_key = buffer_create_on_heap(HEADER_KEY_SIZE, 0); buffer_t *message_key = buffer_create_on_heap(MESSAGE_KEY_SIZE, 0); )
This macro would then automatically produce code like this:
buffer_t *header_key = buffer_create_on_heap(HEADER_KEY_SIZE, 0); buffer_t *message_key = buffer_create_on_heap(MESSAGE_KEY_SIZE, 0); throw_on_failed_alloc(header_key); throw_on_failed_alloc(message_key);
This could be achieved by some crazy macro trick like this
Although this seems nice, it would make debugging a lot harder. I don't think this is worth it.
Just a crazy idea on how the C preprocessor could be abused. Right now molch has the
throw_on_failed_alloc
macro, see #78. Let's take a look at some example:But that could be better, right?
This macro would then automatically produce code like this:
This could be achieved by some crazy macro trick like this