mirror of
https://github.com/Rockbox/rockbox.git
synced 2025-12-08 12:45:26 -05:00
buflib: add handle_to_block_end
Change-Id: I598cf32bc8cd08ab4bca3827645e0a38b284468f
This commit is contained in:
parent
88b21731fc
commit
ecfec3e9bf
1 changed files with 15 additions and 1 deletions
|
|
@ -317,6 +317,20 @@ void handle_free(struct buflib_context *ctx, union buflib_data *handle)
|
||||||
ctx->compact = false;
|
ctx->compact = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline
|
||||||
|
union buflib_data* handle_to_block_end(struct buflib_context *ctx, int handle)
|
||||||
|
{
|
||||||
|
void *ptr = buflib_get_data(ctx, handle);
|
||||||
|
|
||||||
|
/* this is a valid case for shrinking if handle
|
||||||
|
* was freed by the shrink callback */
|
||||||
|
if (!ptr)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
union buflib_data *data = ALIGN_DOWN(ptr, sizeof(*data));
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
/* Get the start block of an allocation */
|
/* Get the start block of an allocation */
|
||||||
static inline
|
static inline
|
||||||
union buflib_data* handle_to_block(struct buflib_context* ctx, int handle)
|
union buflib_data* handle_to_block(struct buflib_context* ctx, int handle)
|
||||||
|
|
@ -1038,7 +1052,7 @@ buflib_shrink(struct buflib_context* ctx, int handle, void* new_start, size_t ne
|
||||||
|
|
||||||
const char* buflib_get_name(struct buflib_context *ctx, int handle)
|
const char* buflib_get_name(struct buflib_context *ctx, int handle)
|
||||||
{
|
{
|
||||||
union buflib_data *data = ALIGN_DOWN(buflib_get_data(ctx, handle), sizeof (*data));
|
union buflib_data *data = handle_to_block_end(ctx, handle);
|
||||||
size_t len = data[-bidx_BSIZE].val;
|
size_t len = data[-bidx_BSIZE].val;
|
||||||
if (len <= BUFLIB_NUM_FIELDS)
|
if (len <= BUFLIB_NUM_FIELDS)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue