Rockbox open source high quality audio player as a Music Player Daemon
mpris rockbox mpd libadwaita audio rust zig deno
2
fork

Configure Feed

Select the types of activity you want to include in your feed.

Remove buflib allocation names, part one

Remove the name handling code, but leave the allocation structure
otherwise untouched; it's as if all callers provided a NULL name.
The public API still accepts names but names are no longer stored
or returned.

Change-Id: I6c4defcdfd255774f02030949a0fd731477e6a54

+15 -35
+15 -35
firmware/buflib.c
··· 118 118 fidx_LEN, /* length of the block, must come first */ 119 119 fidx_HANDLE, /* pointer to entry in the handle table */ 120 120 fidx_OPS, /* pointer to an ops struct */ 121 - fidx_NAME, /* name, optional and variable length, must come last */ 122 121 }; 123 122 124 123 /* Backward indices, used to index a block end pointer as block[-bidx_XXX] */ ··· 131 130 bidx_BSIZE, /* total size of the block header */ 132 131 }; 133 132 134 - /* Number of fields in the block header, excluding the name, which is 135 - * accounted for using the BSIZE field. Note that bidx_USER is not an 133 + /* Number of fields in the block header. Note that bidx_USER is not an 136 134 * actual field so it is not included in the count. */ 137 135 #ifdef BUFLIB_HAS_CRC 138 136 # define BUFLIB_NUM_FIELDS 6 ··· 191 189 static void check_block_crc(struct buflib_context *ctx, 192 190 union buflib_data *block, 193 191 union buflib_data *block_end); 194 - 195 - static inline char* get_block_name(union buflib_data *block) 196 - { 197 - return (char*)&block[fidx_NAME]; 198 - } 199 192 200 193 /* Initialize buffer manager */ 201 194 void ··· 401 394 return false; 402 395 403 396 int handle = ctx->handle_table - h_entry; 404 - BDEBUGF("%s(): moving \"%s\"(id=%d) by %d(%d)\n", __func__, 405 - get_block_name(block), handle, shift, shift*(int)sizeof(union buflib_data)); 397 + BDEBUGF("%s(): moving id=%d by %d(%d)\n", __func__, 398 + handle, shift, shift*(int)sizeof(union buflib_data)); 406 399 new_block = block + shift; 407 400 new_start = h_entry->alloc + shift*sizeof(union buflib_data); 408 401 ··· 645 638 646 639 /* Allocate a buffer of size bytes, returning a handle for it. 647 640 * 648 - * The additional name parameter gives the allocation a human-readable name, 649 - * the ops parameter points to caller-implemented callbacks for moving and 641 + * The ops parameter points to caller-implemented callbacks for moving and 650 642 * shrinking. 651 643 * 652 644 * If you pass NULL for "ops", buffers are movable by default. ··· 658 650 buflib_alloc_ex(struct buflib_context *ctx, size_t size, const char *name, 659 651 struct buflib_callbacks *ops) 660 652 { 653 + (void)name; 654 + 661 655 union buflib_data *handle, *block; 662 - size_t name_len = name ? B_ALIGN_UP(strlen(name)+1) : 0; 663 656 bool last; 664 657 /* This really is assigned a value before use */ 665 658 int block_len; 666 - size += name_len; 667 659 size = (size + sizeof(union buflib_data) - 1) / 668 660 sizeof(union buflib_data) 669 661 + BUFLIB_NUM_FIELDS; ··· 749 741 block[fidx_LEN].val = size; 750 742 block[fidx_HANDLE].handle = handle; 751 743 block[fidx_OPS].ops = ops; 752 - if (name_len > 0) 753 - strcpy(get_block_name(block), name); 754 744 755 - size_t bsize = BUFLIB_NUM_FIELDS + name_len/sizeof(union buflib_data); 745 + size_t bsize = BUFLIB_NUM_FIELDS; 756 746 union buflib_data *block_end = block + bsize; 757 747 block_end[-bidx_PIN].pincount = 0; 758 748 block_end[-bidx_BSIZE].val = bsize; ··· 760 750 761 751 handle->alloc = (char*)&block_end[-bidx_USER]; 762 752 763 - BDEBUGF("buflib_alloc_ex: size=%d handle=%p clb=%p name=\"%s\"\n", 764 - (unsigned int)size, (void *)handle, (void *)ops, name ? name : ""); 753 + BDEBUGF("buflib_alloc_ex: size=%d handle=%p clb=%p\n", 754 + (unsigned int)size, (void *)handle, (void *)ops); 765 755 766 756 block += size; 767 757 /* alloc_end must be kept current if we're taking the last block. */ ··· 868 858 ptrdiff_t diff = (ctx->last_handle - ctx->alloc_end - BUFLIB_NUM_FIELDS); 869 859 diff -= 16; /* space for future handles */ 870 860 diff *= sizeof(union buflib_data); /* make it bytes */ 871 - diff -= 16; /* reserve 16 for the name */ 872 861 873 862 if (diff > 0) 874 863 return diff; ··· 956 945 int 957 946 buflib_alloc_maximum(struct buflib_context* ctx, const char* name, size_t *size, struct buflib_callbacks *ops) 958 947 { 959 - /* limit name to 16 since that's what buflib_available() accounts for it */ 960 - char buf[16]; 961 - 962 948 /* ignore ctx->compact because it's true if all movable blocks are contiguous 963 949 * even if the buffer has holes due to unmovable allocations */ 964 950 unsigned hints; ··· 974 960 if (*size <= 0) /* OOM */ 975 961 return -1; 976 962 977 - strmemccpy(buf, name, sizeof(buf)); 978 - 979 - return buflib_alloc_ex(ctx, *size, buf, ops); 963 + return buflib_alloc_ex(ctx, *size, name, ops); 980 964 } 981 965 982 966 /* Shrink the allocation indicated by the handle according to new_start and ··· 1091 1075 1092 1076 const char* buflib_get_name(struct buflib_context *ctx, int handle) 1093 1077 { 1094 - union buflib_data *data = handle_to_block_end(ctx, handle); 1095 - size_t len = data[-bidx_BSIZE].val; 1096 - if (len <= BUFLIB_NUM_FIELDS) 1097 - return NULL; 1098 - 1099 - data -= len; 1100 - return get_block_name(data); 1078 + (void)ctx; 1079 + (void)handle; 1080 + return ""; 1101 1081 } 1102 1082 1103 1083 #ifdef DEBUG ··· 1153 1133 1154 1134 if (block_num-- == 0) 1155 1135 { 1156 - snprintf(buf, bufsize, "%8p: val: %4ld (%s)", 1136 + snprintf(buf, bufsize, "%8p: val: %4ld (%sallocated)", 1157 1137 block, (long)block->val, 1158 - block->val > 0 ? get_block_name(block) : "<unallocated>"); 1138 + block->val > 0 ? "" : "un"); 1159 1139 } 1160 1140 } 1161 1141 }