Rizin
unix-like reverse engineering framework and cli tools
vector.c File Reference
#include "rz_vector.h"

Go to the source code of this file.

Macros

#define INITIAL_VECTOR_LEN   4
 
#define NEXT_VECTOR_CAPACITY
 
#define RESIZE_OR_RETURN_NULL(next_capacity)
 
#define VEC_INDEX(a, i)   (char *)a + elem_size *(i)
 

Functions

RZ_API void rz_vector_init (RzVector *vec, size_t elem_size, RzVectorFree free, void *free_user)
 
RZ_API RzVectorrz_vector_new (size_t elem_size, RzVectorFree free, void *free_user)
 
static void vector_free_elems (RzVector *vec)
 
RZ_API void rz_vector_fini (RzVector *vec)
 
RZ_API void rz_vector_clear (RzVector *vec)
 
RZ_API void rz_vector_free (RzVector *vec)
 
static bool vector_clone (RzVector *dst, RzVector *src)
 
RZ_API RzVectorrz_vector_clone (RzVector *vec)
 
RZ_API void rz_vector_assign (RzVector *vec, void *p, void *elem)
 
RZ_API void * rz_vector_assign_at (RzVector *vec, size_t index, void *elem)
 
RZ_API void rz_vector_remove_at (RzVector *vec, size_t index, void *into)
 
RZ_API void rz_vector_remove_range (RzVector *vec, size_t index, size_t count, void *into)
 
RZ_API void * rz_vector_insert (RzVector *vec, size_t index, void *x)
 
RZ_API void * rz_vector_insert_range (RzVector *vec, size_t index, void *first, size_t count)
 
RZ_API void rz_vector_pop (RzVector *vec, void *into)
 
RZ_API void rz_vector_pop_front (RzVector *vec, void *into)
 
RZ_API void * rz_vector_push (RzVector *vec, void *x)
 
RZ_API void * rz_vector_push_front (RzVector *vec, void *x)
 
RZ_API void * rz_vector_reserve (RzVector *vec, size_t capacity)
 
RZ_API void * rz_vector_shrink (RzVector *vec)
 
RZ_API void * rz_vector_flush (RzVector *vec)
 Turn the vector into a fixed-size array. This will clear the vector and return an array of its original contents whose ownership is transferred to the caller. This is useful when RzVector is used for its dynamically growing functionality as an intermediate step to generate a fixed-size array in the end. More...
 
static void vector_quick_sort (void *a, size_t elem_size, size_t len, RzPVectorComparator cmp, bool reverse)
 
RZ_API void rz_vector_sort (RzVector *vec, RzVectorComparator cmp, bool reverse)
 Sort function for RzVector. More...
 
static void pvector_free_elem (void *e, void *user)
 
RZ_API void rz_pvector_init (RzPVector *vec, RzPVectorFree free)
 
RZ_API RzPVectorrz_pvector_new (RzPVectorFree free)
 
RZ_API RzPVectorrz_pvector_new_with_len (RzPVectorFree free, size_t length)
 
RZ_API void rz_pvector_clear (RzPVector *vec)
 
RZ_API void rz_pvector_fini (RzPVector *vec)
 
RZ_API void rz_pvector_free (RzPVector *vec)
 
RZ_API void ** rz_pvector_contains (RzPVector *vec, void *x)
 
RZ_API void * rz_pvector_remove_at (RzPVector *vec, size_t index)
 
RZ_API void rz_pvector_remove_data (RzPVector *vec, void *x)
 
RZ_API void * rz_pvector_pop (RzPVector *vec)
 
RZ_API void * rz_pvector_pop_front (RzPVector *vec)
 
static void quick_sort (void **a, size_t n, RzPVectorComparator cmp)
 
RZ_API void rz_pvector_sort (RzPVector *vec, RzPVectorComparator cmp)
 

Macro Definition Documentation

◆ INITIAL_VECTOR_LEN

#define INITIAL_VECTOR_LEN   4

Definition at line 14 of file vector.c.

◆ NEXT_VECTOR_CAPACITY

#define NEXT_VECTOR_CAPACITY
Value:
(vec->capacity < INITIAL_VECTOR_LEN \
: vec->capacity <= 12 ? vec->capacity * 2 \
: vec->capacity + (vec->capacity >> 1))
#define INITIAL_VECTOR_LEN
Definition: vector.c:14

Definition at line 17 of file vector.c.

◆ RESIZE_OR_RETURN_NULL

#define RESIZE_OR_RETURN_NULL (   next_capacity)
Value:
do { \
size_t new_capacity = next_capacity; \
void **new_a = realloc(vec->a, vec->elem_size * new_capacity); \
if (!new_a && new_capacity) { \
return NULL; \
} \
vec->a = new_a; \
vec->capacity = new_capacity; \
} while (0)
#define NULL
Definition: cris-opc.c:27
void * realloc(void *ptr, size_t size)
Definition: malloc.c:144

Definition at line 22 of file vector.c.

◆ VEC_INDEX

#define VEC_INDEX (   a,
  i 
)    (char *)a + elem_size *(i)

Definition at line 240 of file vector.c.

Function Documentation

◆ pvector_free_elem()

static void pvector_free_elem ( void *  e,
void *  user 
)
static

Definition at line 292 of file vector.c.

292  {
293  void *p = *((void **)e);
294  RzPVectorFree elem_free = (RzPVectorFree)user;
295  elem_free(p);
296 }
#define e(frag)
void * p
Definition: libc.cpp:67
void(* RzPVectorFree)(void *e)
Definition: rz_vector.h:43

References e, and p.

Referenced by rz_pvector_init().

◆ quick_sort()

static void quick_sort ( void **  a,
size_t  n,
RzPVectorComparator  cmp 
)
static

Definition at line 387 of file vector.c.

387  {
388  if (n <= 1) {
389  return;
390  }
391  size_t i = rand() % n, j = 0;
392  void *t, *pivot = a[i];
393  a[i] = a[n - 1];
394  for (i = 0; i < n - 1; i++) {
395  if (cmp(a[i], pivot) < 0) {
396  t = a[i];
397  a[i] = a[j];
398  a[j] = t;
399  j++;
400  }
401  }
402  a[n - 1] = a[j];
403  a[j] = pivot;
404  quick_sort(a, j, cmp);
405  quick_sort(a + j + 1, n - j - 1, cmp);
406 }
lzma_index ** i
Definition: index.h:629
static RzILOpEffect * cmp(cs_insn *insn, bool is_thumb)
Definition: arm_il32.c:942
int n
Definition: mipsasm.c:19
#define a(i)
Definition: sha256.c:41
static void quick_sort(void **a, size_t n, RzPVectorComparator cmp)
Definition: vector.c:387

References a, cmp(), i, and n.

Referenced by rz_pvector_sort().

◆ rz_pvector_clear()

◆ rz_pvector_contains()

RZ_API void** rz_pvector_contains ( RzPVector vec,
void *  x 
)

Definition at line 344 of file vector.c.

344  {
346  size_t i;
347  for (i = 0; i < vec->v.len; i++) {
348  if (((void **)vec->v.a)[i] == x) {
349  return &((void **)vec->v.a)[i];
350  }
351  }
352  return NULL;
353 }
int x
Definition: mipsasm.c:20
#define rz_return_val_if_fail(expr, val)
Definition: rz_assert.h:108
void * a
Definition: rz_vector.h:46
size_t len
Definition: rz_vector.h:47

References rz_vector_t::a, i, rz_vector_t::len, NULL, rz_return_val_if_fail, rz_pvector_t::v, and x.

Referenced by rz_analysis_var_set_access(), and rz_pvector_remove_data().

◆ rz_pvector_fini()

◆ rz_pvector_free()

RZ_API void rz_pvector_free ( RzPVector vec)

◆ rz_pvector_init()

◆ rz_pvector_new()

RZ_API RzPVector* rz_pvector_new ( RzPVectorFree  free)

Definition at line 302 of file vector.c.

302  {
304  if (!v) {
305  return NULL;
306  }
308  return v;
309 }
const char * v
Definition: dsignal.c:12
#define RZ_NEW(x)
Definition: rz_types.h:285
RZ_API void rz_pvector_init(RzPVector *vec, RzPVectorFree free)
Definition: vector.c:298

References free(), NULL, RZ_NEW, rz_pvector_init(), and v.

Referenced by analysis_class_print(), bin_pe_dotnet_init_metadata(), c_parser_new_callable(), c_parser_new_naked_callable(), capture_filter_keywords(), collect_nodes_at(), collect_nodes_in(), collect_nodes_intersect(), del(), get_patchable_relocs(), get_token_patterns(), parse_type_mfunction(), parse_type_procedure(), print_stats(), rz_analysis_esil_trace_new(), rz_analysis_function_all_opcode_stat_handler(), rz_analysis_function_args(), rz_analysis_il_trace_instruction_new(), rz_analysis_rzil_trace_new(), rz_analysis_var_set_access(), rz_annotated_code_annotations_in(), rz_annotated_code_annotations_range(), rz_bin_dex_new(), rz_bin_object_get_maps_at(), rz_cmd_debug_traces_esil_delete_handler(), rz_core_analysis_bytes(), rz_il_var_set_get_all(), rz_pvector_new_with_len(), rz_table_add_row(), rz_table_add_row_columnsf(), rz_table_add_rowf(), rz_table_columns(), rz_test_load_asm_test_file(), rz_test_load_cmd_test_file(), rz_test_load_json_test_file(), rz_test_main(), rz_tree_bfs(), rz_type_callable_clone(), and rz_type_callable_new().

◆ rz_pvector_new_with_len()

RZ_API RzPVector* rz_pvector_new_with_len ( RzPVectorFree  free,
size_t  length 
)

Definition at line 311 of file vector.c.

311  {
313  if (!v) {
314  return NULL;
315  }
316  void **p = rz_pvector_reserve(v, length);
317  if (!p) {
319  return NULL;
320  }
321  memset(p, 0, v->v.elem_size * v->v.capacity);
322  v->v.len = length;
323  return v;
324 }
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd static protocol static who struct sockaddr static addrlen static backlog struct timeval struct timezone static tz const struct iovec static count static mode const void const struct sockaddr static tolen const char static pathname void static offset struct stat static buf void long static basep static whence static length const void static len static semflg const void static shmflg const struct timespec struct timespec static rem const char static group const void length
Definition: sflib.h:133
return memset(p, 0, total)
static void ** rz_pvector_reserve(RzPVector *vec, size_t capacity)
Definition: rz_vector.h:312
RZ_API RzPVector * rz_pvector_new(RzPVectorFree free)
Definition: vector.c:302
RZ_API void rz_pvector_free(RzPVector *vec)
Definition: vector.c:336

References free(), length, memset(), NULL, p, rz_pvector_free(), rz_pvector_new(), rz_pvector_reserve(), and v.

Referenced by get_relocs().

◆ rz_pvector_pop()

RZ_API void* rz_pvector_pop ( RzPVector vec)

Definition at line 372 of file vector.c.

372  {
374  void *r = rz_pvector_at(vec, vec->v.len - 1);
375  rz_vector_pop(&vec->v, NULL);
376  return r;
377 }
#define r
Definition: crypto_rc6.c:12
static void * rz_pvector_at(const RzPVector *vec, size_t index)
Definition: rz_vector.h:236
RZ_API void rz_vector_pop(RzVector *vec, void *into)
Definition: vector.c:184

References rz_vector_t::len, NULL, r, rz_pvector_at(), rz_return_val_if_fail, rz_vector_pop(), and rz_pvector_t::v.

Referenced by analysis_block_on_exit(), rz_analysis_block_recurse(), rz_analysis_block_recurse_followthrough(), rz_core_visual_cmd(), rz_test_run_asm_test(), substitute_args_fini(), and worker_th().

◆ rz_pvector_pop_front()

RZ_API void* rz_pvector_pop_front ( RzPVector vec)

Definition at line 379 of file vector.c.

379  {
381  void *r = rz_pvector_at(vec, 0);
382  rz_vector_pop_front(&vec->v, NULL);
383  return r;
384 }
RZ_API void rz_vector_pop_front(RzVector *vec, void *into)
Definition: vector.c:192

References NULL, r, rz_pvector_at(), rz_return_val_if_fail, rz_vector_pop_front(), and rz_pvector_t::v.

Referenced by rz_core_disasm_pde(), and rz_tree_bfs().

◆ rz_pvector_remove_at()

RZ_API void* rz_pvector_remove_at ( RzPVector vec,
size_t  index 
)

Definition at line 355 of file vector.c.

355  {
357  void *r = rz_pvector_at(vec, index);
358  rz_vector_remove_at(&vec->v, index, NULL);
359  return r;
360 }
RZ_API void rz_vector_remove_at(RzVector *vec, size_t index, void *into)
Definition: vector.c:127

References NULL, r, rz_pvector_at(), rz_return_val_if_fail, rz_vector_remove_at(), and rz_pvector_t::v.

Referenced by rz_analysis_function_delete_vars_by_kind(), rz_analysis_var_delete(), rz_io_map_cleanup(), rz_io_map_del(), rz_io_map_del_for_fd(), rz_io_map_depriorize(), rz_io_map_priorize(), rz_io_map_priorize_for_fd(), and rz_test_main().

◆ rz_pvector_remove_data()

RZ_API void rz_pvector_remove_data ( RzPVector vec,
void *  x 
)

Definition at line 362 of file vector.c.

362  {
363  void **el = rz_pvector_contains(vec, x);
364  if (!el) {
365  return;
366  }
367 
368  size_t index = el - (void **)vec->v.a;
369  rz_vector_remove_at(&vec->v, index, NULL);
370 }
RZ_API void ** rz_pvector_contains(RzPVector *vec, void *x)
Definition: vector.c:344

References rz_vector_t::a, NULL, rz_pvector_contains(), rz_vector_remove_at(), rz_pvector_t::v, and x.

Referenced by cmd_desc_unset_parent(), rz_analysis_function_delete_var(), rz_analysis_var_clear_accesses(), rz_analysis_var_remove_access_at(), rz_core_file_bin_file_deleted(), rz_core_file_io_desc_closed(), rz_core_file_io_map_deleted(), rz_io_cache_invalidate(), and rz_subprocess_free().

◆ rz_pvector_sort()

◆ rz_vector_assign()

RZ_API void rz_vector_assign ( RzVector vec,
void *  p,
void *  elem 
)

Definition at line 114 of file vector.c.

114  {
115  rz_return_if_fail(vec && p && elem);
116  memcpy(p, elem, vec->elem_size);
117 }
memcpy(mem, inblock.get(), min(CONTAINING_RECORD(inblock.get(), MEMBLOCK, data) ->size, size))
size_t elem_size
Definition: rz_vector.h:49

References rz_vector_t::elem_size, memcpy(), p, and rz_return_if_fail.

Referenced by rz_vector_assign_at(), rz_vector_insert(), rz_vector_pop(), rz_vector_push(), and rz_vector_remove_at().

◆ rz_vector_assign_at()

RZ_API void* rz_vector_assign_at ( RzVector vec,
size_t  index,
void *  elem 
)

Definition at line 119 of file vector.c.

119  {
120  void *p = rz_vector_index_ptr(vec, index);
121  if (elem) {
122  rz_vector_assign(vec, p, elem);
123  }
124  return p;
125 }
static void * rz_vector_index_ptr(RzVector *vec, size_t index)
Definition: rz_vector.h:88
RZ_API void rz_vector_assign(RzVector *vec, void *p, void *elem)
Definition: vector.c:114

References p, rz_vector_assign(), and rz_vector_index_ptr().

◆ rz_vector_clear()

◆ rz_vector_clone()

RZ_API RzVector* rz_vector_clone ( RzVector vec)

Definition at line 101 of file vector.c.

101  {
103  RzVector *ret = RZ_NEW(RzVector);
104  if (!ret) {
105  return NULL;
106  }
107  if (!vector_clone(ret, vec)) {
108  free(ret);
109  return NULL;
110  }
111  return ret;
112 }
static bool vector_clone(RzVector *dst, RzVector *src)
Definition: vector.c:82

References free(), NULL, RZ_NEW, rz_return_val_if_fail, and vector_clone().

Referenced by clear_bb_vars(), fcn_takeover_block_recursive_followthrough_cb(), rz_analysis_function_delete_unused_vars(), rz_analysis_function_set_type(), rz_analysis_var_resolve_overlaps(), rz_asm_token_string_clone(), and rz_core_disasm_pde().

◆ rz_vector_fini()

◆ rz_vector_flush()

RZ_API void* rz_vector_flush ( RzVector vec)

Turn the vector into a fixed-size array. This will clear the vector and return an array of its original contents whose ownership is transferred to the caller. This is useful when RzVector is used for its dynamically growing functionality as an intermediate step to generate a fixed-size array in the end.

Definition at line 230 of file vector.c.

230  {
232  rz_vector_shrink(vec);
233  void *r = vec->a;
234  vec->a = NULL;
235  vec->capacity = vec->len = 0;
236  return r;
237 }
RZ_API void * rz_vector_shrink(RzVector *vec)
Definition: vector.c:222

References rz_vector_t::a, rz_vector_t::capacity, rz_vector_t::len, NULL, r, rz_return_val_if_fail, and rz_vector_shrink().

Referenced by parse_line_header_source(), parse_line_raw(), rz_bin_source_line_info_builder_build_and_fini(), rz_il_reg_binding_derive(), and rz_pvector_flush().

◆ rz_vector_free()

◆ rz_vector_init()

◆ rz_vector_insert()

RZ_API void* rz_vector_insert ( RzVector vec,
size_t  index,
void *  x 
)

Definition at line 151 of file vector.c.

151  {
152  rz_return_val_if_fail(vec && index <= vec->len, NULL);
153  if (vec->len >= vec->capacity) {
155  }
156  void *p = rz_vector_index_ptr(vec, index);
157  if (index < vec->len) {
158  memmove((char *)p + vec->elem_size, p, vec->elem_size * (vec->len - index));
159  }
160  vec->len++;
161  if (x) {
162  rz_vector_assign(vec, p, x);
163  }
164  return p;
165 }
size_t len
Definition: 6502dis.c:15
#define NEXT_VECTOR_CAPACITY
Definition: vector.c:17
#define RESIZE_OR_RETURN_NULL(next_capacity)
Definition: vector.c:22

References rz_vector_t::capacity, rz_vector_t::elem_size, len, rz_vector_t::len, NEXT_VECTOR_CAPACITY, NULL, p, RESIZE_OR_RETURN_NULL, rz_return_val_if_fail, rz_vector_assign(), rz_vector_index_ptr(), and x.

Referenced by rz_analysis_var_set_access(), rz_pvector_insert(), rz_skyline_add(), rz_vector_push_front(), and sparse_write().

◆ rz_vector_insert_range()

RZ_API void* rz_vector_insert_range ( RzVector vec,
size_t  index,
void *  first,
size_t  count 
)

Definition at line 167 of file vector.c.

167  {
168  rz_return_val_if_fail(vec && index <= vec->len, NULL);
169  if (vec->len + count > vec->capacity) {
171  }
172  size_t sz = count * vec->elem_size;
173  void *p = rz_vector_index_ptr(vec, index);
174  if (index < vec->len) {
175  memmove((char *)p + sz, p, vec->elem_size * (vec->len - index));
176  }
177  vec->len += count;
178  if (first) {
179  memcpy(p, first, sz);
180  }
181  return p;
182 }
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd static protocol static who struct sockaddr static addrlen static backlog struct timeval struct timezone static tz const struct iovec static count static mode const void const struct sockaddr static tolen const char static pathname void count
Definition: sflib.h:98
#define RZ_MAX(x, y)

References rz_vector_t::capacity, count, rz_vector_t::elem_size, len, rz_vector_t::len, memcpy(), NEXT_VECTOR_CAPACITY, NULL, p, RESIZE_OR_RETURN_NULL, RZ_MAX, rz_return_val_if_fail, and rz_vector_index_ptr().

Referenced by rz_core_analysis_get_stats(), and rz_pvector_insert_range().

◆ rz_vector_new()

◆ rz_vector_pop()

RZ_API void rz_vector_pop ( RzVector vec,
void *  into 
)

Definition at line 184 of file vector.c.

184  {
185  rz_return_if_fail(vec);
186  if (into) {
187  rz_vector_assign(vec, into, rz_vector_index_ptr(vec, vec->len - 1));
188  }
189  vec->len--;
190 }

References rz_vector_t::len, rz_return_if_fail, rz_vector_assign(), and rz_vector_index_ptr().

Referenced by rz_analysis_block_recurse_depth_first(), rz_analysis_run_tasks(), rz_core_seek_redo(), rz_core_seek_undo(), and rz_pvector_pop().

◆ rz_vector_pop_front()

RZ_API void rz_vector_pop_front ( RzVector vec,
void *  into 
)

Definition at line 192 of file vector.c.

192  {
193  rz_return_if_fail(vec);
194  rz_vector_remove_at(vec, 0, into);
195 }

References rz_return_if_fail, and rz_vector_remove_at().

Referenced by rz_id_pool_grab_id(), and rz_pvector_pop_front().

◆ rz_vector_push()

RZ_API void* rz_vector_push ( RzVector vec,
void *  x 
)

Definition at line 197 of file vector.c.

197  {
199  if (vec->len >= vec->capacity) {
201  }
202  void *p = rz_vector_index_ptr(vec, vec->len++);
203  if (x) {
204  rz_vector_assign(vec, p, x);
205  }
206  return p;
207 }

References rz_vector_t::capacity, rz_vector_t::len, NEXT_VECTOR_CAPACITY, NULL, p, RESIZE_OR_RETURN_NULL, rz_return_val_if_fail, rz_vector_assign(), rz_vector_index_ptr(), and x.

Referenced by add_dt_dynamic_entry(), add_mem_change(), add_reg_change(), add_seek_history(), add_token(), analyze_function_locally(), array_add(), bflt_load_relocs(), compute_symbols_from_segment(), convert_sections_from_shdr(), create_section_from_phdr(), deserialize_checkpoints_cb(), deserialize_memory_cb(), deserialize_registers_cb(), ensure_addr_hint_record(), get_enum_type(), get_gnu_debugdata_elf_symbols(), get_relocs_entry(), get_segments_from_phdr(), get_struct_type(), get_union_type(), global_var_load_cb(), init_module_runtime_functions(), nextword(), parse_enum(), parse_enum_node(), parse_enum_type(), parse_line_header_source(), parse_note_file(), parse_note_prstatus(), parse_opcodes(), parse_struct_node(), parse_structure(), parse_structure_type(), parse_union(), parse_union_node(), recovery_analysis_complete_object_locator(), rz_analysis_block_recurse_depth_first(), rz_analysis_class_base_get_all(), rz_analysis_class_method_get_all(), rz_analysis_class_vtable_get_all(), rz_analysis_get_delta_jmptbl_info(), rz_analysis_il_init_state_set_var(), rz_analysis_task_item_new(), rz_analysis_var_add_constraint(), rz_analysis_var_global_add_constraint(), rz_analysis_vtable_parse_at(), rz_annotated_code_add_annotation(), rz_annotated_code_line_offsets(), rz_bin_elf_notes_new(), rz_bin_elf_sections_new(), rz_bin_object_p2v_all(), rz_bin_object_sections_mapping_list(), rz_bin_source_line_info_builder_push_sample(), rz_core_seek_redo(), rz_core_seek_undo(), rz_debug_add_checkpoint(), rz_debug_dmp_init(), rz_debug_dmp_pids(), rz_debug_session_add_mem_change(), rz_debug_session_add_reg_change(), rz_event_hook(), rz_event_unhook(), rz_id_pool_kick_id(), rz_il_reg_binding_derive(), rz_pvector_push(), rz_serialize_analysis_var_load(), rz_table_add_column(), rz_table_add_row(), rz_table_add_row_vec(), and rz_table_columns().

◆ rz_vector_push_front()

RZ_API void* rz_vector_push_front ( RzVector vec,
void *  x 
)

Definition at line 209 of file vector.c.

209  {
211  return rz_vector_insert(vec, 0, x);
212 }
RZ_API void * rz_vector_insert(RzVector *vec, size_t index, void *x)
Definition: vector.c:151

References NULL, rz_return_val_if_fail, rz_vector_insert(), and x.

Referenced by rz_pvector_push_front().

◆ rz_vector_remove_at()

RZ_API void rz_vector_remove_at ( RzVector vec,
size_t  index,
void *  into 
)

Definition at line 127 of file vector.c.

127  {
128  rz_return_if_fail(vec);
129  void *p = rz_vector_index_ptr(vec, index);
130  if (into) {
131  rz_vector_assign(vec, into, p);
132  }
133  vec->len--;
134  if (index < vec->len) {
135  memmove(p, (char *)p + vec->elem_size, vec->elem_size * (vec->len - index));
136  }
137 }

References rz_vector_t::elem_size, len, rz_vector_t::len, p, rz_return_if_fail, rz_vector_assign(), and rz_vector_index_ptr().

Referenced by add_seek_history(), del_hook(), rz_analysis_var_remove_access_at(), rz_pvector_remove_at(), rz_pvector_remove_data(), rz_skyline_add(), rz_table_filter(), rz_table_group(), rz_vector_pop_front(), and unset_addr_hint_record().

◆ rz_vector_remove_range()

RZ_API void rz_vector_remove_range ( RzVector vec,
size_t  index,
size_t  count,
void *  into 
)

remove all elements in the given range and write the contents to into (must be appropriately large). It is the caller's responsibility to free potential resources associated with the elements.

Definition at line 139 of file vector.c.

139  {
140  rz_return_if_fail(vec && index + count <= vec->len);
141  void *p = rz_vector_index_ptr(vec, index);
142  if (into) {
143  memcpy(into, p, count * vec->elem_size);
144  }
145  vec->len -= count;
146  if (index < vec->len) {
147  memmove(p, (char *)p + vec->elem_size * count, vec->elem_size * (vec->len - index));
148  }
149 }

References count, rz_vector_t::elem_size, len, rz_vector_t::len, memcpy(), p, rz_return_if_fail, and rz_vector_index_ptr().

Referenced by buf_sparse_resize(), and sparse_write().

◆ rz_vector_reserve()

◆ rz_vector_shrink()

RZ_API void* rz_vector_shrink ( RzVector vec)

Definition at line 222 of file vector.c.

222  {
224  if (vec->len < vec->capacity) {
226  }
227  return vec->a;
228 }

References rz_vector_t::a, rz_vector_t::capacity, rz_vector_t::len, NULL, RESIZE_OR_RETURN_NULL, and rz_return_val_if_fail.

Referenced by rz_pvector_shrink(), and rz_vector_flush().

◆ rz_vector_sort()

RZ_API void rz_vector_sort ( RzVector vec,
RzVectorComparator  cmp,
bool  reverse 
)

Sort function for RzVector.

Parameters
vecpointer to RzVector
cmpfunction used for comparing elements while sorting
reversesort order, ascending order when reverse = False

Definition at line 285 of file vector.c.

285  {
286  rz_return_if_fail(vec && cmp);
287  vector_quick_sort(vec->a, vec->elem_size, vec->len, cmp, reverse);
288 }
static void vector_quick_sort(void *a, size_t elem_size, size_t len, RzPVectorComparator cmp, bool reverse)
Definition: vector.c:241

References rz_vector_t::a, cmp(), rz_vector_t::elem_size, rz_vector_t::len, make_dist_html::reverse, rz_return_if_fail, and vector_quick_sort().

Referenced by rz_asm_tokenize_asm_regex(), rz_table_sort(), and rz_table_sortlen().

◆ vector_clone()

static bool vector_clone ( RzVector dst,
RzVector src 
)
static

Definition at line 82 of file vector.c.

82  {
83  rz_return_val_if_fail(dst && src, false);
84  dst->capacity = src->capacity;
85  dst->len = src->len;
86  dst->elem_size = src->elem_size;
87  dst->free = src->free;
88  dst->free_user = src->free_user;
89  if (!dst->len) {
90  dst->a = NULL;
91  } else {
92  dst->a = malloc(src->elem_size * src->capacity);
93  if (!dst->a) {
94  return false;
95  }
96  memcpy(dst->a, src->a, src->elem_size * src->len);
97  }
98  return true;
99 }
lzma_index * src
Definition: index.h:567
void * malloc(size_t size)
Definition: malloc.c:123
char * dst
Definition: lz4.h:724

References dst, malloc(), memcpy(), NULL, rz_return_val_if_fail, and src.

Referenced by rz_vector_clone().

◆ vector_free_elems()

static void vector_free_elems ( RzVector vec)
static

Definition at line 51 of file vector.c.

51  {
52  if (vec->free) {
53  while (vec->len > 0) {
54  vec->free(rz_vector_index_ptr(vec, --vec->len), vec->free_user);
55  }
56  } else {
57  vec->len = 0;
58  }
59 }

References rz_vector_t::free, rz_vector_t::free_user, rz_vector_t::len, and rz_vector_index_ptr().

Referenced by rz_vector_clear().

◆ vector_quick_sort()

static void vector_quick_sort ( void *  a,
size_t  elem_size,
size_t  len,
RzPVectorComparator  cmp,
bool  reverse 
)
static

Definition at line 241 of file vector.c.

241  {
243  if (len <= 1) {
244  return;
245  }
246  size_t i = rand() % len, j = 0;
247  void *t, *pivot;
248 
249  t = (void *)malloc(elem_size);
250  pivot = (void *)malloc(elem_size);
251  if (!t || !pivot) {
252  free(t);
253  free(pivot);
254  RZ_LOG_ERROR("Failed to allocate memory\n");
255  return;
256  }
257 
258  memcpy(pivot, VEC_INDEX(a, i), elem_size);
259  memcpy(VEC_INDEX(a, i), VEC_INDEX(a, len - 1), elem_size);
260  for (i = 0; i < len - 1; i++) {
261  if ((cmp(VEC_INDEX(a, i), pivot) < 0 && !reverse) ||
262  (cmp(VEC_INDEX(a, i), pivot) > 0 && reverse)) {
263  memcpy(t, VEC_INDEX(a, i), elem_size);
264  memcpy(VEC_INDEX(a, i), VEC_INDEX(a, j), elem_size);
265  memcpy(VEC_INDEX(a, j), t, elem_size);
266  j++;
267  }
268  }
269  memcpy(VEC_INDEX(a, len - 1), VEC_INDEX(a, j), elem_size);
270  memcpy(VEC_INDEX(a, j), pivot, elem_size);
271  RZ_FREE(t);
272  RZ_FREE(pivot);
273  vector_quick_sort(a, elem_size, j, cmp, reverse);
274  vector_quick_sort(VEC_INDEX(a, j + 1), elem_size, len - j - 1, cmp, reverse);
275 }
#define RZ_LOG_ERROR(fmtstr,...)
Definition: rz_log.h:58
#define VEC_INDEX(a, i)
Definition: vector.c:240

References a, cmp(), free(), i, len, malloc(), memcpy(), make_dist_html::reverse, RZ_FREE, RZ_LOG_ERROR, rz_return_if_fail, and VEC_INDEX.

Referenced by rz_vector_sort().