/*
- * Project: libFIRM
- * File name: ir/adt/array.c
- * Purpose: Array --- dynamic & flexible arrays.
- * Author: Markus Armbruster
- * Modified by:
- * Created: 1999 by getting from fiasco
- * CVS-ID: $Id$
- * Copyright: (c) 1995, 1996 Markus Armbruster
- * Licence: This file protected by GPL - GNU GENERAL PUBLIC LICENSE.
+ * Copyright (C) 1995-2007 University of Karlsruhe. All right reserved.
+ *
+ * This file is part of libFirm.
+ *
+ * This file may be distributed and/or modified under the terms of the
+ * GNU General Public License version 2 as published by the Free Software
+ * Foundation and appearing in the file LICENSE.GPL included in the
+ * packaging of this file.
+ *
+ * Licensees holding valid libFirm Professional Edition licenses may use
+ * this file in accordance with the libFirm Commercial License.
+ * Agreement provided with the Software.
+ *
+ * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
+ * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE.
+ */
+
+/**
+ * @file
+ * @brief Array --- dynamic & flexible arrays.
+ * @author Markus Armbruster
+ * @version $Id$
*/
#ifdef HAVE_CONFIG_H
-# include <config.h>
+# include "config.h"
#endif
-#include <stdlib.h>
+#ifdef HAVE_STDLIB_H
+# include <stdlib.h>
+#endif
#include "array.h"
#include "xmalloc.h"
*/
_arr_descr arr_mt_descr
#ifndef NDEBUG
- = { ARR_D_MAGIC }
+ = { ARR_D_MAGIC, 0, {0}, 0, {{0}} }
#endif
;
_arr_descr *dp = _ARR_DESCR (elts);
ARR_VRFY (elts);
- assert (dp->cookie == ARR_F_MAGIC);
+ assert (dp->magic == ARR_F_MAGIC);
#ifndef NDEBUG
- dp->cookie = 0xdeadbeef;
+ dp->magic = 0xdeadbeef;
#endif
free (dp);
}
{
_arr_descr *dp = _ARR_DESCR (elts);
- assert ((dp->cookie == ARR_F_MAGIC) && (nelts >= 0));
+ assert ((dp->magic == ARR_F_MAGIC) && (nelts >= 0));
ARR_VRFY (elts);
assert (!dp->eltsize || !nelts || (dp->eltsize == elts_size/nelts));
* Resize a flexible array, allocate more data if needed but do NOT
* reduce.
*
- * @param elts The flexible array (pointer to the first element).
- * @param nelts The new number of elements.
- * @param elts_size The size of the array elements.
+ * @param elts The flexible array (pointer to the first element).
+ * @param nelts The new number of elements.
+ * @param eltsize The size of the array elements.
*
* @return A resized flexible array, possibly other address than
* elts.
_arr_descr *dp = _ARR_DESCR (elts);
int n;
- assert ((dp->cookie == ARR_F_MAGIC) && (nelts >= 0));
+ assert ((dp->magic == ARR_F_MAGIC) && (nelts >= 0));
ARR_VRFY (elts);
assert (dp->eltsize ? dp->eltsize == eltsize : (dp->eltsize = eltsize, 1));
return dp->v.elts;
}
+
+#ifdef DEBUG_libfirm
+/**
+ * This function returns the length of a flexible array.
+ * Do NOT use is in code, use ARR_LEN() macro!
+ * This function is intended to be called from a debugger.
+ */
+int array_len(void *arr) {
+ return ARR_LEN(arr);
+}
+
+/**
+ * This function returns the array descriptor of a flexible array.
+ * Do NOT use is in code!.
+ * This function is intended to be called from a debugger.
+ */
+_arr_descr *array_descr(void *arr) {
+ if (! arr)
+ return NULL;
+ return _ARR_DESCR(arr);
+}
+#endif /* DEBUG_libfirm */