mirror of
https://gitlab.freedesktop.org/dbus/dbus.git
synced 2026-05-09 08:28:02 +02:00
chop dbus-marshal-basic in half and move it to be insertion rather than append based
This commit is contained in:
parent
e07789e511
commit
10f0f04980
4 changed files with 653 additions and 2305 deletions
File diff suppressed because it is too large
Load diff
|
|
@ -5,7 +5,7 @@
|
|||
* Copyright (C) 2004 Red Hat, Inc.
|
||||
*
|
||||
* Licensed under the Academic Free License version 2.1
|
||||
*
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
|
|
@ -15,7 +15,7 @@
|
|||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
|
@ -232,6 +232,7 @@ void _dbus_pack_uint32 (dbus_uint32_t value,
|
|||
unsigned char *data);
|
||||
dbus_uint32_t _dbus_unpack_uint32 (int byte_order,
|
||||
const unsigned char *data);
|
||||
|
||||
#ifdef DBUS_HAVE_INT64
|
||||
void _dbus_pack_int64 (dbus_int64_t value,
|
||||
int byte_order,
|
||||
|
|
@ -264,205 +265,43 @@ void _dbus_marshal_set_uint64 (DBusString *str,
|
|||
dbus_uint64_t value);
|
||||
#endif /* DBUS_HAVE_INT64 */
|
||||
|
||||
dbus_bool_t _dbus_marshal_set_string (DBusString *str,
|
||||
int byte_order,
|
||||
int offset,
|
||||
const DBusString *value,
|
||||
int len);
|
||||
void _dbus_marshal_set_object_path (DBusString *str,
|
||||
int byte_order,
|
||||
int offset,
|
||||
const char **path,
|
||||
int path_len);
|
||||
|
||||
dbus_bool_t _dbus_marshal_int32 (DBusString *str,
|
||||
int byte_order,
|
||||
dbus_int32_t value);
|
||||
dbus_bool_t _dbus_marshal_uint32 (DBusString *str,
|
||||
int byte_order,
|
||||
dbus_uint32_t value);
|
||||
|
||||
#ifdef DBUS_HAVE_INT64
|
||||
dbus_bool_t _dbus_marshal_int64 (DBusString *str,
|
||||
int byte_order,
|
||||
dbus_int64_t value);
|
||||
dbus_bool_t _dbus_marshal_uint64 (DBusString *str,
|
||||
int byte_order,
|
||||
dbus_uint64_t value);
|
||||
#endif /* DBUS_HAVE_INT64 */
|
||||
dbus_bool_t _dbus_marshal_double (DBusString *str,
|
||||
int byte_order,
|
||||
double value);
|
||||
|
||||
dbus_bool_t _dbus_marshal_string (DBusString *str,
|
||||
int byte_order,
|
||||
const char *value);
|
||||
dbus_bool_t _dbus_marshal_string_len (DBusString *str,
|
||||
int byte_order,
|
||||
const char *value,
|
||||
int len);
|
||||
|
||||
dbus_bool_t _dbus_marshal_basic_type (DBusString *str,
|
||||
int insert_at,
|
||||
char type,
|
||||
const void *value,
|
||||
int byte_order);
|
||||
dbus_bool_t _dbus_marshal_basic_type_array (DBusString *str,
|
||||
int insert_at,
|
||||
char element_type,
|
||||
const void *value,
|
||||
int len,
|
||||
int byte_order);
|
||||
dbus_bool_t _dbus_marshal_byte_array (DBusString *str,
|
||||
int byte_order,
|
||||
const unsigned char *value,
|
||||
int len);
|
||||
dbus_bool_t _dbus_marshal_int32_array (DBusString *str,
|
||||
int byte_order,
|
||||
const dbus_int32_t *value,
|
||||
int len);
|
||||
dbus_bool_t _dbus_marshal_uint32_array (DBusString *str,
|
||||
int byte_order,
|
||||
const dbus_uint32_t *value,
|
||||
int len);
|
||||
#ifdef DBUS_HAVE_INT64
|
||||
dbus_bool_t _dbus_marshal_int64_array (DBusString *str,
|
||||
int byte_order,
|
||||
const dbus_int64_t *value,
|
||||
int len);
|
||||
dbus_bool_t _dbus_marshal_uint64_array (DBusString *str,
|
||||
int byte_order,
|
||||
const dbus_uint64_t *value,
|
||||
int len);
|
||||
#endif /* DBUS_HAVE_INT64 */
|
||||
dbus_bool_t _dbus_marshal_double_array (DBusString *str,
|
||||
int byte_order,
|
||||
const double *value,
|
||||
int len);
|
||||
dbus_bool_t _dbus_marshal_string_array (DBusString *str,
|
||||
int byte_order,
|
||||
const char **value,
|
||||
int len);
|
||||
double _dbus_demarshal_double (const DBusString *str,
|
||||
int byte_order,
|
||||
int pos,
|
||||
int *new_pos);
|
||||
dbus_int32_t _dbus_demarshal_int32 (const DBusString *str,
|
||||
int byte_order,
|
||||
int pos,
|
||||
int *new_pos);
|
||||
dbus_uint32_t _dbus_demarshal_uint32 (const DBusString *str,
|
||||
int byte_order,
|
||||
int pos,
|
||||
int *new_pos);
|
||||
#ifdef DBUS_HAVE_INT64
|
||||
dbus_int64_t _dbus_demarshal_int64 (const DBusString *str,
|
||||
int byte_order,
|
||||
int pos,
|
||||
int *new_pos);
|
||||
dbus_uint64_t _dbus_demarshal_uint64 (const DBusString *str,
|
||||
int byte_order,
|
||||
int pos,
|
||||
int *new_pos);
|
||||
#endif /* DBUS_HAVE_INT64 */
|
||||
void _dbus_demarshal_basic_type (const DBusString *str,
|
||||
int type,
|
||||
void *value,
|
||||
int byte_order,
|
||||
int *pos);
|
||||
char * _dbus_demarshal_string (const DBusString *str,
|
||||
int byte_order,
|
||||
int pos,
|
||||
int *new_pos);
|
||||
dbus_bool_t _dbus_demarshal_byte_array (const DBusString *str,
|
||||
int byte_order,
|
||||
int pos,
|
||||
int *new_pos,
|
||||
unsigned char **array,
|
||||
int *array_len);
|
||||
dbus_bool_t _dbus_demarshal_int32_array (const DBusString *str,
|
||||
int byte_order,
|
||||
int pos,
|
||||
int *new_pos,
|
||||
dbus_int32_t **array,
|
||||
int *array_len);
|
||||
dbus_bool_t _dbus_demarshal_uint32_array (const DBusString *str,
|
||||
int byte_order,
|
||||
int pos,
|
||||
int *new_pos,
|
||||
dbus_uint32_t **array,
|
||||
int *array_len);
|
||||
#ifdef DBUS_HAVE_INT64
|
||||
dbus_bool_t _dbus_demarshal_int64_array (const DBusString *str,
|
||||
int byte_order,
|
||||
int pos,
|
||||
int *new_pos,
|
||||
dbus_int64_t **array,
|
||||
int *array_len);
|
||||
dbus_bool_t _dbus_demarshal_uint64_array (const DBusString *str,
|
||||
int byte_order,
|
||||
int pos,
|
||||
int *new_pos,
|
||||
dbus_uint64_t **array,
|
||||
int *array_len);
|
||||
#endif /* DBUS_HAVE_INT64 */
|
||||
dbus_bool_t _dbus_demarshal_double_array (const DBusString *str,
|
||||
int byte_order,
|
||||
int pos,
|
||||
int *new_pos,
|
||||
double **array,
|
||||
int *array_len);
|
||||
dbus_bool_t _dbus_demarshal_basic_type_array (const DBusString *str,
|
||||
int type,
|
||||
void **array,
|
||||
int *array_len,
|
||||
int byte_order,
|
||||
int *pos);
|
||||
|
||||
dbus_bool_t _dbus_demarshal_string_array (const DBusString *str,
|
||||
int byte_order,
|
||||
int pos,
|
||||
int *new_pos,
|
||||
char ***array,
|
||||
int *array_len);
|
||||
dbus_bool_t _dbus_decompose_path (const char* data,
|
||||
int len,
|
||||
char ***path,
|
||||
int *path_len);
|
||||
dbus_bool_t _dbus_demarshal_object_path (const DBusString *str,
|
||||
int byte_order,
|
||||
int pos,
|
||||
int *new_pos,
|
||||
char ***path,
|
||||
int *path_len);
|
||||
|
||||
void _dbus_marshal_skip_basic_type (const DBusString *str,
|
||||
int type,
|
||||
int byte_order,
|
||||
int *pos);
|
||||
void _dbus_marshal_skip_array (const DBusString *str,
|
||||
int byte_order,
|
||||
int *pos);
|
||||
|
||||
dbus_bool_t _dbus_marshal_get_arg_end_pos (const DBusString *str,
|
||||
int byte_order,
|
||||
int type,
|
||||
int pos,
|
||||
int *end_pos);
|
||||
dbus_bool_t _dbus_marshal_validate_type (const DBusString *str,
|
||||
int pos,
|
||||
int *type,
|
||||
int *end_pos);
|
||||
dbus_bool_t _dbus_marshal_validate_arg (const DBusString *str,
|
||||
int depth,
|
||||
int byte_order,
|
||||
int type,
|
||||
int array_type_pos,
|
||||
int pos,
|
||||
int *end_pos);
|
||||
|
||||
dbus_bool_t _dbus_type_is_valid (int typecode);
|
||||
|
||||
int _dbus_type_get_alignment (int typecode);
|
||||
dbus_bool_t _dbus_marshal_set_string (DBusString *str,
|
||||
int byte_order,
|
||||
int offset,
|
||||
const DBusString *value,
|
||||
int len);
|
||||
dbus_bool_t _dbus_marshal_basic_type (DBusString *str,
|
||||
int insert_at,
|
||||
char type,
|
||||
const void *value,
|
||||
int byte_order,
|
||||
int *pos_after);
|
||||
dbus_bool_t _dbus_marshal_basic_type_array (DBusString *str,
|
||||
int insert_at,
|
||||
char element_type,
|
||||
const void *value,
|
||||
int len,
|
||||
int byte_order,
|
||||
int *pos_after);
|
||||
dbus_uint32_t _dbus_demarshal_uint32 (const DBusString *str,
|
||||
int byte_order,
|
||||
int pos,
|
||||
int *new_pos);
|
||||
void _dbus_demarshal_basic_type (const DBusString *str,
|
||||
int type,
|
||||
void *value,
|
||||
int byte_order,
|
||||
int pos,
|
||||
int *new_pos);
|
||||
void _dbus_marshal_skip_basic_type (const DBusString *str,
|
||||
int type,
|
||||
int byte_order,
|
||||
int *pos);
|
||||
void _dbus_marshal_skip_array (const DBusString *str,
|
||||
int byte_order,
|
||||
int element_type,
|
||||
int *pos);
|
||||
dbus_bool_t _dbus_type_is_valid (int typecode);
|
||||
int _dbus_type_get_alignment (int typecode);
|
||||
|
||||
#endif /* DBUS_MARSHAL_H */
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@
|
|||
*/
|
||||
|
||||
#include "dbus-marshal-recursive.h"
|
||||
#include "dbus-marshal-basic.h"
|
||||
#include "dbus-internals.h"
|
||||
|
||||
/**
|
||||
|
|
@ -147,6 +148,7 @@ array_reader_recurse (DBusTypeReader *sub,
|
|||
DBUS_TYPE_UINT32,
|
||||
&array_len,
|
||||
sub->byte_order,
|
||||
sub->value_pos,
|
||||
&sub->value_pos);
|
||||
|
||||
sub->u.array.len = array_len;
|
||||
|
|
@ -290,31 +292,6 @@ skip_one_complete_type (const DBusString *type_str,
|
|||
*type_pos += 1;
|
||||
}
|
||||
|
||||
static void
|
||||
skip_array_values (int element_type,
|
||||
const DBusString *value_str,
|
||||
int *value_pos,
|
||||
int byte_order)
|
||||
{
|
||||
dbus_uint32_t array_len;
|
||||
int pos;
|
||||
int alignment;
|
||||
|
||||
pos = _DBUS_ALIGN_VALUE (*value_pos, 4);
|
||||
|
||||
_dbus_demarshal_basic_type (value_str,
|
||||
DBUS_TYPE_UINT32,
|
||||
&array_len,
|
||||
byte_order,
|
||||
&pos);
|
||||
|
||||
alignment = _dbus_type_get_alignment (element_type);
|
||||
|
||||
pos = _DBUS_ALIGN_VALUE (pos, alignment);
|
||||
|
||||
*value_pos = pos + array_len;
|
||||
}
|
||||
|
||||
static void
|
||||
base_reader_next (DBusTypeReader *reader,
|
||||
int current_type)
|
||||
|
|
@ -354,9 +331,10 @@ base_reader_next (DBusTypeReader *reader,
|
|||
case DBUS_TYPE_ARRAY:
|
||||
{
|
||||
if (!reader->klass->types_only)
|
||||
skip_array_values (first_type_in_signature (reader->type_str,
|
||||
reader->type_pos + 1),
|
||||
reader->value_str, &reader->value_pos, reader->byte_order);
|
||||
_dbus_marshal_skip_array (reader->value_str, reader->byte_order,
|
||||
first_type_in_signature (reader->type_str,
|
||||
reader->type_pos + 1),
|
||||
&reader->value_pos);
|
||||
|
||||
skip_one_complete_type (reader->type_str, &reader->type_pos);
|
||||
}
|
||||
|
|
@ -441,9 +419,10 @@ array_reader_next (DBusTypeReader *reader,
|
|||
|
||||
case DBUS_TYPE_ARRAY:
|
||||
{
|
||||
skip_array_values (first_type_in_signature (reader->type_str,
|
||||
reader->type_pos + 1),
|
||||
reader->value_str, &reader->value_pos, reader->byte_order);
|
||||
_dbus_marshal_skip_array (reader->value_str, reader->byte_order,
|
||||
first_type_in_signature (reader->type_str,
|
||||
reader->type_pos + 1),
|
||||
&reader->value_pos);
|
||||
}
|
||||
break;
|
||||
|
||||
|
|
@ -581,18 +560,20 @@ dbus_bool_t
|
|||
_dbus_type_reader_array_is_empty (DBusTypeReader *reader)
|
||||
{
|
||||
dbus_uint32_t array_len;
|
||||
int len_pos;
|
||||
|
||||
_dbus_assert (_dbus_type_reader_get_current_type (reader) == DBUS_TYPE_ARRAY);
|
||||
_dbus_assert (!reader->klass->types_only);
|
||||
|
||||
len_pos = _DBUS_ALIGN_VALUE (reader->value_pos, 4);
|
||||
/* reader is supposed to be at an array child */
|
||||
_dbus_verbose ("checking array len at %d\n", reader->value_pos);
|
||||
|
||||
_dbus_demarshal_basic_type (reader->value_str,
|
||||
DBUS_TYPE_UINT32,
|
||||
&array_len,
|
||||
reader->byte_order,
|
||||
&len_pos);
|
||||
reader->value_pos,
|
||||
NULL);
|
||||
_dbus_verbose (" ... array len = %d\n", array_len);
|
||||
|
||||
return array_len == 0;
|
||||
}
|
||||
|
|
@ -602,22 +583,20 @@ _dbus_type_reader_read_basic (DBusTypeReader *reader,
|
|||
void *value)
|
||||
{
|
||||
int t;
|
||||
int next;
|
||||
|
||||
_dbus_assert (!reader->klass->types_only);
|
||||
|
||||
t = _dbus_type_reader_get_current_type (reader);
|
||||
|
||||
next = reader->value_pos;
|
||||
_dbus_demarshal_basic_type (reader->value_str,
|
||||
t, value,
|
||||
reader->byte_order,
|
||||
&next);
|
||||
reader->value_pos, NULL);
|
||||
|
||||
|
||||
#if RECURSIVE_MARSHAL_TRACE
|
||||
_dbus_verbose (" type reader %p read basic type_pos = %d value_pos = %d next = %d remaining sig '%s'\n",
|
||||
reader, reader->type_pos, reader->value_pos, next,
|
||||
_dbus_verbose (" type reader %p read basic type_pos = %d value_pos = %d remaining sig '%s'\n",
|
||||
reader, reader->type_pos, reader->value_pos,
|
||||
_dbus_string_get_const_data_len (reader->type_str, reader->type_pos, 0));
|
||||
#endif
|
||||
}
|
||||
|
|
@ -765,23 +744,12 @@ _dbus_type_writer_write_basic_no_typecode (DBusTypeWriter *writer,
|
|||
int type,
|
||||
const void *value)
|
||||
{
|
||||
int old_value_len;
|
||||
int bytes_written;
|
||||
|
||||
old_value_len = _dbus_string_get_length (writer->value_str);
|
||||
|
||||
if (!_dbus_marshal_basic_type (writer->value_str,
|
||||
writer->value_pos,
|
||||
type,
|
||||
value,
|
||||
writer->byte_order))
|
||||
return FALSE;
|
||||
|
||||
bytes_written = _dbus_string_get_length (writer->value_str) - old_value_len;
|
||||
|
||||
writer->value_pos += bytes_written;
|
||||
|
||||
return TRUE;
|
||||
return _dbus_marshal_basic_type (writer->value_str,
|
||||
writer->value_pos,
|
||||
type,
|
||||
value,
|
||||
writer->byte_order,
|
||||
&writer->value_pos);
|
||||
}
|
||||
|
||||
/* If our parent is an array, things are a little bit complicated.
|
||||
|
|
@ -1037,8 +1005,9 @@ _dbus_type_writer_recurse_array (DBusTypeWriter *writer,
|
|||
_dbus_assert (sub->u.array.len_pos < sub->u.array.start_pos);
|
||||
|
||||
#if RECURSIVE_MARSHAL_TRACE
|
||||
_dbus_verbose (" type writer %p recurse array done remaining sig '%s'\n", sub,
|
||||
_dbus_string_get_const_data_len (sub->type_str, sub->type_pos, 0));
|
||||
_dbus_verbose (" type writer %p recurse array done remaining sig '%s' array start_pos = %d len_pos = %d\n", sub,
|
||||
_dbus_string_get_const_data_len (sub->type_str, sub->type_pos, 0),
|
||||
sub->u.array.start_pos, sub->u.array.len_pos);
|
||||
#endif
|
||||
|
||||
return TRUE;
|
||||
|
|
@ -1928,7 +1897,9 @@ run_test_nodes_iteration (void *data)
|
|||
++i;
|
||||
}
|
||||
|
||||
/* FIXME type-iterate both signature and value */
|
||||
/* FIXME type-iterate both signature and value and compare the resulting
|
||||
* tree to the node tree
|
||||
*/
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
|
@ -2382,9 +2353,12 @@ _dbus_marshal_recursive_test (void)
|
|||
}
|
||||
|
||||
#if 1
|
||||
dbus_bool_t _dbus_marshal_test (void);
|
||||
int
|
||||
main (int argc, char **argv)
|
||||
{
|
||||
_dbus_marshal_test ();
|
||||
|
||||
_dbus_marshal_recursive_test ();
|
||||
|
||||
return 0;
|
||||
|
|
@ -2692,11 +2666,6 @@ double_write_value (TestTypeNode *node,
|
|||
&v);
|
||||
}
|
||||
|
||||
/* Maybe this macro should be in a real header,
|
||||
* depends on why it's needed which I don't understand yet
|
||||
*/
|
||||
#define DOUBLES_BITWISE_EQUAL(a, b) \
|
||||
(memcmp ((char*)&(a), (char*)&(b), 8) == 0)
|
||||
static dbus_bool_t
|
||||
double_read_value (TestTypeNode *node,
|
||||
DataBlock *block,
|
||||
|
|
@ -2713,7 +2682,7 @@ double_read_value (TestTypeNode *node,
|
|||
|
||||
expected = double_from_seed (seed);
|
||||
|
||||
if (!DOUBLES_BITWISE_EQUAL (v, expected))
|
||||
if (!_DBUS_DOUBLES_BITWISE_EQUAL (v, expected))
|
||||
{
|
||||
#ifdef DBUS_HAVE_INT64
|
||||
_dbus_warn ("Expected double %g got %g\n bits = 0x%llx vs.\n bits = 0x%llx)\n",
|
||||
|
|
@ -2748,7 +2717,7 @@ object_path_from_seed (char *buf,
|
|||
++i;
|
||||
buf[i] = v;
|
||||
++i;
|
||||
|
||||
|
||||
v += 1;
|
||||
}
|
||||
|
||||
|
|
@ -2813,7 +2782,7 @@ signature_from_seed (char *buf,
|
|||
};
|
||||
|
||||
s = sample_signatures[seed % _DBUS_N_ELEMENTS(sample_signatures)];
|
||||
|
||||
|
||||
for (i = 0; s[i]; i++)
|
||||
{
|
||||
buf[i] = s[i];
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
* Copyright (C) 2004 Red Hat, Inc.
|
||||
*
|
||||
* Licensed under the Academic Free License version 2.1
|
||||
*
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
|
|
@ -14,7 +14,7 @@
|
|||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
|
@ -25,12 +25,25 @@
|
|||
#define DBUS_MARSHAL_RECURSIVE_H
|
||||
|
||||
#include <config.h>
|
||||
#include <dbus/dbus-marshal-basic.h>
|
||||
#include <dbus/dbus-marshal-basic.h> /* this can become protocol.h when we merge */
|
||||
|
||||
#ifndef PACKAGE
|
||||
#error "config.h not included here"
|
||||
#endif
|
||||
|
||||
/* Features we need to port dbus-message:
|
||||
* - memoize a position of a reader for small/fast access later
|
||||
* - delete an array element and re-align the remainder of the array
|
||||
* (not necessary yet to re-align remainder of entire string,
|
||||
* though that's probably just as hard/easy)
|
||||
* - set string, int, etc. values at a memoized position
|
||||
* (implement generic set of any value? changes only
|
||||
* value_str not type_str)
|
||||
* - implement has_next()
|
||||
* - the all-in-one-block array accessors
|
||||
* - validation
|
||||
*/
|
||||
|
||||
typedef struct DBusTypeReader DBusTypeReader;
|
||||
typedef struct DBusTypeWriter DBusTypeWriter;
|
||||
typedef struct DBusTypeReaderClass DBusTypeReaderClass;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue