avoid deref

We can avoid a deref when we use container_of to get from the interface
to the handle.
This commit is contained in:
Wim Taymans 2016-10-12 17:27:29 +02:00
parent 6b3bb79e70
commit 82414810e8
23 changed files with 433 additions and 385 deletions

View file

@ -187,10 +187,10 @@ spa_audiotestsrc_node_get_props (SpaNode *node,
{
SpaAudioTestSrc *this;
if (node == NULL || node->handle == NULL || props == NULL)
if (node == NULL || props == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
this = (SpaAudioTestSrc *) node->handle;
this = SPA_CONTAINER_OF (node, SpaAudioTestSrc, node);
memcpy (&this->props[0], &this->props[1], sizeof (this->props[1]));
*props = &this->props[0].props;
@ -206,10 +206,10 @@ spa_audiotestsrc_node_set_props (SpaNode *node,
SpaAudioTestSrcProps *p;
SpaResult res;
if (node == NULL || node->handle == NULL)
if (node == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
this = (SpaAudioTestSrc *) node->handle;
this = SPA_CONTAINER_OF (node, SpaAudioTestSrc, node);
p = &this->props[1];
if (props == NULL) {
@ -346,10 +346,10 @@ spa_audiotestsrc_node_send_command (SpaNode *node,
{
SpaAudioTestSrc *this;
if (node == NULL || node->handle == NULL || command == NULL)
if (node == NULL || command == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
this = (SpaAudioTestSrc *) node->handle;
this = SPA_CONTAINER_OF (node, SpaAudioTestSrc, node);
switch (command->type) {
case SPA_NODE_COMMAND_INVALID:
@ -413,10 +413,10 @@ spa_audiotestsrc_node_set_event_callback (SpaNode *node,
{
SpaAudioTestSrc *this;
if (node == NULL || node->handle == NULL)
if (node == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
this = (SpaAudioTestSrc *) node->handle;
this = SPA_CONTAINER_OF (node, SpaAudioTestSrc, node);
if (event_cb == NULL && this->event_cb) {
spa_poll_remove_item (this->data_loop, &this->timer);
@ -438,7 +438,7 @@ spa_audiotestsrc_node_get_n_ports (SpaNode *node,
unsigned int *n_output_ports,
unsigned int *max_output_ports)
{
if (node == NULL || node->handle == NULL)
if (node == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
if (n_input_ports)
@ -460,7 +460,7 @@ spa_audiotestsrc_node_get_port_ids (SpaNode *node,
unsigned int n_output_ports,
uint32_t *output_ids)
{
if (node == NULL || node->handle == NULL)
if (node == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
if (n_output_ports > 0 && output_ids != NULL)
@ -496,10 +496,10 @@ spa_audiotestsrc_node_port_enum_formats (SpaNode *node,
SpaAudioTestSrc *this;
int index;
if (node == NULL || node->handle == NULL || format == NULL || state == NULL)
if (node == NULL || format == NULL || state == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
this = (SpaAudioTestSrc *) node->handle;
this = SPA_CONTAINER_OF (node, SpaAudioTestSrc, node);
if (!CHECK_PORT (this, direction, port_id))
return SPA_RESULT_INVALID_PORT;
@ -546,10 +546,10 @@ spa_audiotestsrc_node_port_set_format (SpaNode *node,
SpaAudioTestSrc *this;
SpaResult res;
if (node == NULL || node->handle == NULL)
if (node == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
this = (SpaAudioTestSrc *) node->handle;
this = SPA_CONTAINER_OF (node, SpaAudioTestSrc, node);
if (!CHECK_PORT (this, direction, port_id))
return SPA_RESULT_INVALID_PORT;
@ -600,10 +600,10 @@ spa_audiotestsrc_node_port_get_format (SpaNode *node,
{
SpaAudioTestSrc *this;
if (node == NULL || node->handle == NULL || format == NULL)
if (node == NULL || format == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
this = (SpaAudioTestSrc *) node->handle;
this = SPA_CONTAINER_OF (node, SpaAudioTestSrc, node);
if (!CHECK_PORT (this, direction, port_id))
return SPA_RESULT_INVALID_PORT;
@ -624,10 +624,10 @@ spa_audiotestsrc_node_port_get_info (SpaNode *node,
{
SpaAudioTestSrc *this;
if (node == NULL || node->handle == NULL || info == NULL)
if (node == NULL || info == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
this = (SpaAudioTestSrc *) node->handle;
this = SPA_CONTAINER_OF (node, SpaAudioTestSrc, node);
if (!CHECK_PORT (this, direction, port_id))
return SPA_RESULT_INVALID_PORT;
@ -665,10 +665,10 @@ spa_audiotestsrc_node_port_use_buffers (SpaNode *node,
SpaAudioTestSrc *this;
unsigned int i;
if (node == NULL || node->handle == NULL)
if (node == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
this = (SpaAudioTestSrc *) node->handle;
this = SPA_CONTAINER_OF (node, SpaAudioTestSrc, node);
if (!CHECK_PORT (this, direction, port_id))
return SPA_RESULT_INVALID_PORT;
@ -726,10 +726,10 @@ spa_audiotestsrc_node_port_alloc_buffers (SpaNode *node,
{
SpaAudioTestSrc *this;
if (node == NULL || node->handle == NULL)
if (node == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
this = (SpaAudioTestSrc *) node->handle;
this = SPA_CONTAINER_OF (node, SpaAudioTestSrc, node);
if (!CHECK_PORT (this, direction, port_id))
return SPA_RESULT_INVALID_PORT;
@ -751,10 +751,10 @@ spa_audiotestsrc_node_port_get_status (SpaNode *node,
{
SpaAudioTestSrc *this;
if (node == NULL || node->handle == NULL || status == NULL)
if (node == NULL || status == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
this = (SpaAudioTestSrc *) node->handle;
this = SPA_CONTAINER_OF (node, SpaAudioTestSrc, node);
if (!CHECK_PORT (this, direction, port_id))
return SPA_RESULT_INVALID_PORT;
@ -785,10 +785,10 @@ spa_audiotestsrc_node_port_pull_output (SpaNode *node,
unsigned int i;
bool have_error = false;
if (node == NULL || node->handle == NULL || n_info == 0 || info == NULL)
if (node == NULL || n_info == 0 || info == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
this = (SpaAudioTestSrc *) node->handle;
this = SPA_CONTAINER_OF (node, SpaAudioTestSrc, node);
for (i = 0; i < n_info; i++) {
ATSBuffer *b;
@ -830,10 +830,10 @@ spa_audiotestsrc_node_port_reuse_buffer (SpaNode *node,
SpaAudioTestSrc *this;
ATSBuffer *b;
if (node == NULL || node->handle == NULL)
if (node == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
this = (SpaAudioTestSrc *) node->handle;
this = SPA_CONTAINER_OF (node, SpaAudioTestSrc, node);
if (port_id != 0)
return SPA_RESULT_INVALID_PORT;
@ -868,7 +868,6 @@ spa_audiotestsrc_node_port_push_event (SpaNode *node,
}
static const SpaNode audiotestsrc_node = {
NULL,
sizeof (SpaNode),
NULL,
SPA_NODE_STATE_INIT,
@ -918,7 +917,7 @@ spa_audiotestsrc_clock_get_time (SpaClock *clock,
struct timespec now;
uint64_t tnow;
if (clock == NULL || clock->handle == NULL)
if (clock == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
if (rate)
@ -936,7 +935,6 @@ spa_audiotestsrc_clock_get_time (SpaClock *clock,
}
static const SpaClock audiotestsrc_clock = {
NULL,
sizeof (SpaClock),
NULL,
SPA_CLOCK_STATE_STOPPED,
@ -1020,9 +1018,7 @@ audiotestsrc_init (const SpaHandleFactory *factory,
this->uri.clock = spa_id_map_get_id (this->map, SPA_CLOCK_URI);
this->node = audiotestsrc_node;
this->node.handle = handle;
this->clock = audiotestsrc_clock;
this->clock.handle = handle;
this->props[1].props.n_prop_info = PROP_ID_LAST;
this->props[1].props.prop_info = prop_info;
reset_audiotestsrc_props (&this->props[1]);