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

Feature: Customization to define custom allocators #75

Open
sigvartmh opened this issue Sep 22, 2017 · 4 comments
Open

Feature: Customization to define custom allocators #75

sigvartmh opened this issue Sep 22, 2017 · 4 comments

Comments

@sigvartmh
Copy link

Some constrained systems may require the use of custom allocator like some ports using freeRTOS. So a way of redefining the allocators for _cbor_value_dup_string could be useful.

@sigvartmh
Copy link
Author

I'll try to do a proposal and submit a pull request.

@thiagomacieira
Copy link
Member

There's no need for new API. If you need a custom allocator, do:

    size_t n;
    err = cbor_value_calculate_string_length(value, &n);
    if (!err) {
        buffer = allocate_somehow(n);
        err = cbor_value_copy_text_string(value, buffer, &n, &value);
    }
    return err;

@sigvartmh
Copy link
Author

sigvartmh commented Sep 25, 2017

https://github.com/01org/tinycbor/blob/70f58e8b8adaed0cc7828c2d75f147a63af50eba/src/cborparser_dup_string.c#L102

Since malloc/free already exists in a function of the parser wouldn't it be better just to allow the user to set custom allocators instead of reimplementing the function?

I know it's in the documentation, but I don't think it would increase the code size or complexity that much.

@thiagomacieira
Copy link
Member

I will accept a patch that allows you to choose your allocator at compile time. I will not accept a patch that stores anything.

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

No branches or pull requests

2 participants