fix more compile errors

Avoid void * arithmetic
Do explicit casts to target type to make c++ happy
This commit is contained in:
Wim Taymans 2019-01-08 11:53:36 +01:00
parent 3fa2ad33e4
commit b0f4be5fbc
26 changed files with 175 additions and 159 deletions

View file

@ -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)
{

View file

@ -22,6 +22,14 @@
* DEALINGS IN THE SOFTWARE.
*/
#ifndef __SPA_POD_COMPARE_H__
#define __SPA_POD_COMPARE_H__
#ifdef __cplusplus
extern "C" {
#endif
#include <stdarg.h>
#include <errno.h>
#include <stdint.h>
#include <stddef.h>
@ -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

View file

@ -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;
}

View file

@ -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)