Rizin
unix-like reverse engineering framework and cli tools
rz_stack.h File Reference
#include <rz_types.h>

Go to the source code of this file.

Classes

struct  rz_stack_t
 

Typedefs

typedef void(* RzStackFree) (void *ptr)
 
typedef struct rz_stack_t RzStack
 

Functions

RZ_API RzStackrz_stack_new (ut32 n)
 
RZ_API void rz_stack_free (RzStack *s)
 
RZ_API bool rz_stack_is_empty (RzStack *s)
 
RZ_API RzStackrz_stack_newf (ut32 n, RzStackFree f)
 
RZ_API bool rz_stack_push (RzStack *s, void *el)
 
RZ_API void * rz_stack_pop (RzStack *s)
 
RZ_API size_t rz_stack_size (RzStack *s)
 
RZ_API void * rz_stack_peek (RzStack *s)
 

Typedef Documentation

◆ RzStack

typedef struct rz_stack_t RzStack

◆ RzStackFree

typedef void(* RzStackFree) (void *ptr)

Definition at line 10 of file rz_stack.h.

Function Documentation

◆ rz_stack_free()

RZ_API void rz_stack_free ( RzStack s)

Definition at line 29 of file stack.c.

29  {
30  if (s) {
31  if (s->free) {
32  int i;
33  for (i = 0; i <= s->top; i++) {
34  s->free(s->elems[i]);
35  }
36  }
37  free(s->elems);
38  free(s);
39  }
40 }
lzma_index ** i
Definition: index.h:629
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
static RzSocket * s
Definition: rtr.c:28

References free(), i, and s.

Referenced by cons_context_deinit(), dfs_node(), GetSegmentHeapBlocks(), rz_cons_break_end(), rz_str_word_set0_stack(), and tree_dfs_node().

◆ rz_stack_is_empty()

RZ_API bool rz_stack_is_empty ( RzStack s)

Definition at line 68 of file stack.c.

68  {
69  return s->top == -1;
70 }

References s.

Referenced by dfs_node(), GetSegmentHeapBlocks(), rz_cons_break_end(), rz_cons_context_break_push(), rz_stack_peek(), rz_str_word_set0_stack(), and tree_dfs_node().

◆ rz_stack_new()

RZ_API RzStack* rz_stack_new ( ut32  n)

Definition at line 6 of file stack.c.

6  {
8  if (!s) {
9  return NULL;
10  }
11  s->elems = RZ_NEWS0(void *, n);
12  if (!s->elems) {
13  free(s);
14  return NULL;
15  }
16  s->n_elems = n;
17  s->top = -1;
18  return s;
19 }
#define NULL
Definition: cris-opc.c:27
int n
Definition: mipsasm.c:19
#define RZ_NEW0(x)
Definition: rz_types.h:284
#define RZ_NEWS0(x, y)
Definition: rz_types.h:282

References free(), n, NULL, RZ_NEW0, RZ_NEWS0, and s.

Referenced by dfs_node(), GetSegmentHeapBlocks(), rz_stack_newf(), rz_str_word_set0_stack(), and tree_dfs_node().

◆ rz_stack_newf()

RZ_API RzStack* rz_stack_newf ( ut32  n,
RzStackFree  f 
)

Definition at line 21 of file stack.c.

21  {
22  RzStack *s = rz_stack_new(n);
23  if (s) {
24  s->free = f;
25  }
26  return s;
27 }
RZ_API RzStack * rz_stack_new(ut32 n)
Definition: stack.c:6
#define f(i)
Definition: sha256.c:46

References f, n, rz_stack_new(), and s.

Referenced by cons_context_init(), and rz_cons_break_end().

◆ rz_stack_peek()

RZ_API void* rz_stack_peek ( RzStack s)

Definition at line 76 of file stack.c.

76  {
77  return rz_stack_is_empty(s) ? NULL : s->elems[s->top];
78 }
RZ_API bool rz_stack_is_empty(RzStack *s)
Definition: stack.c:68

References NULL, rz_stack_is_empty(), and s.

◆ rz_stack_pop()

RZ_API void* rz_stack_pop ( RzStack s)

Definition at line 59 of file stack.c.

59  {
60  if (s->top == -1) {
61  return NULL;
62  }
63  void *res = s->elems[s->top];
64  s->top--;
65  return res;
66 }

References NULL, and s.

Referenced by dfs_node(), GetSegmentHeapBlocks(), rz_cons_context_break_pop(), rz_cons_pop(), rz_str_word_set0_stack(), and tree_dfs_node().

◆ rz_stack_push()

RZ_API bool rz_stack_push ( RzStack s,
void *  el 
)

Definition at line 42 of file stack.c.

42  {
43  if (s->top == s->n_elems - 1) {
44  /* reallocate the stack */
45  s->n_elems *= 2;
46  void **elems = realloc(s->elems, s->n_elems * sizeof(void *));
47  if (!elems) {
48  return false;
49  }
50  s->elems = elems;
51  }
52 
53  s->top++;
54  s->elems[s->top] = el;
55  return true;
56 }
void * realloc(void *ptr, size_t size)
Definition: malloc.c:144

References realloc(), and s.

Referenced by dfs_node(), GetSegmentHeapBlocks(), rz_cons_context_break_push(), rz_cons_push(), rz_str_word_set0_stack(), and tree_dfs_node().

◆ rz_stack_size()

RZ_API size_t rz_stack_size ( RzStack s)

Definition at line 72 of file stack.c.

72  {
73  return (size_t)(s->top + 1);
74 }

References s.