Build fix: Missing message in LTTNG_DEPRECATED invocation
[lttng-tools.git] / src / common / dynamic-array.c
index bea903cafeae2a115b1fc1816345a0d50017dc8f..d723ffacb385094097508250b5d28a40e4c3991c 100644 (file)
@@ -1,23 +1,12 @@
 /*
- * Copyright (C) 2019 Jérémie Galarneau <jeremie.galarneau@efficios.com>
+ * Copyright (C) 2019 Jérémie Galarneau <jeremie.galarneau@efficios.com>
  *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License, version 2.1 only,
- * as published by the Free Software Foundation.
+ * SPDX-License-Identifier: LGPL-2.1-only
  *
- * 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 Lesser General Public License
- * for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
 #include <common/dynamic-array.h>
 
-LTTNG_HIDDEN
 void lttng_dynamic_array_init(struct lttng_dynamic_array *array,
                size_t element_size,
                lttng_dynamic_array_element_destructor destructor)
@@ -28,7 +17,34 @@ void lttng_dynamic_array_init(struct lttng_dynamic_array *array,
        array->destructor = destructor;
 }
 
-LTTNG_HIDDEN
+int lttng_dynamic_array_set_count(struct lttng_dynamic_array *array,
+               size_t new_element_count)
+{
+       int ret;
+
+       if (!array) {
+               ret = -1;
+               goto end;
+       }
+
+       if (array->destructor) {
+               size_t i;
+
+               for (i = new_element_count; i < array->size; i++) {
+                       void *element = lttng_dynamic_array_get_element(
+                                       array, i);
+
+                       array->destructor(element);
+               }
+       }
+
+       array->size = new_element_count;
+       ret = lttng_dynamic_buffer_set_size(&array->buffer,
+                       new_element_count * array->element_size);
+end:
+       return ret;
+}
+
 int lttng_dynamic_array_add_element(struct lttng_dynamic_array *array,
                const void *element)
 {
@@ -49,7 +65,6 @@ end:
        return ret;
 }
 
-LTTNG_HIDDEN
 int lttng_dynamic_array_remove_element(struct lttng_dynamic_array *array,
                size_t element_index)
 {
@@ -71,7 +86,6 @@ int lttng_dynamic_array_remove_element(struct lttng_dynamic_array *array,
                        array->buffer.size - array->element_size);
 }
 
-LTTNG_HIDDEN
 void lttng_dynamic_array_reset(struct lttng_dynamic_array *array)
 {
        if (array->destructor) {
@@ -87,7 +101,6 @@ void lttng_dynamic_array_reset(struct lttng_dynamic_array *array)
        array->size = 0;
 }
 
-LTTNG_HIDDEN
 void lttng_dynamic_array_clear(struct lttng_dynamic_array *array)
 {
        if (array->destructor) {
@@ -99,11 +112,10 @@ void lttng_dynamic_array_clear(struct lttng_dynamic_array *array)
                }
        }
 
-       lttng_dynamic_buffer_set_size(&array->buffer, 0);
+       (void) lttng_dynamic_buffer_set_size(&array->buffer, 0);
        array->size = 0;
 }
 
-LTTNG_HIDDEN
 void lttng_dynamic_pointer_array_init(
                struct lttng_dynamic_pointer_array *array,
                lttng_dynamic_pointer_array_destructor destructor)
@@ -111,7 +123,6 @@ void lttng_dynamic_pointer_array_init(
        lttng_dynamic_array_init(&array->array, sizeof(void *), destructor);
 }      
 
-LTTNG_HIDDEN
 int lttng_dynamic_pointer_array_remove_pointer(
                struct lttng_dynamic_pointer_array *array, size_t index)
 {
@@ -134,7 +145,6 @@ int lttng_dynamic_pointer_array_remove_pointer(
 }
 
 /* Release any memory used by the dynamic array. */
-LTTNG_HIDDEN
 void lttng_dynamic_pointer_array_reset(
                struct lttng_dynamic_pointer_array *array)
 {
@@ -155,7 +165,6 @@ void lttng_dynamic_pointer_array_reset(
        lttng_dynamic_array_reset(&array->array);
 }
 
-LTTNG_HIDDEN
 void lttng_dynamic_pointer_array_clear(
                struct lttng_dynamic_pointer_array *array)
 {
This page took 0.024863 seconds and 4 git commands to generate.