Commit 7c8fcbbd authored by Ganesh Ajjanagadde's avatar Ganesh Ajjanagadde

avutil/tree: add additional const qualifier to the comparator

libc's qsort comparator has a const qualifier on both arguments. This
adds a missing const qualifier to exactly match the comparator API.

Existing usages of av_tree_find, av_tree_insert are appropriately
modified: type signature changes of the comparators, and removal of
unnecessary void * casts of function pointers.
Reviewed-by: 's avatarHenrik Gramner <henrik@gramner.com>
Reviewed-by: 's avatarwm4 <nfxjfg@googlemail.com>
Signed-off-by: 's avatarGanesh Ajjanagadde <gajjanagadde@gmail.com>
parent 94f333f9
...@@ -288,7 +288,7 @@ typedef struct Glyph { ...@@ -288,7 +288,7 @@ typedef struct Glyph {
int bitmap_top; int bitmap_top;
} Glyph; } Glyph;
static int glyph_cmp(void *key, const void *b) static int glyph_cmp(const void *key, const void *b)
{ {
const Glyph *a = key, *bb = b; const Glyph *a = key, *bb = b;
int64_t diff = (int64_t)a->code - (int64_t)bb->code; int64_t diff = (int64_t)a->code - (int64_t)bb->code;
......
...@@ -65,9 +65,9 @@ typedef struct Context { ...@@ -65,9 +65,9 @@ typedef struct Context {
int read_ahead_limit; int read_ahead_limit;
} Context; } Context;
static int cmp(void *key, const void *node) static int cmp(const void *key, const void *node)
{ {
return (*(int64_t *) key) - ((const CacheEntry *) node)->logical_pos; return (*(const int64_t *) key) - ((const CacheEntry *) node)->logical_pos;
} }
static int cache_open(URLContext *h, const char *arg, int flags, AVDictionary **options) static int cache_open(URLContext *h, const char *arg, int flags, AVDictionary **options)
......
...@@ -237,14 +237,16 @@ int64_t ff_lsb2full(StreamContext *stream, int64_t lsb) ...@@ -237,14 +237,16 @@ int64_t ff_lsb2full(StreamContext *stream, int64_t lsb)
return ((lsb - delta) & mask) + delta; return ((lsb - delta) & mask) + delta;
} }
int ff_nut_sp_pos_cmp(const Syncpoint *a, const Syncpoint *b) int ff_nut_sp_pos_cmp(const void *a, const void *b)
{ {
return ((a->pos - b->pos) >> 32) - ((b->pos - a->pos) >> 32); const Syncpoint *va = a, *vb = b;
return ((va->pos - vb->pos) >> 32) - ((vb->pos - va->pos) >> 32);
} }
int ff_nut_sp_pts_cmp(const Syncpoint *a, const Syncpoint *b) int ff_nut_sp_pts_cmp(const void *a, const void *b)
{ {
return ((a->ts - b->ts) >> 32) - ((b->ts - a->ts) >> 32); const Syncpoint *va = a, *vb = b;
return ((va->ts - vb->ts) >> 32) - ((vb->ts - va->ts) >> 32);
} }
int ff_nut_add_sp(NUTContext *nut, int64_t pos, int64_t back_ptr, int64_t ts) int ff_nut_add_sp(NUTContext *nut, int64_t pos, int64_t back_ptr, int64_t ts)
...@@ -263,7 +265,7 @@ int ff_nut_add_sp(NUTContext *nut, int64_t pos, int64_t back_ptr, int64_t ts) ...@@ -263,7 +265,7 @@ int ff_nut_add_sp(NUTContext *nut, int64_t pos, int64_t back_ptr, int64_t ts)
sp->pos = pos; sp->pos = pos;
sp->back_ptr = back_ptr; sp->back_ptr = back_ptr;
sp->ts = ts; sp->ts = ts;
av_tree_insert(&nut->syncpoints, sp, (void *) ff_nut_sp_pos_cmp, &node); av_tree_insert(&nut->syncpoints, sp, ff_nut_sp_pos_cmp, &node);
if (node) { if (node) {
av_free(sp); av_free(sp);
av_free(node); av_free(node);
......
...@@ -132,8 +132,8 @@ typedef struct Dispositions { ...@@ -132,8 +132,8 @@ typedef struct Dispositions {
void ff_nut_reset_ts(NUTContext *nut, AVRational time_base, int64_t val); void ff_nut_reset_ts(NUTContext *nut, AVRational time_base, int64_t val);
int64_t ff_lsb2full(StreamContext *stream, int64_t lsb); int64_t ff_lsb2full(StreamContext *stream, int64_t lsb);
int ff_nut_sp_pos_cmp(const Syncpoint *a, const Syncpoint *b); int ff_nut_sp_pos_cmp(const void *a, const void *b);
int ff_nut_sp_pts_cmp(const Syncpoint *a, const Syncpoint *b); int ff_nut_sp_pts_cmp(const void *a, const void *b);
int ff_nut_add_sp(NUTContext *nut, int64_t pos, int64_t back_ptr, int64_t ts); int ff_nut_add_sp(NUTContext *nut, int64_t pos, int64_t back_ptr, int64_t ts);
void ff_nut_free_sp(NUTContext *nut); void ff_nut_free_sp(NUTContext *nut);
......
...@@ -1271,7 +1271,7 @@ static int read_seek(AVFormatContext *s, int stream_index, ...@@ -1271,7 +1271,7 @@ static int read_seek(AVFormatContext *s, int stream_index,
pos2 = st->index_entries[index].pos; pos2 = st->index_entries[index].pos;
ts = st->index_entries[index].timestamp; ts = st->index_entries[index].timestamp;
} else { } else {
av_tree_find(nut->syncpoints, &dummy, (void *) ff_nut_sp_pts_cmp, av_tree_find(nut->syncpoints, &dummy, ff_nut_sp_pts_cmp,
(void **) next_node); (void **) next_node);
av_log(s, AV_LOG_DEBUG, "%"PRIu64"-%"PRIu64" %"PRId64"-%"PRId64"\n", av_log(s, AV_LOG_DEBUG, "%"PRIu64"-%"PRIu64" %"PRId64"-%"PRId64"\n",
next_node[0]->pos, next_node[1]->pos, next_node[0]->ts, next_node[0]->pos, next_node[1]->pos, next_node[0]->ts,
...@@ -1286,7 +1286,7 @@ static int read_seek(AVFormatContext *s, int stream_index, ...@@ -1286,7 +1286,7 @@ static int read_seek(AVFormatContext *s, int stream_index,
if (!(flags & AVSEEK_FLAG_BACKWARD)) { if (!(flags & AVSEEK_FLAG_BACKWARD)) {
dummy.pos = pos + 16; dummy.pos = pos + 16;
next_node[1] = &nopts_sp; next_node[1] = &nopts_sp;
av_tree_find(nut->syncpoints, &dummy, (void *) ff_nut_sp_pos_cmp, av_tree_find(nut->syncpoints, &dummy, ff_nut_sp_pos_cmp,
(void **) next_node); (void **) next_node);
pos2 = ff_gen_search(s, -2, dummy.pos, next_node[0]->pos, pos2 = ff_gen_search(s, -2, dummy.pos, next_node[0]->pos,
next_node[1]->pos, next_node[1]->pos, next_node[1]->pos, next_node[1]->pos,
...@@ -1297,7 +1297,7 @@ static int read_seek(AVFormatContext *s, int stream_index, ...@@ -1297,7 +1297,7 @@ static int read_seek(AVFormatContext *s, int stream_index,
// FIXME dir but I think it does not matter // FIXME dir but I think it does not matter
} }
dummy.pos = pos; dummy.pos = pos;
sp = av_tree_find(nut->syncpoints, &dummy, (void *) ff_nut_sp_pos_cmp, sp = av_tree_find(nut->syncpoints, &dummy, ff_nut_sp_pos_cmp,
NULL); NULL);
av_assert0(sp); av_assert0(sp);
......
...@@ -587,7 +587,7 @@ static int write_index(NUTContext *nut, AVIOContext *bc) { ...@@ -587,7 +587,7 @@ static int write_index(NUTContext *nut, AVIOContext *bc) {
ff_put_v(bc, nut->sp_count); ff_put_v(bc, nut->sp_count);
for (i=0; i<nut->sp_count; i++) { for (i=0; i<nut->sp_count; i++) {
av_tree_find(nut->syncpoints, &dummy, (void *) ff_nut_sp_pos_cmp, (void**)next_node); av_tree_find(nut->syncpoints, &dummy, ff_nut_sp_pos_cmp, (void**)next_node);
ff_put_v(bc, (next_node[1]->pos >> 4) - (dummy.pos>>4)); ff_put_v(bc, (next_node[1]->pos >> 4) - (dummy.pos>>4));
dummy.pos = next_node[1]->pos; dummy.pos = next_node[1]->pos;
} }
......
...@@ -37,7 +37,7 @@ struct AVTreeNode *av_tree_node_alloc(void) ...@@ -37,7 +37,7 @@ struct AVTreeNode *av_tree_node_alloc(void)
} }
void *av_tree_find(const AVTreeNode *t, void *key, void *av_tree_find(const AVTreeNode *t, void *key,
int (*cmp)(void *key, const void *b), void *next[2]) int (*cmp)(const void *key, const void *b), void *next[2])
{ {
if (t) { if (t) {
unsigned int v = cmp(key, t->elem); unsigned int v = cmp(key, t->elem);
...@@ -57,7 +57,7 @@ void *av_tree_find(const AVTreeNode *t, void *key, ...@@ -57,7 +57,7 @@ void *av_tree_find(const AVTreeNode *t, void *key,
} }
void *av_tree_insert(AVTreeNode **tp, void *key, void *av_tree_insert(AVTreeNode **tp, void *key,
int (*cmp)(void *key, const void *b), AVTreeNode **next) int (*cmp)(const void *key, const void *b), AVTreeNode **next)
{ {
AVTreeNode *t = *tp; AVTreeNode *t = *tp;
if (t) { if (t) {
......
...@@ -62,7 +62,7 @@ struct AVTreeNode *av_tree_node_alloc(void); ...@@ -62,7 +62,7 @@ struct AVTreeNode *av_tree_node_alloc(void);
* exists in the tree. * exists in the tree.
*/ */
void *av_tree_find(const struct AVTreeNode *root, void *key, void *av_tree_find(const struct AVTreeNode *root, void *key,
int (*cmp)(void *key, const void *b), void *next[2]); int (*cmp)(const void *key, const void *b), void *next[2]);
/** /**
* Insert or remove an element. * Insert or remove an element.
...@@ -109,7 +109,7 @@ void *av_tree_find(const struct AVTreeNode *root, void *key, ...@@ -109,7 +109,7 @@ void *av_tree_find(const struct AVTreeNode *root, void *key,
* should make no assumptions that it's one or the other in the code. * should make no assumptions that it's one or the other in the code.
*/ */
void *av_tree_insert(struct AVTreeNode **rootp, void *key, void *av_tree_insert(struct AVTreeNode **rootp, void *key,
int (*cmp)(void *key, const void *b), int (*cmp)(const void *key, const void *b),
struct AVTreeNode **next); struct AVTreeNode **next);
void av_tree_destroy(struct AVTreeNode *t); void av_tree_destroy(struct AVTreeNode *t);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment