From b0f4be5fbcc0e16aafa5cae3f1bf93b1db7121b6 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Tue, 8 Jan 2019 11:53:36 +0100 Subject: [PATCH] fix more compile errors Avoid void * arithmetic Do explicit casts to target type to make c++ happy --- meson.build | 2 +- spa/include/spa/buffer/alloc.h | 30 ++++++++-------- spa/include/spa/buffer/meta.h | 6 ++-- spa/include/spa/buffer/type-info.h | 2 +- spa/include/spa/control/control.h | 1 + spa/include/spa/debug/buffer.h | 35 ++++++++++++------ spa/include/spa/debug/format.h | 32 ++++------------- spa/include/spa/debug/mem.h | 2 +- spa/include/spa/debug/pod.h | 16 ++++----- spa/include/spa/graph/graph.h | 8 ++--- spa/include/spa/param/audio/format-utils.h | 21 +++++++---- spa/include/spa/param/video/encoded.h | 4 --- spa/include/spa/pod/builder.h | 6 ++-- spa/include/spa/pod/compare.h | 24 ++++++++++--- spa/include/spa/pod/filter.h | 28 +++++++-------- spa/include/spa/pod/iter.h | 14 ++++---- spa/include/spa/utils/type-info.h | 36 ------------------- spa/include/spa/utils/type.h | 35 ++++++++++++++++++ spa/plugins/alsa/alsa-utils.c | 2 +- spa/plugins/audiomixer/audiomixer.c | 6 ++-- spa/plugins/bluez5/a2dp-sink.c | 2 +- src/gst/gstpipewireformat.c | 2 +- src/modules/module-client-node/client-node.c | 2 +- .../module-protocol-native/connection.c | 4 +-- src/pipewire/link.c | 4 +-- src/pipewire/mem.c | 10 +++--- 26 files changed, 175 insertions(+), 159 deletions(-) diff --git a/meson.build b/meson.build index 9c2f1f793..d3443ab55 100644 --- a/meson.build +++ b/meson.build @@ -40,7 +40,7 @@ pkgconfig = import('pkgconfig') cc = meson.get_compiler('c') if cc.get_id() == 'gcc' - add_global_arguments('-Wsign-compare', '-Wimplicit-fallthrough', language : 'c') + add_global_arguments('-Wsign-compare', '-Wimplicit-fallthrough', '-Wpointer-arith', language : 'c') endif cdata = configuration_data() diff --git a/spa/include/spa/buffer/alloc.h b/spa/include/spa/buffer/alloc.h index 1dbc334ba..308ae659c 100644 --- a/spa/include/spa/buffer/alloc.h +++ b/spa/include/spa/buffer/alloc.h @@ -48,9 +48,9 @@ struct spa_buffer_alloc_info { }; static inline int spa_buffer_alloc_fill_info(struct spa_buffer_alloc_info *info, - uint32_t n_metas, struct spa_meta metas[n_metas], - uint32_t n_datas, struct spa_data datas[n_datas], - uint32_t data_aligns[n_datas]) + uint32_t n_metas, struct spa_meta metas[], + uint32_t n_datas, struct spa_data datas[], + uint32_t data_aligns[]) { size_t size; uint32_t i; @@ -91,7 +91,7 @@ static inline struct spa_buffer * spa_buffer_alloc_layout(struct spa_buffer_alloc_info *info, void *skel_mem, void *data_mem) { - struct spa_buffer *b = skel_mem; + struct spa_buffer *b = (struct spa_buffer*)skel_mem; size_t size; uint32_t i; void **dp, *skel, *data; @@ -114,17 +114,17 @@ spa_buffer_alloc_layout(struct spa_buffer_alloc_info *info, struct spa_meta *m = &b->metas[i]; *m = info->metas[i]; m->data = *dp; - *dp += m->size; + *dp = SPA_MEMBER(*dp, m->size, void); } size = info->n_datas * sizeof(struct spa_chunk); if (SPA_FLAG_CHECK(info->flags, SPA_BUFFER_ALLOC_FLAG_INLINE_CHUNK)) { - cp = skel; - skel += size; + cp = (struct spa_chunk*)skel; + skel = SPA_MEMBER(skel, size, void); } else { - cp = data; - data += size; + cp = (struct spa_chunk*)data; + data = SPA_MEMBER(data, size, void); } if (SPA_FLAG_CHECK(info->flags, SPA_BUFFER_ALLOC_FLAG_INLINE_DATA)) @@ -139,7 +139,7 @@ spa_buffer_alloc_layout(struct spa_buffer_alloc_info *info, d->chunk = &cp[i]; if (!SPA_FLAG_CHECK(info->flags, SPA_BUFFER_ALLOC_FLAG_NO_DATA)) { d->data = *dp; - *dp += d->maxsize; + *dp = SPA_MEMBER(*dp, d->maxsize, void); } } return b; @@ -147,7 +147,7 @@ spa_buffer_alloc_layout(struct spa_buffer_alloc_info *info, static inline int spa_buffer_alloc_layout_array(struct spa_buffer_alloc_info *info, - uint32_t n_buffers, struct spa_buffer *buffers[n_buffers], + uint32_t n_buffers, struct spa_buffer *buffers[], void *skel_mem, void *data_mem) { uint32_t i; @@ -162,9 +162,9 @@ spa_buffer_alloc_layout_array(struct spa_buffer_alloc_info *info, static inline struct spa_buffer ** spa_buffer_alloc_array(uint32_t n_buffers, uint32_t flags, - uint32_t n_metas, struct spa_meta metas[n_metas], - uint32_t n_datas, struct spa_data datas[n_datas], - uint32_t data_aligns[n_datas]) + uint32_t n_metas, struct spa_meta metas[], + uint32_t n_datas, struct spa_data datas[], + uint32_t data_aligns[]) { struct spa_buffer **buffers; @@ -175,7 +175,7 @@ spa_buffer_alloc_array(uint32_t n_buffers, uint32_t flags, info.skel_size = SPA_ROUND_UP_N(info.skel_size, 16); - buffers = calloc(n_buffers, sizeof(struct spa_buffer *) + info.skel_size); + buffers = (struct spa_buffer **)calloc(n_buffers, sizeof(struct spa_buffer *) + info.skel_size); skel = SPA_MEMBER(buffers, sizeof(struct spa_buffer *) * n_buffers, void); diff --git a/spa/include/spa/buffer/meta.h b/spa/include/spa/buffer/meta.h index 86f0ad82f..f01d86929 100644 --- a/spa/include/spa/buffer/meta.h +++ b/spa/include/spa/buffer/meta.h @@ -60,8 +60,8 @@ struct spa_meta { }; #define spa_meta_first(m) ((m)->data) -#define spa_meta_end(m) ((m)->data + (m)->size) -#define spa_meta_check(p,m) ((void*)(p) + sizeof(*p) <= spa_meta_end(m)) +#define spa_meta_end(m) SPA_MEMBER((m)->data,(m)->size,void) +#define spa_meta_check(p,m) (SPA_MEMBER(p,sizeof(*p),void) <= spa_meta_end(m)) /** * Describes essential buffer header metadata such as flags and @@ -89,7 +89,7 @@ struct spa_meta_region { #define spa_meta_region_is_valid(m) ((m)->region.size.width != 0 && (m)->region.size.height != 0) #define spa_meta_region_for_each(pos,meta) \ - for (pos = spa_meta_first(meta); \ + for (pos = (__typeof(pos))spa_meta_first(meta); \ spa_meta_check(pos, meta); \ (pos)++) diff --git a/spa/include/spa/buffer/type-info.h b/spa/include/spa/buffer/type-info.h index 692f185ff..0b6485b15 100644 --- a/spa/include/spa/buffer/type-info.h +++ b/spa/include/spa/buffer/type-info.h @@ -31,7 +31,7 @@ extern "C" { #include #include -#include +#include #define SPA_TYPE__Buffer SPA_TYPE_POINTER_BASE "Buffer" #define SPA_TYPE_BUFFER_BASE SPA_TYPE__Buffer ":" diff --git a/spa/include/spa/control/control.h b/spa/include/spa/control/control.h index a8553cfde..2b9129155 100644 --- a/spa/include/spa/control/control.h +++ b/spa/include/spa/control/control.h @@ -41,6 +41,7 @@ enum spa_control_type { SPA_CONTROL_Invalid, SPA_CONTROL_Properties, SPA_CONTROL_Midi, + SPA_CONTROL_LAST, /**< not part of ABI */ }; #ifdef __cplusplus diff --git a/spa/include/spa/debug/buffer.h b/spa/include/spa/debug/buffer.h index dbeb015c0..d88916c9c 100644 --- a/spa/include/spa/debug/buffer.h +++ b/spa/include/spa/debug/buffer.h @@ -29,7 +29,8 @@ extern "C" { #endif -#include +#include +#include #include #ifndef spa_debug @@ -38,10 +39,9 @@ extern "C" { static inline int spa_debug_buffer(int indent, const struct spa_buffer *buffer) { - int i; + uint32_t i; spa_debug("%*s" "struct spa_buffer %p:", indent, "", buffer); - spa_debug("%*s" " id: %08X", indent, "", buffer->id); spa_debug("%*s" " n_metas: %u (at %p)", indent, "", buffer->n_metas, buffer->metas); for (i = 0; i < buffer->n_metas; i++) { struct spa_meta *m = &buffer->metas[i]; @@ -54,7 +54,7 @@ static inline int spa_debug_buffer(int indent, const struct spa_buffer *buffer) switch (m->type) { case SPA_META_Header: { - struct spa_meta_header *h = m->data; + struct spa_meta_header *h = (struct spa_meta_header*)m->data; spa_debug("%*s" " struct spa_meta_header:", indent, ""); spa_debug("%*s" " flags: %08x", indent, "", h->flags); spa_debug("%*s" " seq: %u", indent, "", h->seq); @@ -64,15 +64,30 @@ static inline int spa_debug_buffer(int indent, const struct spa_buffer *buffer) } case SPA_META_VideoCrop: { - struct spa_meta_video_crop *h = m->data; - spa_debug("%*s" " struct spa_meta_video_crop:", indent, ""); - spa_debug("%*s" " x: %d", indent, "", h->x); - spa_debug("%*s" " y: %d", indent, "", h->y); - spa_debug("%*s" " width: %d", indent, "", h->width); - spa_debug("%*s" " height: %d", indent, "", h->height); + struct spa_meta_region *h = (struct spa_meta_region*)m->data; + spa_debug("%*s" " struct spa_meta_region:", indent, ""); + spa_debug("%*s" " x: %d", indent, "", h->region.position.x); + spa_debug("%*s" " y: %d", indent, "", h->region.position.y); + spa_debug("%*s" " width: %d", indent, "", h->region.size.width); + spa_debug("%*s" " height: %d", indent, "", h->region.size.height); break; } case SPA_META_VideoDamage: + { + struct spa_meta_region *h; + spa_meta_region_for_each(h, m) { + spa_debug("%*s" " struct spa_meta_region:", indent, ""); + spa_debug("%*s" " x: %d", indent, "", h->region.position.x); + spa_debug("%*s" " y: %d", indent, "", h->region.position.y); + spa_debug("%*s" " width: %d", indent, "", h->region.size.width); + spa_debug("%*s" " height: %d", indent, "", h->region.size.height); + } + break; + } + case SPA_META_Bitmap: + break; + case SPA_META_Cursor: + break; default: spa_debug("%*s" " Unknown:", indent, ""); spa_debug_mem(5, m->data, m->size); diff --git a/spa/include/spa/debug/format.h b/spa/include/spa/debug/format.h index db0bea090..ecb8d7190 100644 --- a/spa/include/spa/debug/format.h +++ b/spa/include/spa/debug/format.h @@ -74,13 +74,13 @@ spa_debug_format_value(const struct spa_type_info *info, break; case SPA_TYPE_Rectangle: { - struct spa_rectangle *r = body; + struct spa_rectangle *r = (struct spa_rectangle *)body; fprintf(stderr, "%" PRIu32 "x%" PRIu32, r->width, r->height); break; } case SPA_TYPE_Fraction: { - struct spa_fraction *f = body; + struct spa_fraction *f = (struct spa_fraction *)body; fprintf(stderr, "%" PRIu32 "/%" PRIu32, f->num, f->denom); break; } @@ -93,7 +93,7 @@ spa_debug_format_value(const struct spa_type_info *info, case SPA_TYPE_Array: { void *p; - struct spa_pod_array_body *b = body; + struct spa_pod_array_body *b = (struct spa_pod_array_body *)body; int i = 0; fprintf(stderr, "< "); SPA_POD_ARRAY_BODY_FOREACH(b, size, p) { @@ -118,27 +118,6 @@ static inline int spa_debug_format(int indent, const char *media_subtype; struct spa_pod_prop *prop; uint32_t mtype, mstype; - const char *pod_type_names[] = { - [SPA_TYPE_None] = "none", - [SPA_TYPE_Bool] = "bool", - [SPA_TYPE_Id] = "id", - [SPA_TYPE_Int] = "int", - [SPA_TYPE_Long] = "long", - [SPA_TYPE_Float] = "float", - [SPA_TYPE_Double] = "double", - [SPA_TYPE_String] = "string", - [SPA_TYPE_Bytes] = "bytes", - [SPA_TYPE_Rectangle] = "rectangle", - [SPA_TYPE_Fraction] = "fraction", - [SPA_TYPE_Bitmap] = "bitmap", - [SPA_TYPE_Array] = "array", - [SPA_TYPE_Struct] = "struct", - [SPA_TYPE_Object] = "object", - [SPA_TYPE_Pointer] = "pointer", - [SPA_TYPE_Fd] = "fd", - [SPA_TYPE_Choice] = "choice", - [SPA_TYPE_Pod] = "pod" - }; if (info == NULL) info = spa_type_format; @@ -173,12 +152,15 @@ static inline int spa_debug_format(int indent, size = val->size; vals = SPA_POD_BODY(val); + if (type < SPA_TYPE_None || type >= SPA_TYPE_LAST) + continue; + ti = spa_debug_type_find(info, prop->key); key = ti ? ti->name : NULL; fprintf(stderr, "%*s %16s : (%s) ", indent, "", key ? rindex(key, ':') + 1 : "unknown", - pod_type_names[type]); + rindex(spa_types[type].name, ':') + 1); if (choice == SPA_CHOICE_None) { spa_debug_format_value(ti->values, type, vals, size); diff --git a/spa/include/spa/debug/mem.h b/spa/include/spa/debug/mem.h index aa3564689..4f0eb10b5 100644 --- a/spa/include/spa/debug/mem.h +++ b/spa/include/spa/debug/mem.h @@ -37,7 +37,7 @@ extern "C" { static inline int spa_debug_mem(int indent, const void *data, size_t size) { - const uint8_t *t = data; + const uint8_t *t = (const uint8_t*)data; char buffer[512]; size_t i; int pos = 0; diff --git a/spa/include/spa/debug/pod.h b/spa/include/spa/debug/pod.h index 149d2f207..891d41e49 100644 --- a/spa/include/spa/debug/pod.h +++ b/spa/include/spa/debug/pod.h @@ -137,20 +137,20 @@ spa_debug_pod_value(int indent, const struct spa_type_info *info, break; case SPA_TYPE_Pointer: { - struct spa_pod_pointer_body *b = body; + struct spa_pod_pointer_body *b = (struct spa_pod_pointer_body *)body; spa_debug("%*s" "Pointer %s %p", indent, "", spa_debug_type_find_name(SPA_TYPE_ROOT, b->type), b->value); break; } case SPA_TYPE_Rectangle: { - struct spa_rectangle *r = body; + struct spa_rectangle *r = (struct spa_rectangle *)body; spa_debug("%*s" "Rectangle %dx%d", indent, "", r->width, r->height); break; } case SPA_TYPE_Fraction: { - struct spa_fraction *f = body; + struct spa_fraction *f = (struct spa_fraction *)body; spa_debug("%*s" "Fraction %d/%d", indent, "", f->num, f->denom); break; } @@ -159,7 +159,7 @@ spa_debug_pod_value(int indent, const struct spa_type_info *info, break; case SPA_TYPE_Array: { - struct spa_pod_array_body *b = body; + struct spa_pod_array_body *b = (struct spa_pod_array_body *)body; void *p; const struct spa_type_info *ti = spa_debug_type_find(SPA_TYPE_ROOT, b->child.type); @@ -172,7 +172,7 @@ spa_debug_pod_value(int indent, const struct spa_type_info *info, } case SPA_TYPE_Choice: { - struct spa_pod_choice_body *b = body; + struct spa_pod_choice_body *b = (struct spa_pod_choice_body *)body; void *p; const struct spa_type_info *ti = spa_debug_type_find(spa_type_choice, b->type); @@ -185,7 +185,7 @@ spa_debug_pod_value(int indent, const struct spa_type_info *info, } case SPA_TYPE_Struct: { - struct spa_pod *b = body, *p; + struct spa_pod *b = (struct spa_pod *)body, *p; spa_debug("%*s" "Struct: size %d", indent, "", size); SPA_POD_FOREACH(b, size, p) spa_debug_pod_value(indent + 2, info, p->type, SPA_POD_BODY(p), p->size); @@ -193,7 +193,7 @@ spa_debug_pod_value(int indent, const struct spa_type_info *info, } case SPA_TYPE_Object: { - struct spa_pod_object_body *b = body; + struct spa_pod_object_body *b = (struct spa_pod_object_body *)body; struct spa_pod_prop *p; const struct spa_type_info *ti, *ii; @@ -221,7 +221,7 @@ spa_debug_pod_value(int indent, const struct spa_type_info *info, } case SPA_TYPE_Sequence: { - struct spa_pod_sequence_body *b = body; + struct spa_pod_sequence_body *b = (struct spa_pod_sequence_body *)body; const struct spa_type_info *ti, *ii; struct spa_pod_control *c; diff --git a/spa/include/spa/graph/graph.h b/spa/include/spa/graph/graph.h index 4d930ed10..196c15e40 100644 --- a/spa/include/spa/graph/graph.h +++ b/spa/include/spa/graph/graph.h @@ -132,14 +132,14 @@ struct spa_graph_port { static inline int spa_graph_link_signal_node(void *data) { - struct spa_graph_node *node = data; + struct spa_graph_node *node = (struct spa_graph_node *)data; spa_debug("node %p call process", node); return spa_graph_node_process(node); } static inline int spa_graph_link_signal_graph(void *data) { - struct spa_graph_node *node = data; + struct spa_graph_node *node = (struct spa_graph_node *)data; if (node->graph) spa_graph_finish(node->graph); return 0; @@ -299,7 +299,7 @@ spa_graph_port_unlink(struct spa_graph_port *port) static inline int spa_graph_node_impl_process(void *data, struct spa_graph_node *node) { - struct spa_node *n = data; + struct spa_node *n = (struct spa_node *)data; struct spa_graph_state *state = node->state; spa_debug("node %p: process state %p: %d, node %p", node, state, state->status, n); @@ -312,7 +312,7 @@ static inline int spa_graph_node_impl_process(void *data, struct spa_graph_node static inline int spa_graph_node_impl_reuse_buffer(void *data, struct spa_graph_node *node, uint32_t port_id, uint32_t buffer_id) { - struct spa_node *n = data; + struct spa_node *n = (struct spa_node *)data; return spa_node_port_reuse_buffer(n, port_id, buffer_id); } diff --git a/spa/include/spa/param/audio/format-utils.h b/spa/include/spa/param/audio/format-utils.h index fef80db71..aa581ac71 100644 --- a/spa/include/spa/param/audio/format-utils.h +++ b/spa/include/spa/param/audio/format-utils.h @@ -48,7 +48,7 @@ spa_format_audio_raw_parse(const struct spa_pod *format, struct spa_audio_info_r ":", SPA_FORMAT_AUDIO_position, "?P", &position, NULL); if (position && position->type == SPA_TYPE_Array && SPA_POD_ARRAY_TYPE(position) == SPA_TYPE_Id) { - uint32_t *values = SPA_POD_ARRAY_VALUES(position); + uint32_t *values = (uint32_t*)SPA_POD_ARRAY_VALUES(position); uint32_t n_values = SPA_MIN(SPA_POD_ARRAY_N_VALUES(position), SPA_AUDIO_MAX_CHANNELS); memcpy(info->position, values, n_values * sizeof(uint32_t)); } @@ -61,13 +61,19 @@ spa_format_audio_raw_parse(const struct spa_pod *format, struct spa_audio_info_r static inline struct spa_pod * spa_format_audio_raw_build(struct spa_pod_builder *builder, uint32_t id, struct spa_audio_info_raw *info) { + const struct spa_pod_id media_type = SPA_POD_Id(SPA_MEDIA_TYPE_audio); + const struct spa_pod_id media_subtype = SPA_POD_Id(SPA_MEDIA_SUBTYPE_raw); + const struct spa_pod_id format = SPA_POD_Id(info->format); + const struct spa_pod_int rate = SPA_POD_Int(info->rate); + const struct spa_pod_int channels = SPA_POD_Int(info->channels); + spa_pod_builder_push_object(builder, SPA_TYPE_OBJECT_Format, id); spa_pod_builder_props(builder, - SPA_FORMAT_mediaType, &SPA_POD_Id(SPA_MEDIA_TYPE_audio), - SPA_FORMAT_mediaSubtype, &SPA_POD_Id(SPA_MEDIA_SUBTYPE_raw), - SPA_FORMAT_AUDIO_format, &SPA_POD_Id(info->format), - SPA_FORMAT_AUDIO_rate, &SPA_POD_Int(info->rate), - SPA_FORMAT_AUDIO_channels, &SPA_POD_Int(info->channels), + SPA_FORMAT_mediaType, &media_type, + SPA_FORMAT_mediaSubtype, &media_subtype, + SPA_FORMAT_AUDIO_format, &format, + SPA_FORMAT_AUDIO_rate, &rate, + SPA_FORMAT_AUDIO_channels, &channels, 0); if (!SPA_FLAG_CHECK(info->flags, SPA_AUDIO_FLAG_UNPOSITIONED)) { @@ -75,7 +81,8 @@ spa_format_audio_raw_build(struct spa_pod_builder *builder, uint32_t id, struct spa_pod_builder_array(builder, sizeof(uint32_t), SPA_TYPE_Id, info->channels, info->position); } - return spa_pod_builder_pop(builder); + + return (struct spa_pod*)spa_pod_builder_pop(builder); } diff --git a/spa/include/spa/param/video/encoded.h b/spa/include/spa/param/video/encoded.h index 88270efb3..529a9a822 100644 --- a/spa/include/spa/param/video/encoded.h +++ b/spa/include/spa/param/video/encoded.h @@ -29,11 +29,7 @@ extern "C" { #endif -struct spa_video_info_h264; -struct spa_video_info_mjpg; - #include -#include enum spa_h264_stream_format { SPA_H264_STREAM_FORMAT_UNKNOWN = 0, diff --git a/spa/include/spa/pod/builder.h b/spa/include/spa/pod/builder.h index 6e9d27fc2..3a35a7dfa 100644 --- a/spa/include/spa/pod/builder.h +++ b/spa/include/spa/pod/builder.h @@ -232,7 +232,7 @@ static inline uint32_t spa_pod_builder_bool(struct spa_pod_builder *builder, boo return spa_pod_builder_primitive(builder, &p.pod); } -#define SPA_POD_Id(val) (struct spa_pod_id){ { sizeof(uint32_t), SPA_TYPE_Id }, val, 0 } +#define SPA_POD_Id(val) (struct spa_pod_id){ { sizeof(uint32_t), SPA_TYPE_Id }, (uint32_t)val, 0 } static inline uint32_t spa_pod_builder_id(struct spa_pod_builder *builder, uint32_t val) { @@ -240,7 +240,7 @@ static inline uint32_t spa_pod_builder_id(struct spa_pod_builder *builder, uint3 return spa_pod_builder_primitive(builder, &p.pod); } -#define SPA_POD_Int(val) (struct spa_pod_int){ { sizeof(uint32_t), SPA_TYPE_Int }, val, 0 } +#define SPA_POD_Int(val) (struct spa_pod_int){ { sizeof(int32_t), SPA_TYPE_Int }, (int32_t)val, 0 } static inline uint32_t spa_pod_builder_int(struct spa_pod_builder *builder, int32_t val) { @@ -248,7 +248,7 @@ static inline uint32_t spa_pod_builder_int(struct spa_pod_builder *builder, int3 return spa_pod_builder_primitive(builder, &p.pod); } -#define SPA_POD_Long(val) (struct spa_pod_long){ { sizeof(uint64_t), SPA_TYPE_Long }, val } +#define SPA_POD_Long(val) (struct spa_pod_long){ { sizeof(int64_t), SPA_TYPE_Long }, (int64_t)val } static inline uint32_t spa_pod_builder_long(struct spa_pod_builder *builder, int64_t val) { diff --git a/spa/include/spa/pod/compare.h b/spa/include/spa/pod/compare.h index 9d4c03594..269114037 100644 --- a/spa/include/spa/pod/compare.h +++ b/spa/include/spa/pod/compare.h @@ -22,6 +22,14 @@ * DEALINGS IN THE SOFTWARE. */ +#ifndef __SPA_POD_COMPARE_H__ +#define __SPA_POD_COMPARE_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include #include #include #include @@ -49,7 +57,7 @@ static inline int spa_pod_compare_value(uint32_t type, const void *r1, const voi case SPA_TYPE_Double: return *(double *) r1 - *(double *) r2; case SPA_TYPE_String: - return strcmp(r1, r2); + return strcmp((char *)r1, (char *)r2); case SPA_TYPE_Rectangle: { const struct spa_rectangle *rec1 = (struct spa_rectangle *) r1, @@ -106,9 +114,9 @@ static inline int spa_pod_compare(const struct spa_pod *pod1, const struct spa_pod *p1, *p2; size_t p1s, p2s; - p1 = SPA_POD_BODY_CONST(pod1); + p1 = (const struct spa_pod*)SPA_POD_BODY_CONST(pod1); p1s = SPA_POD_BODY_SIZE(pod1); - p2 = SPA_POD_BODY_CONST(pod2); + p2 = (const struct spa_pod*)SPA_POD_BODY_CONST(pod2); p2s = SPA_POD_BODY_SIZE(pod2); while (true) { @@ -119,8 +127,8 @@ static inline int spa_pod_compare(const struct spa_pod *pod1, if ((res = spa_pod_compare(p1, p2)) != 0) return res; - p1 = spa_pod_next(p1); - p2 = spa_pod_next(p2); + p1 = (const struct spa_pod*)spa_pod_next(p1); + p2 = (const struct spa_pod*)spa_pod_next(p2); } break; } @@ -153,3 +161,9 @@ static inline int spa_pod_compare(const struct spa_pod *pod1, } return res; } + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/spa/include/spa/pod/filter.h b/spa/include/spa/pod/filter.h index 6a38f372d..a8240d927 100644 --- a/spa/include/spa/pod/filter.h +++ b/spa/include/spa/pod/filter.h @@ -125,7 +125,7 @@ spa_pod_filter_prop(struct spa_pod_builder *b, /* start with copying the property */ spa_pod_builder_prop(b, p1->key, 0); - nc = spa_pod_builder_deref(b, spa_pod_builder_push_choice(b, 0, 0)); + nc = (struct spa_pod_choice*)spa_pod_builder_deref(b, spa_pod_builder_push_choice(b, 0, 0)); /* default value */ spa_pod_builder_primitive(b, v1); @@ -136,8 +136,8 @@ spa_pod_filter_prop(struct spa_pod_builder *b, (p1c == SPA_CHOICE_Enum && p2c == SPA_CHOICE_Enum)) { int n_copied = 0; /* copy all equal values but don't copy the default value again */ - for (j = 0, a1 = alt1; j < nalt1; j++, a1 += size) { - for (k = 0, a2 = alt2; k < nalt2; k++, a2 += size) { + for (j = 0, a1 = alt1; j < nalt1; j++, a1 = SPA_MEMBER(a1, size, void)) { + for (k = 0, a2 = alt2; k < nalt2; k++, a2 = SPA_MEMBER(a2,size,void)) { if (spa_pod_compare_value(type, a1, a2) == 0) { if (p1c == SPA_CHOICE_Enum || j > 0) spa_pod_builder_raw(b, a1, size); @@ -154,10 +154,10 @@ spa_pod_filter_prop(struct spa_pod_builder *b, (p1c == SPA_CHOICE_Enum && p2c == SPA_CHOICE_Range)) { int n_copied = 0; /* copy all values inside the range */ - for (j = 0, a1 = alt1, a2 = alt2; j < nalt1; j++, a1 += size) { + for (j = 0, a1 = alt1, a2 = alt2; j < nalt1; j++, a1 = SPA_MEMBER(a1,size,void)) { if (spa_pod_compare_value(type, a1, a2) < 0) continue; - if (spa_pod_compare_value(type, a1, a2 + size) > 0) + if (spa_pod_compare_value(type, a1, SPA_MEMBER(a2,size,void)) > 0) continue; spa_pod_builder_raw(b, a1, size); n_copied++; @@ -176,10 +176,10 @@ spa_pod_filter_prop(struct spa_pod_builder *b, (p1c == SPA_CHOICE_Range && p2c == SPA_CHOICE_Enum)) { int n_copied = 0; /* copy all values inside the range */ - for (k = 0, a1 = alt1, a2 = alt2; k < nalt2; k++, a2 += size) { + for (k = 0, a1 = alt1, a2 = alt2; k < nalt2; k++, a2 = SPA_MEMBER(a2,size,void)) { if (spa_pod_compare_value(type, a2, a1) < 0) continue; - if (spa_pod_compare_value(type, a2, a1 + size) > 0) + if (spa_pod_compare_value(type, a2, SPA_MEMBER(a1,size,void)) > 0) continue; spa_pod_builder_raw(b, a2, size); n_copied++; @@ -195,8 +195,8 @@ spa_pod_filter_prop(struct spa_pod_builder *b, else spa_pod_builder_raw(b, alt1, size); - alt1 += size; - alt2 += size; + alt1 = SPA_MEMBER(alt1,size,void); + alt2 = SPA_MEMBER(alt2,size,void); if (spa_pod_compare_value(type, alt1, alt2) < 0) spa_pod_builder_raw(b, alt1, size); @@ -304,9 +304,9 @@ static inline int spa_pod_filter_part(struct spa_pod_builder *b, filter_offset = sizeof(struct spa_pod_struct); spa_pod_builder_push_struct(b); res = spa_pod_filter_part(b, - SPA_MEMBER(pp,filter_offset,void), + SPA_MEMBER(pp,filter_offset,const struct spa_pod), SPA_POD_SIZE(pp) - filter_offset, - SPA_MEMBER(pf,filter_offset,void), + SPA_MEMBER(pf,filter_offset,const struct spa_pod), SPA_POD_SIZE(pf) - filter_offset); spa_pod_builder_pop(b); do_advance = true; @@ -329,7 +329,7 @@ static inline int spa_pod_filter_part(struct spa_pod_builder *b, if (do_copy) spa_pod_builder_raw_padded(b, pp, SPA_POD_SIZE(pp)); if (do_advance) { - pf = spa_pod_next(pf); + pf = (const struct spa_pod*)spa_pod_next(pf); if (!spa_pod_is_inside(filter, filter_size, pf)) pf = NULL; } @@ -352,7 +352,7 @@ spa_pod_filter(struct spa_pod_builder *b, spa_return_val_if_fail(b != NULL, -EINVAL); if (filter == NULL) { - *result = spa_pod_builder_deref(b, + *result = (struct spa_pod*)spa_pod_builder_deref(b, spa_pod_builder_raw_padded(b, pod, SPA_POD_SIZE(pod))); return 0; } @@ -361,7 +361,7 @@ spa_pod_filter(struct spa_pod_builder *b, if ((res = spa_pod_filter_part(b, pod, SPA_POD_SIZE(pod), filter, SPA_POD_SIZE(filter))) < 0) spa_pod_builder_reset(b, &state); else - *result = spa_pod_builder_deref(b, state.offset); + *result = (struct spa_pod*)spa_pod_builder_deref(b, state.offset); return res; } diff --git a/spa/include/spa/pod/iter.h b/spa/include/spa/pod/iter.h index a58af92f8..67f0612c4 100644 --- a/spa/include/spa/pod/iter.h +++ b/spa/include/spa/pod/iter.h @@ -108,19 +108,19 @@ static inline struct spa_pod_control *spa_pod_control_next(const struct spa_pod_ } #define SPA_POD_ARRAY_BODY_FOREACH(body, _size, iter) \ - for ((iter) = SPA_MEMBER((body), sizeof(struct spa_pod_array_body), __typeof__(*(iter))); \ - (iter) < SPA_MEMBER((body), (_size), __typeof__(*(iter))); \ - (iter) = SPA_MEMBER((iter), (body)->child.size, __typeof__(*(iter)))) + for ((iter) = (__typeof__(iter))SPA_MEMBER((body), sizeof(struct spa_pod_array_body), void); \ + (iter) < (__typeof__(iter))SPA_MEMBER((body), (_size), void); \ + (iter) = (__typeof__(iter))SPA_MEMBER((iter), (body)->child.size, void)) #define SPA_POD_CHOICE_BODY_FOREACH(body, _size, iter) \ - for ((iter) = SPA_MEMBER((body), sizeof(struct spa_pod_choice_body), __typeof__(*(iter))); \ - (iter) < SPA_MEMBER((body), (_size), __typeof__(*(iter))); \ - (iter) = SPA_MEMBER((iter), (body)->child.size, __typeof__(*(iter)))) + for ((iter) = (__typeof__(iter))SPA_MEMBER((body), sizeof(struct spa_pod_choice_body), void); \ + (iter) < (__typeof__(iter))SPA_MEMBER((body), (_size), void); \ + (iter) = (__typeof__(iter))SPA_MEMBER((iter), (body)->child.size, void)) #define SPA_POD_FOREACH(pod, size, iter) \ for ((iter) = (pod); \ spa_pod_is_inside(pod, size, iter); \ - (iter) = spa_pod_next(iter)) + (iter) = (__typeof__(iter))spa_pod_next(iter)) #define SPA_POD_STRUCT_FOREACH(obj, iter) \ SPA_POD_FOREACH(SPA_POD_BODY(obj), SPA_POD_BODY_SIZE(obj), iter) diff --git a/spa/include/spa/utils/type-info.h b/spa/include/spa/utils/type-info.h index b68ed19db..9afcc772e 100644 --- a/spa/include/spa/utils/type-info.h +++ b/spa/include/spa/utils/type-info.h @@ -40,42 +40,6 @@ static inline bool spa_type_is_a(const char *type, const char *parent) return type != NULL && parent != NULL && strncmp(type, parent, strlen(parent)) == 0; } -struct spa_type_info { - uint32_t type; - const char *name; - uint32_t parent; - const struct spa_type_info *values; -}; - -#define SPA_TYPE_BASE "Spa:" - -#define SPA_TYPE__Flags SPA_TYPE_BASE "Flags" -#define SPA_TYPE_FLAGS_BASE SPA_TYPE__Flags ":" - -#define SPA_TYPE__Enum SPA_TYPE_BASE "Enum" -#define SPA_TYPE_ENUM_BASE SPA_TYPE__Enum ":" - -#define SPA_TYPE__Pod SPA_TYPE_BASE "Pod" -#define SPA_TYPE_POD_BASE SPA_TYPE__Pod ":" - -#define SPA_TYPE__Struct SPA_TYPE_POD_BASE "Struct" -#define SPA_TYPE_STRUCT_BASE SPA_TYPE__Struct ":" - -#define SPA_TYPE__Object SPA_TYPE_POD_BASE "Object" -#define SPA_TYPE_OBJECT_BASE SPA_TYPE__Object ":" - -#define SPA_TYPE__Pointer SPA_TYPE_BASE "Pointer" -#define SPA_TYPE_POINTER_BASE SPA_TYPE__Pointer ":" - -#define SPA_TYPE__Interface SPA_TYPE_POINTER_BASE "Interface" -#define SPA_TYPE_INTERFACE_BASE SPA_TYPE__Interface ":" - -#define SPA_TYPE__Event SPA_TYPE_OBJECT_BASE "Event" -#define SPA_TYPE_EVENT_BASE SPA_TYPE__Event ":" - -#define SPA_TYPE__Command SPA_TYPE_OBJECT_BASE "Command" -#define SPA_TYPE_COMMAND_BASE SPA_TYPE__Command ":" - #include /* base for parameter object enumerations */ diff --git a/spa/include/spa/utils/type.h b/spa/include/spa/utils/type.h index b92a0c8e3..437e7be55 100644 --- a/spa/include/spa/utils/type.h +++ b/spa/include/spa/utils/type.h @@ -110,6 +110,41 @@ enum { SPA_TYPE_VENDOR_Other = 0x7f000000, }; +#define SPA_TYPE_BASE "Spa:" + +#define SPA_TYPE__Flags SPA_TYPE_BASE "Flags" +#define SPA_TYPE_FLAGS_BASE SPA_TYPE__Flags ":" + +#define SPA_TYPE__Enum SPA_TYPE_BASE "Enum" +#define SPA_TYPE_ENUM_BASE SPA_TYPE__Enum ":" + +#define SPA_TYPE__Pod SPA_TYPE_BASE "Pod" +#define SPA_TYPE_POD_BASE SPA_TYPE__Pod ":" + +#define SPA_TYPE__Struct SPA_TYPE_POD_BASE "Struct" +#define SPA_TYPE_STRUCT_BASE SPA_TYPE__Struct ":" + +#define SPA_TYPE__Object SPA_TYPE_POD_BASE "Object" +#define SPA_TYPE_OBJECT_BASE SPA_TYPE__Object ":" + +#define SPA_TYPE__Pointer SPA_TYPE_BASE "Pointer" +#define SPA_TYPE_POINTER_BASE SPA_TYPE__Pointer ":" + +#define SPA_TYPE__Interface SPA_TYPE_POINTER_BASE "Interface" +#define SPA_TYPE_INTERFACE_BASE SPA_TYPE__Interface ":" + +#define SPA_TYPE__Event SPA_TYPE_OBJECT_BASE "Event" +#define SPA_TYPE_EVENT_BASE SPA_TYPE__Event ":" + +#define SPA_TYPE__Command SPA_TYPE_OBJECT_BASE "Command" +#define SPA_TYPE_COMMAND_BASE SPA_TYPE__Command ":" + +struct spa_type_info { + uint32_t type; + const char *name; + uint32_t parent; + const struct spa_type_info *values; +}; #ifdef __cplusplus } /* extern "C" */ diff --git a/spa/plugins/alsa/alsa-utils.c b/spa/plugins/alsa/alsa-utils.c index dfb557a85..80c690f69 100644 --- a/spa/plugins/alsa/alsa-utils.c +++ b/spa/plugins/alsa/alsa-utils.c @@ -801,7 +801,7 @@ push_frames(struct state *state, l0 = SPA_MIN(n_bytes, d[0].maxsize - offs); l1 = n_bytes - l0; - memcpy(d[0].data + offs, src, l0); + memcpy(SPA_MEMBER(d[0].data, offs, void), src, l0); if (l1 > 0) memcpy(d[0].data, src + l0, l1); diff --git a/spa/plugins/audiomixer/audiomixer.c b/spa/plugins/audiomixer/audiomixer.c index 2f26cfd21..5a5eb2d4d 100644 --- a/spa/plugins/audiomixer/audiomixer.c +++ b/spa/plugins/audiomixer/audiomixer.c @@ -760,7 +760,7 @@ add_port_data(struct impl *this, void *out, size_t outsize, struct port *port, i if (layer == 0) { this->clear(out, len1); if (len2 > 0) - this->clear(out + len1, len2); + this->clear(SPA_MEMBER(out, len1, void), len2); } } else if (volume < 0.999 || volume > 1.001) { @@ -768,14 +768,14 @@ add_port_data(struct impl *this, void *out, size_t outsize, struct port *port, i mix(out, SPA_MEMBER(data, offset, void), volume, len1); if (len2 > 0) - mix(out + len1, data, volume, len2); + mix(SPA_MEMBER(out, len1, void), data, volume, len2); } else { mix_func_t mix = layer == 0 ? this->copy : this->add; mix(out, SPA_MEMBER(data, offset, void), len1); if (len2 > 0) - mix(out + len1, data, len2); + mix(SPA_MEMBER(out, len1, void), data, len2); } port->queued_bytes -= outsize; diff --git a/spa/plugins/bluez5/a2dp-sink.c b/spa/plugins/bluez5/a2dp-sink.c index 1d01f0f79..eaadab868 100644 --- a/spa/plugins/bluez5/a2dp-sink.c +++ b/spa/plugins/bluez5/a2dp-sink.c @@ -413,7 +413,7 @@ static int add_data(struct impl *this, const void *data, int size) if (processed < 0) return 0; - data += processed; + data = SPA_MEMBER(data, processed, void); size -= processed; total += processed; } diff --git a/src/gst/gstpipewireformat.c b/src/gst/gstpipewireformat.c index 8e4439a50..7eccebd6b 100644 --- a/src/gst/gstpipewireformat.c +++ b/src/gst/gstpipewireformat.c @@ -529,7 +529,7 @@ write_pod (struct spa_pod_builder *b, const void *data, uint32_t size) if (b->data == NULL) return -1; } - memcpy (b->data + ref, data, size); + memcpy (SPA_MEMBER(b->data, ref, void), data, size); return ref; } diff --git a/src/modules/module-client-node/client-node.c b/src/modules/module-client-node/client-node.c index ecb6f0692..2cd7d934c 100644 --- a/src/modules/module-client-node/client-node.c +++ b/src/modules/module-client-node/client-node.c @@ -852,7 +852,7 @@ do_port_use_buffers(struct impl *impl, mb[i].buffer = &b->buffer; mb[i].mem_id = b->memid; - mb[i].offset = SPA_PTRDIFF(baseptr, mem->ptr + mem->offset); + mb[i].offset = SPA_PTRDIFF(baseptr, SPA_MEMBER(mem->ptr, mem->offset, void)); mb[i].size = data_size; for (j = 0; j < buffers[i]->n_metas; j++) diff --git a/src/modules/module-protocol-native/connection.c b/src/modules/module-protocol-native/connection.c index ba303cb32..6ec19dcde 100644 --- a/src/modules/module-protocol-native/connection.c +++ b/src/modules/module-protocol-native/connection.c @@ -361,7 +361,7 @@ static uint32_t write_pod(struct spa_pod_builder *b, const void *data, uint32_t b->size = SPA_ROUND_UP_N(ref + size, 4096); b->data = begin_write(&impl->this, b->size); } - memcpy(b->data + ref, data, size); + memcpy(SPA_MEMBER(b->data, ref, void), data, size); return ref; } @@ -493,7 +493,7 @@ int pw_protocol_native_connection_flush(struct pw_protocol_native_connection *co outfds); size -= sent; - data += sent; + data = SPA_MEMBER(data, sent, void); n_fds -= outfds; fds += outfds; } diff --git a/src/pipewire/link.c b/src/pipewire/link.c index afa3e01d9..2d96dee2a 100644 --- a/src/pipewire/link.c +++ b/src/pipewire/link.c @@ -491,7 +491,7 @@ static int alloc_buffers(struct pw_link *this, m->type = metas[j].type; m->size = metas[j].size; m->data = p; - p += m->size; + p = SPA_MEMBER(p, m->size, void); } /* pointer to data structure */ b->n_datas = n_datas; @@ -514,7 +514,7 @@ static int alloc_buffers(struct pw_link *this, d->chunk->offset = 0; d->chunk->size = 0; d->chunk->stride = data_strides[j]; - ddp += data_sizes[j]; + ddp = SPA_MEMBER(ddp, data_sizes[j], void); } else { /* needs to be allocated by a node */ d->type = SPA_ID_INVALID; diff --git a/src/pipewire/mem.c b/src/pipewire/mem.c index 5f34ee602..02c2a98c7 100644 --- a/src/pipewire/mem.c +++ b/src/pipewire/mem.c @@ -112,7 +112,7 @@ int pw_memblock_map(struct pw_memblock *mem) prot |= PROT_WRITE; if (mem->flags & PW_MEMBLOCK_FLAG_MAP_TWICE) { - void *ptr; + void *ptr, *wrap; mem->ptr = mmap(NULL, mem->size << 1, PROT_NONE, MAP_ANONYMOUS | MAP_PRIVATE, -1, @@ -128,10 +128,12 @@ int pw_memblock_map(struct pw_memblock *mem) return -ENOMEM; } + wrap = SPA_MEMBER(mem->ptr, mem->size, void); + ptr = - mmap(mem->ptr + mem->size, mem->size, prot, MAP_FIXED | MAP_SHARED, + mmap(wrap, mem->size, prot, MAP_FIXED | MAP_SHARED, mem->fd, mem->offset); - if (ptr != mem->ptr + mem->size) { + if (ptr != wrap) { munmap(mem->ptr, mem->size << 1); return -ENOMEM; } @@ -280,7 +282,7 @@ struct pw_memblock * pw_memblock_find(const void *ptr) struct memblock *m; spa_list_for_each(m, &_memblocks, link) { - if (ptr >= m->mem.ptr && ptr < m->mem.ptr + m->mem.size) + if (ptr >= m->mem.ptr && ptr < SPA_MEMBER(m->mem.ptr, m->mem.size, void)) return &m->mem; } return NULL;