Unverified Commit bc5b19e6 by Patrick Steinhardt Committed by GitHub

Merge pull request #4561 from pks-t/pks/downcasting

[RFC] util: introduce GIT_DOWNCAST macro
parents af95615f 431601f2
...@@ -227,9 +227,9 @@ static void backend_free(git_config_backend *_backend) ...@@ -227,9 +227,9 @@ static void backend_free(git_config_backend *_backend)
static int config_iterator_new( static int config_iterator_new(
git_config_iterator **iter, git_config_iterator **iter,
struct git_config_backend* backend) struct git_config_backend *backend)
{ {
diskfile_header *bh = (diskfile_header *) backend; diskfile_header *bh = GIT_CONTAINER_OF(backend, diskfile_header, parent);
git_config_entries *entries; git_config_entries *entries;
int error; int error;
......
...@@ -1521,7 +1521,7 @@ static void filesystem_iterator_set_current( ...@@ -1521,7 +1521,7 @@ static void filesystem_iterator_set_current(
static int filesystem_iterator_current( static int filesystem_iterator_current(
const git_index_entry **out, git_iterator *i) const git_index_entry **out, git_iterator *i)
{ {
filesystem_iterator *iter = (filesystem_iterator *)i; filesystem_iterator *iter = GIT_CONTAINER_OF(i, filesystem_iterator, base);
if (!iterator__has_been_accessed(i)) if (!iterator__has_been_accessed(i))
return iter->base.cb->advance(out, i); return iter->base.cb->advance(out, i);
...@@ -1568,7 +1568,7 @@ done: ...@@ -1568,7 +1568,7 @@ done:
static int filesystem_iterator_advance( static int filesystem_iterator_advance(
const git_index_entry **out, git_iterator *i) const git_index_entry **out, git_iterator *i)
{ {
filesystem_iterator *iter = (filesystem_iterator *)i; filesystem_iterator *iter = GIT_CONTAINER_OF(i, filesystem_iterator, base);
bool is_dir; bool is_dir;
int error = 0; int error = 0;
...@@ -1627,7 +1627,7 @@ static int filesystem_iterator_advance( ...@@ -1627,7 +1627,7 @@ static int filesystem_iterator_advance(
static int filesystem_iterator_advance_into( static int filesystem_iterator_advance_into(
const git_index_entry **out, git_iterator *i) const git_index_entry **out, git_iterator *i)
{ {
filesystem_iterator *iter = (filesystem_iterator *)i; filesystem_iterator *iter = GIT_CONTAINER_OF(i, filesystem_iterator, base);
filesystem_iterator_frame *frame; filesystem_iterator_frame *frame;
filesystem_iterator_entry *prev_entry; filesystem_iterator_entry *prev_entry;
int error; int error;
...@@ -1664,7 +1664,7 @@ static int filesystem_iterator_advance_into( ...@@ -1664,7 +1664,7 @@ static int filesystem_iterator_advance_into(
int git_iterator_current_workdir_path(git_buf **out, git_iterator *i) int git_iterator_current_workdir_path(git_buf **out, git_iterator *i)
{ {
filesystem_iterator *iter = (filesystem_iterator *)i; filesystem_iterator *iter = GIT_CONTAINER_OF(i, filesystem_iterator, base);
const git_index_entry *entry; const git_index_entry *entry;
if (i->type != GIT_ITERATOR_TYPE_FS && if (i->type != GIT_ITERATOR_TYPE_FS &&
...@@ -1724,15 +1724,19 @@ GIT_INLINE(bool) filesystem_iterator_current_is_ignored( ...@@ -1724,15 +1724,19 @@ GIT_INLINE(bool) filesystem_iterator_current_is_ignored(
bool git_iterator_current_is_ignored(git_iterator *i) bool git_iterator_current_is_ignored(git_iterator *i)
{ {
filesystem_iterator *iter = NULL;
if (i->type != GIT_ITERATOR_TYPE_WORKDIR) if (i->type != GIT_ITERATOR_TYPE_WORKDIR)
return false; return false;
return filesystem_iterator_current_is_ignored((filesystem_iterator *)i); iter = GIT_CONTAINER_OF(i, filesystem_iterator, base);
return filesystem_iterator_current_is_ignored(iter);
} }
bool git_iterator_current_tree_is_ignored(git_iterator *i) bool git_iterator_current_tree_is_ignored(git_iterator *i)
{ {
filesystem_iterator *iter = (filesystem_iterator *)i; filesystem_iterator *iter = GIT_CONTAINER_OF(i, filesystem_iterator, base);
filesystem_iterator_frame *frame; filesystem_iterator_frame *frame;
if (i->type != GIT_ITERATOR_TYPE_WORKDIR) if (i->type != GIT_ITERATOR_TYPE_WORKDIR)
...@@ -1747,7 +1751,7 @@ static int filesystem_iterator_advance_over( ...@@ -1747,7 +1751,7 @@ static int filesystem_iterator_advance_over(
git_iterator_status_t *status, git_iterator_status_t *status,
git_iterator *i) git_iterator *i)
{ {
filesystem_iterator *iter = (filesystem_iterator *)i; filesystem_iterator *iter = GIT_CONTAINER_OF(i, filesystem_iterator, base);
filesystem_iterator_frame *current_frame; filesystem_iterator_frame *current_frame;
filesystem_iterator_entry *current_entry; filesystem_iterator_entry *current_entry;
const git_index_entry *entry = NULL; const git_index_entry *entry = NULL;
...@@ -1866,7 +1870,7 @@ static int filesystem_iterator_init(filesystem_iterator *iter) ...@@ -1866,7 +1870,7 @@ static int filesystem_iterator_init(filesystem_iterator *iter)
static int filesystem_iterator_reset(git_iterator *i) static int filesystem_iterator_reset(git_iterator *i)
{ {
filesystem_iterator *iter = (filesystem_iterator *)i; filesystem_iterator *iter = GIT_CONTAINER_OF(i, filesystem_iterator, base);
filesystem_iterator_clear(iter); filesystem_iterator_clear(iter);
return filesystem_iterator_init(iter); return filesystem_iterator_init(iter);
...@@ -1874,7 +1878,7 @@ static int filesystem_iterator_reset(git_iterator *i) ...@@ -1874,7 +1878,7 @@ static int filesystem_iterator_reset(git_iterator *i)
static void filesystem_iterator_free(git_iterator *i) static void filesystem_iterator_free(git_iterator *i)
{ {
filesystem_iterator *iter = (filesystem_iterator *)i; filesystem_iterator *iter = GIT_CONTAINER_OF(i, filesystem_iterator, base);
git__free(iter->root); git__free(iter->root);
git_buf_dispose(&iter->current_path); git_buf_dispose(&iter->current_path);
git_tree_free(iter->tree); git_tree_free(iter->tree);
...@@ -2083,7 +2087,7 @@ static int index_iterator_skip_pseudotree(index_iterator *iter) ...@@ -2083,7 +2087,7 @@ static int index_iterator_skip_pseudotree(index_iterator *iter)
static int index_iterator_advance( static int index_iterator_advance(
const git_index_entry **out, git_iterator *i) const git_index_entry **out, git_iterator *i)
{ {
index_iterator *iter = (index_iterator *)i; index_iterator *iter = GIT_CONTAINER_OF(i, index_iterator, base);
const git_index_entry *entry = NULL; const git_index_entry *entry = NULL;
bool is_submodule; bool is_submodule;
int error = 0; int error = 0;
...@@ -2156,7 +2160,7 @@ static int index_iterator_advance( ...@@ -2156,7 +2160,7 @@ static int index_iterator_advance(
static int index_iterator_advance_into( static int index_iterator_advance_into(
const git_index_entry **out, git_iterator *i) const git_index_entry **out, git_iterator *i)
{ {
index_iterator *iter = (index_iterator *)i; index_iterator *iter = GIT_CONTAINER_OF(i, index_iterator, base);
if (! S_ISDIR(iter->tree_entry.mode)) { if (! S_ISDIR(iter->tree_entry.mode)) {
if (out) if (out)
...@@ -2174,7 +2178,7 @@ static int index_iterator_advance_over( ...@@ -2174,7 +2178,7 @@ static int index_iterator_advance_over(
git_iterator_status_t *status, git_iterator_status_t *status,
git_iterator *i) git_iterator *i)
{ {
index_iterator *iter = (index_iterator *)i; index_iterator *iter = GIT_CONTAINER_OF(i, index_iterator, base);
const git_index_entry *entry; const git_index_entry *entry;
int error; int error;
...@@ -2203,7 +2207,7 @@ static int index_iterator_init(index_iterator *iter) ...@@ -2203,7 +2207,7 @@ static int index_iterator_init(index_iterator *iter)
static int index_iterator_reset(git_iterator *i) static int index_iterator_reset(git_iterator *i)
{ {
index_iterator *iter = (index_iterator *)i; index_iterator *iter = GIT_CONTAINER_OF(i, index_iterator, base);
index_iterator_clear(iter); index_iterator_clear(iter);
return index_iterator_init(iter); return index_iterator_init(iter);
...@@ -2211,7 +2215,7 @@ static int index_iterator_reset(git_iterator *i) ...@@ -2211,7 +2215,7 @@ static int index_iterator_reset(git_iterator *i)
static void index_iterator_free(git_iterator *i) static void index_iterator_free(git_iterator *i)
{ {
index_iterator *iter = (index_iterator *)i; index_iterator *iter = GIT_CONTAINER_OF(i, index_iterator, base);
git_index_snapshot_release(&iter->entries, iter->base.index); git_index_snapshot_release(&iter->entries, iter->base.index);
git_buf_dispose(&iter->tree_buf); git_buf_dispose(&iter->tree_buf);
......
...@@ -327,7 +327,7 @@ static int refdb_fs_backend__exists( ...@@ -327,7 +327,7 @@ static int refdb_fs_backend__exists(
git_refdb_backend *_backend, git_refdb_backend *_backend,
const char *ref_name) const char *ref_name)
{ {
refdb_fs_backend *backend = (refdb_fs_backend *)_backend; refdb_fs_backend *backend = GIT_CONTAINER_OF(_backend, refdb_fs_backend, parent);
git_buf ref_path = GIT_BUF_INIT; git_buf ref_path = GIT_BUF_INIT;
int error; int error;
...@@ -469,7 +469,7 @@ static int refdb_fs_backend__lookup( ...@@ -469,7 +469,7 @@ static int refdb_fs_backend__lookup(
git_refdb_backend *_backend, git_refdb_backend *_backend,
const char *ref_name) const char *ref_name)
{ {
refdb_fs_backend *backend = (refdb_fs_backend *)_backend; refdb_fs_backend *backend = GIT_CONTAINER_OF(_backend, refdb_fs_backend, parent);
int error; int error;
assert(backend); assert(backend);
...@@ -502,7 +502,7 @@ typedef struct { ...@@ -502,7 +502,7 @@ typedef struct {
static void refdb_fs_backend__iterator_free(git_reference_iterator *_iter) static void refdb_fs_backend__iterator_free(git_reference_iterator *_iter)
{ {
refdb_fs_iter *iter = (refdb_fs_iter *) _iter; refdb_fs_iter *iter = GIT_CONTAINER_OF(_iter, refdb_fs_iter, parent);
git_vector_free(&iter->loose); git_vector_free(&iter->loose);
git_pool_clear(&iter->pool); git_pool_clear(&iter->pool);
...@@ -591,8 +591,8 @@ static int refdb_fs_backend__iterator_next( ...@@ -591,8 +591,8 @@ static int refdb_fs_backend__iterator_next(
git_reference **out, git_reference_iterator *_iter) git_reference **out, git_reference_iterator *_iter)
{ {
int error = GIT_ITEROVER; int error = GIT_ITEROVER;
refdb_fs_iter *iter = (refdb_fs_iter *)_iter; refdb_fs_iter *iter = GIT_CONTAINER_OF(_iter, refdb_fs_iter, parent);
refdb_fs_backend *backend = (refdb_fs_backend *)iter->parent.db->backend; refdb_fs_backend *backend = GIT_CONTAINER_OF(iter->parent.db->backend, refdb_fs_backend, parent);
struct packref *ref; struct packref *ref;
while (iter->loose_pos < iter->loose.length) { while (iter->loose_pos < iter->loose.length) {
...@@ -632,8 +632,8 @@ static int refdb_fs_backend__iterator_next_name( ...@@ -632,8 +632,8 @@ static int refdb_fs_backend__iterator_next_name(
const char **out, git_reference_iterator *_iter) const char **out, git_reference_iterator *_iter)
{ {
int error = GIT_ITEROVER; int error = GIT_ITEROVER;
refdb_fs_iter *iter = (refdb_fs_iter *)_iter; refdb_fs_iter *iter = GIT_CONTAINER_OF(_iter, refdb_fs_iter, parent);
refdb_fs_backend *backend = (refdb_fs_backend *)iter->parent.db->backend; refdb_fs_backend *backend = GIT_CONTAINER_OF(iter->parent.db->backend, refdb_fs_backend, parent);
struct packref *ref; struct packref *ref;
while (iter->loose_pos < iter->loose.length) { while (iter->loose_pos < iter->loose.length) {
...@@ -674,7 +674,7 @@ static int refdb_fs_backend__iterator_next_name( ...@@ -674,7 +674,7 @@ static int refdb_fs_backend__iterator_next_name(
static int refdb_fs_backend__iterator( static int refdb_fs_backend__iterator(
git_reference_iterator **out, git_refdb_backend *_backend, const char *glob) git_reference_iterator **out, git_refdb_backend *_backend, const char *glob)
{ {
refdb_fs_backend *backend = (refdb_fs_backend *)_backend; refdb_fs_backend *backend = GIT_CONTAINER_OF(_backend, refdb_fs_backend, parent);
refdb_fs_iter *iter = NULL; refdb_fs_iter *iter = NULL;
int error; int error;
...@@ -838,7 +838,7 @@ static int refdb_fs_backend__lock(void **out, git_refdb_backend *_backend, const ...@@ -838,7 +838,7 @@ static int refdb_fs_backend__lock(void **out, git_refdb_backend *_backend, const
{ {
int error; int error;
git_filebuf *lock; git_filebuf *lock;
refdb_fs_backend *backend = (refdb_fs_backend *) _backend; refdb_fs_backend *backend = GIT_CONTAINER_OF(_backend, refdb_fs_backend, parent);
lock = git__calloc(1, sizeof(git_filebuf)); lock = git__calloc(1, sizeof(git_filebuf));
GIT_ERROR_CHECK_ALLOC(lock); GIT_ERROR_CHECK_ALLOC(lock);
...@@ -1248,7 +1248,7 @@ static int refdb_fs_backend__write( ...@@ -1248,7 +1248,7 @@ static int refdb_fs_backend__write(
const git_oid *old_id, const git_oid *old_id,
const char *old_target) const char *old_target)
{ {
refdb_fs_backend *backend = (refdb_fs_backend *)_backend; refdb_fs_backend *backend = GIT_CONTAINER_OF(_backend, refdb_fs_backend, parent);
git_filebuf file = GIT_FILEBUF_INIT; git_filebuf file = GIT_FILEBUF_INIT;
int error = 0; int error = 0;
...@@ -1274,7 +1274,7 @@ static int refdb_fs_backend__write_tail( ...@@ -1274,7 +1274,7 @@ static int refdb_fs_backend__write_tail(
const git_oid *old_id, const git_oid *old_id,
const char *old_target) const char *old_target)
{ {
refdb_fs_backend *backend = (refdb_fs_backend *)_backend; refdb_fs_backend *backend = GIT_CONTAINER_OF(_backend, refdb_fs_backend, parent);
int error = 0, cmp = 0, should_write; int error = 0, cmp = 0, should_write;
const char *new_target = NULL; const char *new_target = NULL;
const git_oid *new_id = NULL; const git_oid *new_id = NULL;
...@@ -1364,7 +1364,7 @@ static int refdb_fs_backend__delete( ...@@ -1364,7 +1364,7 @@ static int refdb_fs_backend__delete(
const char *ref_name, const char *ref_name,
const git_oid *old_id, const char *old_target) const git_oid *old_id, const char *old_target)
{ {
refdb_fs_backend *backend = (refdb_fs_backend *)_backend; refdb_fs_backend *backend = GIT_CONTAINER_OF(_backend, refdb_fs_backend, parent);
git_filebuf file = GIT_FILEBUF_INIT; git_filebuf file = GIT_FILEBUF_INIT;
int error = 0; int error = 0;
...@@ -1387,7 +1387,7 @@ static int refdb_fs_backend__delete_tail( ...@@ -1387,7 +1387,7 @@ static int refdb_fs_backend__delete_tail(
const char *ref_name, const char *ref_name,
const git_oid *old_id, const char *old_target) const git_oid *old_id, const char *old_target)
{ {
refdb_fs_backend *backend = (refdb_fs_backend *)_backend; refdb_fs_backend *backend = GIT_CONTAINER_OF(_backend, refdb_fs_backend, parent);
git_buf loose_path = GIT_BUF_INIT; git_buf loose_path = GIT_BUF_INIT;
size_t pack_pos; size_t pack_pos;
int error = 0, cmp = 0; int error = 0, cmp = 0;
...@@ -1455,7 +1455,7 @@ static int refdb_fs_backend__rename( ...@@ -1455,7 +1455,7 @@ static int refdb_fs_backend__rename(
const git_signature *who, const git_signature *who,
const char *message) const char *message)
{ {
refdb_fs_backend *backend = (refdb_fs_backend *)_backend; refdb_fs_backend *backend = GIT_CONTAINER_OF(_backend, refdb_fs_backend, parent);
git_reference *old, *new; git_reference *old, *new;
git_filebuf file = GIT_FILEBUF_INIT; git_filebuf file = GIT_FILEBUF_INIT;
int error; int error;
...@@ -1511,7 +1511,7 @@ static int refdb_fs_backend__rename( ...@@ -1511,7 +1511,7 @@ static int refdb_fs_backend__rename(
static int refdb_fs_backend__compress(git_refdb_backend *_backend) static int refdb_fs_backend__compress(git_refdb_backend *_backend)
{ {
int error; int error;
refdb_fs_backend *backend = (refdb_fs_backend *)_backend; refdb_fs_backend *backend = GIT_CONTAINER_OF(_backend, refdb_fs_backend, parent);
assert(backend); assert(backend);
...@@ -1525,7 +1525,7 @@ static int refdb_fs_backend__compress(git_refdb_backend *_backend) ...@@ -1525,7 +1525,7 @@ static int refdb_fs_backend__compress(git_refdb_backend *_backend)
static void refdb_fs_backend__free(git_refdb_backend *_backend) static void refdb_fs_backend__free(git_refdb_backend *_backend)
{ {
refdb_fs_backend *backend = (refdb_fs_backend *)_backend; refdb_fs_backend *backend = GIT_CONTAINER_OF(_backend, refdb_fs_backend, parent);
assert(backend); assert(backend);
...@@ -1703,7 +1703,7 @@ static int refdb_reflog_fs__ensure_log(git_refdb_backend *_backend, const char * ...@@ -1703,7 +1703,7 @@ static int refdb_reflog_fs__ensure_log(git_refdb_backend *_backend, const char *
assert(_backend && name); assert(_backend && name);
backend = (refdb_fs_backend *) _backend; backend = GIT_CONTAINER_OF(_backend, refdb_fs_backend, parent);
repo = backend->repo; repo = backend->repo;
if ((error = retrieve_reflog_path(&path, repo, name)) < 0) if ((error = retrieve_reflog_path(&path, repo, name)) < 0)
...@@ -1736,7 +1736,7 @@ static int refdb_reflog_fs__has_log(git_refdb_backend *_backend, const char *nam ...@@ -1736,7 +1736,7 @@ static int refdb_reflog_fs__has_log(git_refdb_backend *_backend, const char *nam
assert(_backend && name); assert(_backend && name);
backend = (refdb_fs_backend *) _backend; backend = GIT_CONTAINER_OF(_backend, refdb_fs_backend, parent);
return has_reflog(backend->repo, name); return has_reflog(backend->repo, name);
} }
...@@ -1752,7 +1752,7 @@ static int refdb_reflog_fs__read(git_reflog **out, git_refdb_backend *_backend, ...@@ -1752,7 +1752,7 @@ static int refdb_reflog_fs__read(git_reflog **out, git_refdb_backend *_backend,
assert(out && _backend && name); assert(out && _backend && name);
backend = (refdb_fs_backend *) _backend; backend = GIT_CONTAINER_OF(_backend, refdb_fs_backend, parent);
repo = backend->repo; repo = backend->repo;
if (reflog_alloc(&log, name) < 0) if (reflog_alloc(&log, name) < 0)
...@@ -1862,7 +1862,7 @@ static int refdb_reflog_fs__write(git_refdb_backend *_backend, git_reflog *reflo ...@@ -1862,7 +1862,7 @@ static int refdb_reflog_fs__write(git_refdb_backend *_backend, git_reflog *reflo
assert(_backend && reflog); assert(_backend && reflog);
backend = (refdb_fs_backend *) _backend; backend = GIT_CONTAINER_OF(_backend, refdb_fs_backend, parent);
if ((error = lock_reflog(&fbuf, backend, reflog->ref_name)) < 0) if ((error = lock_reflog(&fbuf, backend, reflog->ref_name)) < 0)
return -1; return -1;
...@@ -1984,7 +1984,7 @@ static int refdb_reflog_fs__rename(git_refdb_backend *_backend, const char *old_ ...@@ -1984,7 +1984,7 @@ static int refdb_reflog_fs__rename(git_refdb_backend *_backend, const char *old_
assert(_backend && old_name && new_name); assert(_backend && old_name && new_name);
backend = (refdb_fs_backend *) _backend; backend = GIT_CONTAINER_OF(_backend, refdb_fs_backend, parent);
repo = backend->repo; repo = backend->repo;
if ((error = git_reference__normalize_name( if ((error = git_reference__normalize_name(
...@@ -2055,7 +2055,7 @@ cleanup: ...@@ -2055,7 +2055,7 @@ cleanup:
static int refdb_reflog_fs__delete(git_refdb_backend *_backend, const char *name) static int refdb_reflog_fs__delete(git_refdb_backend *_backend, const char *name)
{ {
refdb_fs_backend *backend = (refdb_fs_backend *) _backend; refdb_fs_backend *backend = GIT_CONTAINER_OF(_backend, refdb_fs_backend, parent);
git_buf path = GIT_BUF_INIT; git_buf path = GIT_BUF_INIT;
int error; int error;
......
...@@ -1144,7 +1144,7 @@ static int http_stream_write_chunked( ...@@ -1144,7 +1144,7 @@ static int http_stream_write_chunked(
const char *buffer, const char *buffer,
size_t len) size_t len)
{ {
http_stream *s = (http_stream *)stream; http_stream *s = GIT_CONTAINER_OF(stream, http_stream, parent);
http_subtransport *t = OWNING_SUBTRANSPORT(s); http_subtransport *t = OWNING_SUBTRANSPORT(s);
assert(t->connected); assert(t->connected);
...@@ -1218,7 +1218,7 @@ static int http_stream_write_single( ...@@ -1218,7 +1218,7 @@ static int http_stream_write_single(
const char *buffer, const char *buffer,
size_t len) size_t len)
{ {
http_stream *s = (http_stream *)stream; http_stream *s = GIT_CONTAINER_OF(stream, http_stream, parent);
http_subtransport *t = OWNING_SUBTRANSPORT(s); http_subtransport *t = OWNING_SUBTRANSPORT(s);
git_buf request = GIT_BUF_INIT; git_buf request = GIT_BUF_INIT;
...@@ -1252,7 +1252,7 @@ on_error: ...@@ -1252,7 +1252,7 @@ on_error:
static void http_stream_free(git_smart_subtransport_stream *stream) static void http_stream_free(git_smart_subtransport_stream *stream)
{ {
http_stream *s = (http_stream *)stream; http_stream *s = GIT_CONTAINER_OF(stream, http_stream, parent);
if (s->chunk_buffer) if (s->chunk_buffer)
git__free(s->chunk_buffer); git__free(s->chunk_buffer);
...@@ -1365,7 +1365,7 @@ static int http_action( ...@@ -1365,7 +1365,7 @@ static int http_action(
const char *url, const char *url,
git_smart_service_t action) git_smart_service_t action)
{ {
http_subtransport *t = (http_subtransport *)subtransport; http_subtransport *t = GIT_CONTAINER_OF(subtransport, http_subtransport, parent);
int ret; int ret;
assert(stream); assert(stream);
...@@ -1419,7 +1419,7 @@ static void free_auth_contexts(git_vector *contexts) ...@@ -1419,7 +1419,7 @@ static void free_auth_contexts(git_vector *contexts)
static int http_close(git_smart_subtransport *subtransport) static int http_close(git_smart_subtransport *subtransport)
{ {
http_subtransport *t = (http_subtransport *) subtransport; http_subtransport *t = GIT_CONTAINER_OF(subtransport, http_subtransport, parent);
clear_parser_state(t); clear_parser_state(t);
...@@ -1459,7 +1459,7 @@ static int http_close(git_smart_subtransport *subtransport) ...@@ -1459,7 +1459,7 @@ static int http_close(git_smart_subtransport *subtransport)
static void http_free(git_smart_subtransport *subtransport) static void http_free(git_smart_subtransport *subtransport)
{ {
http_subtransport *t = (http_subtransport *) subtransport; http_subtransport *t = GIT_CONTAINER_OF(subtransport, http_subtransport, parent);
http_close(subtransport); http_close(subtransport);
......
...@@ -63,7 +63,7 @@ static int git_smart__set_callbacks( ...@@ -63,7 +63,7 @@ static int git_smart__set_callbacks(
git_transport_certificate_check_cb certificate_check_cb, git_transport_certificate_check_cb certificate_check_cb,
void *message_cb_payload) void *message_cb_payload)
{ {
transport_smart *t = (transport_smart *)transport; transport_smart *t = GIT_CONTAINER_OF(transport, transport_smart, parent);
t->progress_cb = progress_cb; t->progress_cb = progress_cb;
t->error_cb = error_cb; t->error_cb = error_cb;
...@@ -128,7 +128,7 @@ static int git_smart__set_custom_headers( ...@@ -128,7 +128,7 @@ static int git_smart__set_custom_headers(
git_transport *transport, git_transport *transport,
const git_strarray *custom_headers) const git_strarray *custom_headers)
{ {
transport_smart *t = (transport_smart *)transport; transport_smart *t = GIT_CONTAINER_OF(transport, transport_smart, parent);
size_t i; size_t i;
if (t->custom_headers.count) if (t->custom_headers.count)
...@@ -212,7 +212,7 @@ static int git_smart__connect( ...@@ -212,7 +212,7 @@ static int git_smart__connect(
int direction, int direction,
int flags) int flags)
{ {
transport_smart *t = (transport_smart *)transport; transport_smart *t = GIT_CONTAINER_OF(transport, transport_smart, parent);
git_smart_subtransport_stream *stream; git_smart_subtransport_stream *stream;
int error; int error;
git_pkt *pkt; git_pkt *pkt;
...@@ -315,7 +315,7 @@ cleanup: ...@@ -315,7 +315,7 @@ cleanup:
static int git_smart__ls(const git_remote_head ***out, size_t *size, git_transport *transport) static int git_smart__ls(const git_remote_head ***out, size_t *size, git_transport *transport)
{ {
transport_smart *t = (transport_smart *)transport; transport_smart *t = GIT_CONTAINER_OF(transport, transport_smart, parent);
if (!t->have_refs) { if (!t->have_refs) {
git_error_set(GIT_ERROR_NET, "the transport has not yet loaded the refs"); git_error_set(GIT_ERROR_NET, "the transport has not yet loaded the refs");
...@@ -330,7 +330,7 @@ static int git_smart__ls(const git_remote_head ***out, size_t *size, git_transpo ...@@ -330,7 +330,7 @@ static int git_smart__ls(const git_remote_head ***out, size_t *size, git_transpo
int git_smart__negotiation_step(git_transport *transport, void *data, size_t len) int git_smart__negotiation_step(git_transport *transport, void *data, size_t len)
{ {
transport_smart *t = (transport_smart *)transport; transport_smart *t = GIT_CONTAINER_OF(transport, transport_smart, parent);
git_smart_subtransport_stream *stream; git_smart_subtransport_stream *stream;
int error; int error;
...@@ -387,21 +387,21 @@ int git_smart__get_push_stream(transport_smart *t, git_smart_subtransport_stream ...@@ -387,21 +387,21 @@ int git_smart__get_push_stream(transport_smart *t, git_smart_subtransport_stream
static void git_smart__cancel(git_transport *transport) static void git_smart__cancel(git_transport *transport)
{ {
transport_smart *t = (transport_smart *)transport; transport_smart *t = GIT_CONTAINER_OF(transport, transport_smart, parent);
git_atomic_set(&t->cancelled, 1); git_atomic_set(&t->cancelled, 1);
} }
static int git_smart__is_connected(git_transport *transport) static int git_smart__is_connected(git_transport *transport)
{ {
transport_smart *t = (transport_smart *)transport; transport_smart *t = GIT_CONTAINER_OF(transport, transport_smart, parent);
return t->connected; return t->connected;
} }
static int git_smart__read_flags(git_transport *transport, int *flags) static int git_smart__read_flags(git_transport *transport, int *flags)
{ {
transport_smart *t = (transport_smart *)transport; transport_smart *t = GIT_CONTAINER_OF(transport, transport_smart, parent);
*flags = t->flags; *flags = t->flags;
...@@ -410,7 +410,7 @@ static int git_smart__read_flags(git_transport *transport, int *flags) ...@@ -410,7 +410,7 @@ static int git_smart__read_flags(git_transport *transport, int *flags)
static int git_smart__close(git_transport *transport) static int git_smart__close(git_transport *transport)
{ {
transport_smart *t = (transport_smart *)transport; transport_smart *t = GIT_CONTAINER_OF(transport, transport_smart, parent);
git_vector *common = &t->common; git_vector *common = &t->common;
unsigned int i; unsigned int i;
git_pkt *p; git_pkt *p;
...@@ -447,7 +447,7 @@ static int git_smart__close(git_transport *transport) ...@@ -447,7 +447,7 @@ static int git_smart__close(git_transport *transport)
static void git_smart__free(git_transport *transport) static void git_smart__free(git_transport *transport)
{ {
transport_smart *t = (transport_smart *)transport; transport_smart *t = GIT_CONTAINER_OF(transport, transport_smart, parent);
git_vector *refs = &t->refs; git_vector *refs = &t->refs;
unsigned int i; unsigned int i;
git_pkt *p; git_pkt *p;
...@@ -479,7 +479,7 @@ static int ref_name_cmp(const void *a, const void *b) ...@@ -479,7 +479,7 @@ static int ref_name_cmp(const void *a, const void *b)
int git_transport_smart_certificate_check(git_transport *transport, git_cert *cert, int valid, const char *hostname) int git_transport_smart_certificate_check(git_transport *transport, git_cert *cert, int valid, const char *hostname)
{ {
transport_smart *t = (transport_smart *)transport; transport_smart *t = GIT_CONTAINER_OF(transport, transport_smart, parent);
assert(transport && cert && hostname); assert(transport && cert && hostname);
...@@ -491,7 +491,7 @@ int git_transport_smart_certificate_check(git_transport *transport, git_cert *ce ...@@ -491,7 +491,7 @@ int git_transport_smart_certificate_check(git_transport *transport, git_cert *ce
int git_transport_smart_credentials(git_cred **out, git_transport *transport, const char *user, int methods) int git_transport_smart_credentials(git_cred **out, git_transport *transport, const char *user, int methods)
{ {
transport_smart *t = (transport_smart *)transport; transport_smart *t = GIT_CONTAINER_OF(transport, transport_smart, parent);
assert(out && transport); assert(out && transport);
...@@ -503,7 +503,7 @@ int git_transport_smart_credentials(git_cred **out, git_transport *transport, co ...@@ -503,7 +503,7 @@ int git_transport_smart_credentials(git_cred **out, git_transport *transport, co
int git_transport_smart_proxy_options(git_proxy_options *out, git_transport *transport) int git_transport_smart_proxy_options(git_proxy_options *out, git_transport *transport)
{ {
transport_smart *t = (transport_smart *) transport; transport_smart *t = GIT_CONTAINER_OF(transport, transport_smart, parent);
return git_proxy_options_dup(out, &t->proxy); return git_proxy_options_dup(out, &t->proxy);
} }
......
...@@ -132,7 +132,7 @@ static int ssh_stream_read( ...@@ -132,7 +132,7 @@ static int ssh_stream_read(
size_t *bytes_read) size_t *bytes_read)
{ {
int rc; int rc;
ssh_stream *s = (ssh_stream *)stream; ssh_stream *s = GIT_CONTAINER_OF(stream, ssh_stream, parent);
*bytes_read = 0; *bytes_read = 0;
...@@ -170,7 +170,7 @@ static int ssh_stream_write( ...@@ -170,7 +170,7 @@ static int ssh_stream_write(
const char *buffer, const char *buffer,
size_t len) size_t len)
{ {
ssh_stream *s = (ssh_stream *)stream; ssh_stream *s = GIT_CONTAINER_OF(stream, ssh_stream, parent);
size_t off = 0; size_t off = 0;
ssize_t ret = 0; ssize_t ret = 0;
...@@ -196,7 +196,7 @@ static int ssh_stream_write( ...@@ -196,7 +196,7 @@ static int ssh_stream_write(
static void ssh_stream_free(git_smart_subtransport_stream *stream) static void ssh_stream_free(git_smart_subtransport_stream *stream)
{ {
ssh_stream *s = (ssh_stream *)stream; ssh_stream *s = GIT_CONTAINER_OF(stream, ssh_stream, parent);
ssh_subtransport *t; ssh_subtransport *t;
if (!stream) if (!stream)
...@@ -479,7 +479,7 @@ static int _git_ssh_session_create( ...@@ -479,7 +479,7 @@ static int _git_ssh_session_create(
{ {
int rc = 0; int rc = 0;
LIBSSH2_SESSION* s; LIBSSH2_SESSION* s;
git_socket_stream *socket = (git_socket_stream *) io; git_socket_stream *socket = GIT_CONTAINER_OF(io, git_socket_stream, parent);
assert(session); assert(session);
...@@ -730,7 +730,7 @@ static int _ssh_action( ...@@ -730,7 +730,7 @@ static int _ssh_action(
const char *url, const char *url,
git_smart_service_t action) git_smart_service_t action)
{ {
ssh_subtransport *t = (ssh_subtransport *) subtransport; ssh_subtransport *t = GIT_CONTAINER_OF(subtransport, ssh_subtransport, parent);
switch (action) { switch (action) {
case GIT_SERVICE_UPLOADPACK_LS: case GIT_SERVICE_UPLOADPACK_LS:
...@@ -752,7 +752,7 @@ static int _ssh_action( ...@@ -752,7 +752,7 @@ static int _ssh_action(
static int _ssh_close(git_smart_subtransport *subtransport) static int _ssh_close(git_smart_subtransport *subtransport)
{ {
ssh_subtransport *t = (ssh_subtransport *) subtransport; ssh_subtransport *t = GIT_CONTAINER_OF(subtransport, ssh_subtransport, parent);
assert(!t->current_stream); assert(!t->current_stream);
...@@ -763,7 +763,7 @@ static int _ssh_close(git_smart_subtransport *subtransport) ...@@ -763,7 +763,7 @@ static int _ssh_close(git_smart_subtransport *subtransport)
static void _ssh_free(git_smart_subtransport *subtransport) static void _ssh_free(git_smart_subtransport *subtransport)
{ {
ssh_subtransport *t = (ssh_subtransport *) subtransport; ssh_subtransport *t = GIT_CONTAINER_OF(subtransport, ssh_subtransport, parent);
assert(!t->current_stream); assert(!t->current_stream);
......
...@@ -30,6 +30,17 @@ ...@@ -30,6 +30,17 @@
# define max(a,b) ((a) > (b) ? (a) : (b)) # define max(a,b) ((a) > (b) ? (a) : (b))
#endif #endif
#if defined(__GNUC__)
# define GIT_CONTAINER_OF(ptr, type, member) \
__builtin_choose_expr( \
__builtin_offsetof(type, member) == 0 && \
__builtin_types_compatible_p(typeof(&((type *) 0)->member), typeof(ptr)), \
((type *) (ptr)), \
(void)0)
#else
# define GIT_CONTAINER_OF(ptr, type, member) (type *)(ptr)
#endif
#define GIT_DATE_RFC2822_SZ 32 #define GIT_DATE_RFC2822_SZ 32
/** /**
......
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