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

@ -141,10 +141,10 @@ spa_xv_sink_node_get_props (SpaNode *node,
{
SpaXvSink *this;
if (node == NULL || node->handle == NULL || props == NULL)
if (node == NULL || props == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
this = (SpaXvSink *) node->handle;
this = SPA_CONTAINER_OF (node, SpaXvSink, node);
memcpy (&this->props[0], &this->props[1], sizeof (this->props[1]));
*props = &this->props[0].props;
@ -160,10 +160,10 @@ spa_xv_sink_node_set_props (SpaNode *node,
SpaXvSinkProps *p;
SpaResult res;
if (node == NULL || node->handle == NULL)
if (node == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
this = (SpaXvSink *) node->handle;
this = SPA_CONTAINER_OF (node, SpaXvSink, node);
p = &this->props[1];
if (props == NULL) {
@ -182,10 +182,10 @@ spa_xv_sink_node_send_command (SpaNode *node,
{
SpaXvSink *this;
if (node == NULL || node->handle == NULL || command == NULL)
if (node == NULL || command == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
this = (SpaXvSink *) node->handle;
this = SPA_CONTAINER_OF (node, SpaXvSink, node);
switch (command->type) {
case SPA_NODE_COMMAND_INVALID:
@ -218,10 +218,10 @@ spa_xv_sink_node_set_event_callback (SpaNode *node,
{
SpaXvSink *this;
if (node == NULL || node->handle == NULL)
if (node == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
this = (SpaXvSink *) node->handle;
this = SPA_CONTAINER_OF (node, SpaXvSink, node);
this->event_cb = event;
this->user_data = user_data;
@ -236,7 +236,7 @@ spa_xv_sink_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)
@ -258,7 +258,7 @@ spa_xv_sink_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)
@ -295,10 +295,10 @@ spa_xv_sink_node_port_enum_formats (SpaNode *node,
SpaXvSink *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 = (SpaXvSink *) node->handle;
this = SPA_CONTAINER_OF (node, SpaXvSink, node);
if (!CHECK_PORT (this, direction, port_id))
return SPA_RESULT_INVALID_PORT;
@ -332,10 +332,10 @@ spa_xv_sink_node_port_set_format (SpaNode *node,
SpaFormat *f, *tf;
size_t fs;
if (node == NULL || node->handle == NULL || format == NULL)
if (node == NULL || format == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
this = (SpaXvSink *) node->handle;
this = SPA_CONTAINER_OF (node, SpaXvSink, node);
if (!CHECK_PORT (this, direction, port_id))
return SPA_RESULT_INVALID_PORT;
@ -377,10 +377,10 @@ spa_xv_sink_node_port_get_format (SpaNode *node,
{
SpaXvSink *this;
if (node == NULL || node->handle == NULL || format == NULL)
if (node == NULL || format == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
this = (SpaXvSink *) node->handle;
this = SPA_CONTAINER_OF (node, SpaXvSink, node);
if (!CHECK_PORT (this, direction, port_id))
return SPA_RESULT_INVALID_PORT;
@ -401,10 +401,10 @@ spa_xv_sink_node_port_get_info (SpaNode *node,
{
SpaXvSink *this;
if (node == NULL || node->handle == NULL || info == NULL)
if (node == NULL || info == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
this = (SpaXvSink *) node->handle;
this = SPA_CONTAINER_OF (node, SpaXvSink, node);
if (!CHECK_PORT (this, direction, port_id))
return SPA_RESULT_INVALID_PORT;
@ -462,10 +462,10 @@ spa_xv_sink_node_port_get_status (SpaNode *node,
{
SpaXvSink *this;
if (node == NULL || node->handle == NULL || status == NULL)
if (node == NULL || status == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
this = (SpaXvSink *) node->handle;
this = SPA_CONTAINER_OF (node, SpaXvSink, node);
if (!CHECK_PORT (this, direction, port_id))
return SPA_RESULT_INVALID_PORT;
@ -509,7 +509,6 @@ spa_xv_sink_node_port_push_event (SpaNode *node,
}
static const SpaNode xvsink_node = {
NULL,
sizeof (SpaNode),
NULL,
SPA_NODE_STATE_INIT,
@ -593,7 +592,6 @@ xv_sink_init (const SpaHandleFactory *factory,
this->uri.node = spa_id_map_get_id (this->map, SPA_NODE_URI);
this->node = xvsink_node;
this->node.handle = handle;
this->props[1].props.n_prop_info = PROP_ID_LAST;
this->props[1].props.prop_info = prop_info;
reset_xv_sink_props (&this->props[1]);