summaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2017-05-12 21:28:01 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2017-05-12 21:28:01 (GMT)
commit5fce21379baac06b7b9359c4b0fcb7fb3867c301 (patch)
tree19bf2943fe5a8a46bae227b8863bc9714fb3ec66 /src/common
parent8ee7fc5db965adaa835ca87bb3d2e2d43e52fbbb (diff)
Added the ELF strings to the preloaded instruction list.
Diffstat (limited to 'src/common')
-rw-r--r--src/common/array.c81
-rw-r--r--src/common/array.h6
2 files changed, 87 insertions, 0 deletions
diff --git a/src/common/array.c b/src/common/array.c
index f520d1d..dcb9344 100644
--- a/src/common/array.c
+++ b/src/common/array.c
@@ -215,6 +215,87 @@ void reset_flat_array(flat_array_t **array)
/******************************************************************************
* *
+* Paramètres : src = tableau compressé à consulter. *
+* dest = tableau compressé à constituer. [OUT] *
+* size = taille de ce nouvel élément. *
+* notify = éventuelle fonction à appeler sur chaque élément. *
+* *
+* Description : Copie le contenu d'un tableau d'éléments dans un autre. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+void copy_flat_array_items(flat_array_t **src, flat_array_t **dest, size_t size, item_notify_cb notify)
+{
+ void *item; /* Elément manipulé */
+ ext_flat_array_t *extended; /* Version de tableau étendue */
+ ext_flat_array_t *new; /* Nouvelle copie créée */
+ size_t i; /* Boucle de parcours */
+
+ assert(!FLAT_ARRAY_IS_LOCKED(*src));
+ assert(!FLAT_ARRAY_IS_LOCKED(*dest));
+
+ lock_flat_array(src);
+ lock_flat_array(dest);
+
+ assert(FLAT_ARRAY_IS_EMPTY(*dest));
+
+ if (FLAT_ARRAY_IS_EMPTY(*src))
+ goto cfai_done;
+
+ if (FLAT_ARRAY_HAS_NO_INDEX(*src))
+ {
+ item = GET_LONELY_ITEM(*src);
+
+ if (notify != NULL)
+ notify(item);
+
+ *dest = malloc(size);
+ memcpy(*dest, item, size);
+
+ lock_flat_array(dest);
+
+ }
+
+ else
+ {
+ extended = EXTENDED_ARRAY(*src);
+
+ new = (ext_flat_array_t *)malloc(sizeof(ext_flat_array_t));
+
+ new->items = malloc(extended->count * size);
+ new->count = extended->count;
+
+ memcpy(new->items, extended->items, new->count * size);
+
+ if (notify != NULL)
+ for (i = 0; i < new->count; i++)
+ {
+ item = (void *)(((char *)new->items) + i * size);
+ notify(item);
+ }
+
+ FLAT_ARRAY_SET_INDEX(new);
+
+ *dest = (flat_array_t *)new;
+
+ lock_flat_array(dest);
+
+ }
+
+ cfai_done:
+
+ unlock_flat_array(src);
+ unlock_flat_array(dest);
+
+}
+
+
+/******************************************************************************
+* *
* Paramètres : array = tableau compressé à consulter. *
* *
* Description : Indique la quantité d'éléments présents dans le tableau. *
diff --git a/src/common/array.h b/src/common/array.h
index bdb1ae4..546de1a 100644
--- a/src/common/array.h
+++ b/src/common/array.h
@@ -33,6 +33,9 @@
/* Type déclaratif de tableau compressé, à 0 ou 1 élément */
typedef void *flat_array_t;
+/* Parcours d'éléments */
+typedef void (* item_notify_cb) (void *);
+
/* Verrouille l'accès à un tableau compressé. */
void lock_flat_array(flat_array_t **);
@@ -43,6 +46,9 @@ void unlock_flat_array(flat_array_t **);
/* Réinitialise un tableau sans traitement excessif. */
void reset_flat_array(flat_array_t **);
+/* Copie le contenu d'un tableau d'éléments dans un autre. */
+void copy_flat_array_items(flat_array_t **, flat_array_t **, size_t, item_notify_cb);
+
/* Indique la quantité d'éléments présents dans le tableau. */
size_t count_flat_array_items(const flat_array_t *);