cn-cbor icon indicating copy to clipboard operation
cn-cbor copied to clipboard

Changes the cn_cbor_context macros to use const

Open bergzand opened this issue 6 years ago • 4 comments

The cn_cbor_context struct itself should not be modified by the calls that use the context struct. With this in mind the cn_cbor_context struct pointer should be passed as const to the functions using it.

bergzand avatar Apr 13 '18 16:04 bergzand

I am not clear what you are trying to do with this. I would need to remove the const by caching in my allocation and free functions. The cn_cbor_context is just a part of the structure I used for doing allocations.

jimsch avatar Apr 17 '18 01:04 jimsch

I am not clear what you are trying to do with this.

By changing the macro here I'm changing how the cn_cbor_context is passed to the functions requiring it. For example from (with the macro expanded):

cn_cbor* cn_cbor_map_create(cn_cbor_context *context, cn_cbor_errback *errp)

to:

cn_cbor* cn_cbor_map_create(const cn_cbor_context *context, cn_cbor_errback *errp)

The idea here is to indicate to the compiler that the passed cn_cbor_context struct is not modified by the function.

I would need to remove the const by caching in my allocation and free functions. The cn_cbor_context is just a part of the structure I used for doing allocations.

I'm not clear what the problem is you're trying to explain here. Is it possible for you to link a small example where my modification breaks code? This code should not prevent you from modifying the cn_cbor_context yourself and should not prevent the data where the void pointer of the cn_cbor_context points to from being modified.

bergzand avatar Apr 17 '18 07:04 bergzand

ping @cabo.

bergzand avatar May 09 '18 08:05 bergzand

@cabo ping

bergzand avatar Sep 28 '18 18:09 bergzand