talloc: change talloc destructor signature

Change talloc destructor so that they can never signal failure, and
don't return a status code. This makes our talloc copy even more
incompatible to upstream talloc, but on the other hand this is
preparation for getting rid of talloc entirely.

(The talloc replacement in the next commit won't allow the talloc_free
equivalent to fail, and the destructor return value would be useless.
But I don't want to change any mpv code either; the idea is that the
talloc replacement commit can be reverted for some time in order to
test whether the talloc replacement introduced a regression.)
This commit is contained in:
wm4 2013-10-13 01:16:30 +02:00
parent 8d5f800567
commit c613d802bc
8 changed files with 14 additions and 30 deletions

View File

@ -116,12 +116,11 @@ static void ds_free_packs(struct demux_stream *ds)
ds->eof = 0;
}
static int packet_destroy(void *ptr)
static void packet_destroy(void *ptr)
{
struct demux_packet *dp = ptr;
talloc_free(dp->avpacket);
free(dp->allocation);
return 0;
}
static struct demux_packet *create_packet(size_t len)
@ -193,10 +192,9 @@ void free_demux_packet(struct demux_packet *dp)
talloc_free(dp);
}
static int destroy_avpacket(void *pkt)
static void destroy_avpacket(void *pkt)
{
av_free_packet(pkt);
return 0;
}
struct demux_packet *demux_copy_packet(struct demux_packet *dp)

View File

@ -717,10 +717,9 @@ static void seek_reset(demuxer_t *demux)
priv->num_packets = 0;
}
static int destroy_avpacket(void *pkt)
static void destroy_avpacket(void *pkt)
{
av_free_packet(pkt);
return 0;
}
static int read_more_av_packets(demuxer_t *demux)

View File

@ -180,13 +180,12 @@ static void add_options(struct m_config *config,
struct m_config_option *parent,
const struct m_option *defs);
static int config_destroy(void *p)
static void config_destroy(void *p)
{
struct m_config *config = p;
m_config_restore_backups(config);
for (struct m_config_option *copt = config->opts; copt; copt = copt->next)
m_option_free(copt->opt, copt->data);
return 0;
}
struct m_config *m_config_new(void *talloc_parent, size_t size,

View File

@ -135,7 +135,7 @@ struct talloc_reference_handle {
void *ptr;
};
typedef int (*talloc_destructor_t)(void *);
typedef void (*talloc_destructor_t)(void *);
struct talloc_chunk {
struct talloc_chunk *next, *prev;
@ -406,11 +406,8 @@ void *talloc_pool(const void *context, size_t size)
/*
setup a destructor to be called on free of a pointer
the destructor should return 0 on success, or -1 on failure.
if the destructor fails then the free is failed, and the memory can
be continued to be used
*/
void _talloc_set_destructor(const void *ptr, int (*destructor)(void *))
void _talloc_set_destructor(const void *ptr, void (*destructor)(void *))
{
struct talloc_chunk *tc = talloc_chunk_from_ptr(ptr);
tc->destructor = destructor;
@ -432,12 +429,11 @@ int talloc_increase_ref_count(const void *ptr)
this is referenced by a function pointer and should not be inline
*/
static int talloc_reference_destructor(void *ptr)
static void talloc_reference_destructor(void *ptr)
{
struct talloc_reference_handle *handle = ptr;
struct talloc_chunk *ptr_tc = talloc_chunk_from_ptr(handle->ptr);
_TLIST_REMOVE(ptr_tc->refs, handle);
return 0;
}
/*
@ -539,10 +535,7 @@ static inline int _talloc_free(void *ptr)
return -1;
}
tc->destructor = (talloc_destructor_t)-1;
if (d(ptr) == -1) {
tc->destructor = d;
return -1;
}
d(ptr);
tc->destructor = NULL;
}
@ -1651,10 +1644,9 @@ void *talloc_realloc_fn(const void *context, void *ptr, size_t size)
}
static int talloc_autofree_destructor(void *ptr)
static void talloc_autofree_destructor(void *ptr)
{
autofree_context = NULL;
return 0;
}
static void talloc_autofree(void)

View File

@ -113,7 +113,7 @@ typedef void TALLOC_CTX;
/* The following definitions come from talloc.c */
void *_talloc(const void *context, size_t size);
void *talloc_pool(const void *context, size_t size);
void _talloc_set_destructor(const void *ptr, int (*destructor)(void *));
void _talloc_set_destructor(const void *ptr, void (*destructor)(void *));
int talloc_increase_ref_count(const void *ptr);
size_t talloc_reference_count(const void *ptr);
void *_talloc_reference(const void *context, const void *ptr);

View File

@ -62,11 +62,10 @@ struct m_refcount {
};
// Only for checking API usage
static int m_refcount_destructor(void *ptr)
static void m_refcount_destructor(void *ptr)
{
struct m_refcount *ref = ptr;
assert(ref->refcount == 0);
return 0;
}
// Starts out with refcount==1, caller can set .arg and .free and .ext_*
@ -165,11 +164,10 @@ void mp_image_setfmt(struct mp_image *mpi, unsigned int out_fmt)
mp_image_set_size(mpi, mpi->w, mpi->h);
}
static int mp_image_destructor(void *ptr)
static void mp_image_destructor(void *ptr)
{
mp_image_t *mpi = ptr;
m_refcount_unref(mpi->refcount);
return 0;
}
static int mp_chroma_div_up(int size, int shift)

View File

@ -58,11 +58,10 @@ struct image_flags {
bool pool_alive; // the mp_image_pool references this
};
static int image_pool_destructor(void *ptr)
static void image_pool_destructor(void *ptr)
{
struct mp_image_pool *pool = ptr;
mp_image_pool_clear(pool);
return 0;
}
struct mp_image_pool *mp_image_pool_new(int max_count)

View File

@ -150,13 +150,12 @@ static bool cache_valid(struct mp_sws_context *ctx)
ctx->saturation == old->saturation;
}
static int free_mp_sws(void *p)
static void free_mp_sws(void *p)
{
struct mp_sws_context *ctx = p;
sws_freeContext(ctx->sws);
sws_freeFilter(ctx->src_filter);
sws_freeFilter(ctx->dst_filter);
return 0;
}
// You're supposed to set your scaling parameters on the returned context.