+2003-02-27 Havoc Pennington <hp@pobox.com>
+
+ * dbus/dbus-marshal.c (_dbus_demarshal_int32): rewrite to be much
+ more inlined, using dbus-string-private.h, speeds things up
+ substantially
+
+ * dbus/dbus-string.c (_dbus_string_free): apply align offset
+ when freeing the string
+ (_dbus_string_steal_data): fix for align offset
+ (undo_alignment): new function
+
2003-02-26 Havoc Pennington <hp@redhat.com>
All kinds of audit fixes from Owen, plus initial attempt to
dbus-message-builder.h \
dbus-string.c \
dbus-string.h \
+ dbus-string-private.h \
dbus-sysdeps.c \
dbus-sysdeps.h
#include "dbus-marshal.h"
#include "dbus-internals.h"
+#define DBUS_CAN_USE_DBUS_STRING_PRIVATE 1
+#include "dbus-string-private.h"
#include <string.h>
*/
dbus_int32_t
_dbus_demarshal_int32 (const DBusString *str,
- int byte_order,
- int pos,
- int *new_pos)
+ int byte_order,
+ int pos,
+ int *new_pos)
{
- const char *buffer;
-
+ const DBusRealString *real = (const DBusRealString*) str;
+
pos = _DBUS_ALIGN_VALUE (pos, sizeof (dbus_int32_t));
- _dbus_string_get_const_data_len (str, &buffer, pos, sizeof (dbus_int32_t));
-
if (new_pos)
*new_pos = pos + sizeof (dbus_int32_t);
- return _dbus_unpack_int32 (byte_order, buffer);
+ if (byte_order == DBUS_LITTLE_ENDIAN)
+ return DBUS_INT32_FROM_LE (*(dbus_int32_t*)(real->str + pos));
+ else
+ return DBUS_INT32_FROM_BE (*(dbus_int32_t*)(real->str + pos));
}
/**
int pos,
int *new_pos)
{
- const char *buffer;
-
+ const DBusRealString *real = (const DBusRealString*) str;
+
pos = _DBUS_ALIGN_VALUE (pos, sizeof (dbus_uint32_t));
- _dbus_string_get_const_data_len (str, &buffer, pos, sizeof (dbus_uint32_t));
-
if (new_pos)
*new_pos = pos + sizeof (dbus_uint32_t);
- return _dbus_unpack_uint32 (byte_order, buffer);
+ if (byte_order == DBUS_LITTLE_ENDIAN)
+ return DBUS_UINT32_FROM_LE (*(dbus_uint32_t*)(real->str + pos));
+ else
+ return DBUS_UINT32_FROM_BE (*(dbus_uint32_t*)(real->str + pos));
}
/**
--- /dev/null
+/* -*- mode: C; c-file-style: "gnu" -*- */
+/* dbus-string-private.h String utility class (internal to D-BUS implementation)
+ *
+ * Copyright (C) 2002, 2003 Red Hat, Inc.
+ *
+ * Licensed under the Academic Free License version 1.2
+ *
+ * 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
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * 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
+ *
+ */
+
+#ifndef DBUS_STRING_PRIVATE_H
+#define DBUS_STRING_PRIVATE_H
+
+#include <config.h>
+
+#include <dbus/dbus-memory.h>
+#include <dbus/dbus-types.h>
+
+#ifndef DBUS_CAN_USE_DBUS_STRING_PRIVATE
+#error "Don't go including dbus-string-private.h for no good reason"
+#endif
+
+DBUS_BEGIN_DECLS;
+
+/**
+ * @brief Internals of DBusString.
+ *
+ * DBusString internals. DBusString is an opaque objects, it must be
+ * used via accessor functions.
+ */
+typedef struct
+{
+ unsigned char *str; /**< String data, plus nul termination */
+ int len; /**< Length without nul */
+ int allocated; /**< Allocated size of data */
+ int max_length; /**< Max length of this string, without nul byte */
+ unsigned int constant : 1; /**< String data is not owned by DBusString */
+ unsigned int locked : 1; /**< DBusString has been locked and can't be changed */
+ unsigned int invalid : 1; /**< DBusString is invalid (e.g. already freed) */
+ unsigned int align_offset : 3; /**< str - align_offset is the actual malloc block */
+} DBusRealString;
+
+DBUS_END_DECLS;
+
+#endif /* DBUS_STRING_PRIVATE_H */
#include "dbus-string.h"
/* we allow a system header here, for speed/convenience */
#include <string.h>
+#include "dbus-marshal.h"
+#define DBUS_CAN_USE_DBUS_STRING_PRIVATE 1
+#include "dbus-string-private.h"
/**
* @defgroup DBusString string class
*/
/**
- * @brief Internals of DBusString.
- *
- * DBusString internals. DBusString is an opaque objects, it must be
- * used via accessor functions.
- */
-typedef struct
-{
- unsigned char *str; /**< String data, plus nul termination */
- int len; /**< Length without nul */
- int allocated; /**< Allocated size of data */
- int max_length; /**< Max length of this string, without nul byte */
- unsigned int constant : 1; /**< String data is not owned by DBusString */
- unsigned int locked : 1; /**< DBusString has been locked and can't be changed */
- unsigned int invalid : 1; /**< DBusString is invalid (e.g. already freed) */
- unsigned int align_offset : 3; /**< str - align_offset is the actual malloc block */
-} DBusRealString;
-
-/**
* We allocate 1 byte for nul termination, plus 7 bytes for possible
* align_offset, so we always need 8 bytes on top of the string's
* length to be in the allocated block.
_dbus_assert (_DBUS_ALIGN_ADDRESS (real->str, 8) == real->str);
}
+static void
+undo_alignment (DBusRealString *real)
+{
+ if (real->align_offset != 0)
+ {
+ memmove (real->str - real->align_offset,
+ real->str,
+ real->len + 1);
+
+ real->align_offset = 0;
+ real->str = real->str - real->align_offset;
+ }
+}
+
/**
* Initializes a string. The maximum length may be _DBUS_INT_MAX for
* no maximum. The string starts life with zero length.
if (real->constant)
return;
- dbus_free (real->str);
+ dbus_free (real->str - real->align_offset);
real->invalid = TRUE;
}
{
DBUS_STRING_PREAMBLE (str);
_dbus_assert (data_return != NULL);
+
+ undo_alignment (real);
*data_return = real->str;
/* hrm, put it back then */
real->str = *data_return;
*data_return = NULL;
+ fixup_alignment (real);
return FALSE;
}
memset (real->str, '\0', real->allocated);
}
-
/** @} */
#ifdef DBUS_BUILD_TESTS