php-internal-docs 8.4.8
Unofficial docs for php/php-src
Loading...
Searching...
No Matches
zend_worklist.h
Go to the documentation of this file.
1/*
2 +----------------------------------------------------------------------+
3 | Zend Engine |
4 +----------------------------------------------------------------------+
5 | Copyright (c) The PHP Group |
6 +----------------------------------------------------------------------+
7 | This source file is subject to version 3.01 of the PHP license, |
8 | that is bundled with this package in the file LICENSE, and is |
9 | available through the world-wide-web at the following url: |
10 | https://www.php.net/license/3_01.txt |
11 | If you did not receive a copy of the PHP license and are unable to |
12 | obtain it through the world-wide-web, please send a note to |
13 | license@php.net so we can mail you a copy immediately. |
14 +----------------------------------------------------------------------+
15 | Authors: Andy Wingo <wingo@igalia.com> |
16 +----------------------------------------------------------------------+
17*/
18
19#ifndef _ZEND_WORKLIST_H_
20#define _ZEND_WORKLIST_H_
21
22#include "zend_arena.h"
23#include "zend_bitset.h"
24
30
31#define ZEND_WORKLIST_STACK_ALLOCA(s, _len, use_heap) do { \
32 (s)->buf = (int*)do_alloca(sizeof(int) * _len, use_heap); \
33 (s)->len = 0; \
34 (s)->capacity = _len; \
35 } while (0)
36
37#define ZEND_WORKLIST_STACK_FREE_ALLOCA(s, use_heap) \
38 free_alloca((s)->buf, use_heap)
39
40static inline void zend_worklist_stack_prepare(zend_arena **arena, zend_worklist_stack *stack, int len)
41{
42 ZEND_ASSERT(len >= 0);
43
44 stack->buf = (int*)zend_arena_calloc(arena, sizeof(*stack->buf), len);
45 stack->len = 0;
46 stack->capacity = len;
47}
48
49static inline void zend_worklist_stack_push(zend_worklist_stack *stack, int i)
50{
51 ZEND_ASSERT(stack->len < stack->capacity);
52 stack->buf[stack->len++] = i;
53}
54
55static inline int zend_worklist_stack_peek(const zend_worklist_stack *stack)
56{
57 ZEND_ASSERT(stack->len);
58 return stack->buf[stack->len - 1];
59}
60
61static inline int zend_worklist_stack_pop(zend_worklist_stack *stack)
62{
63 ZEND_ASSERT(stack->len);
64 return stack->buf[--stack->len];
65}
66
71
72#define ZEND_WORKLIST_ALLOCA(w, _len, use_heap) do { \
73 (w)->stack.buf = (int*)do_alloca(ZEND_MM_ALIGNED_SIZE(sizeof(int) * _len) + sizeof(zend_ulong) * zend_bitset_len(_len), use_heap); \
74 (w)->stack.len = 0; \
75 (w)->stack.capacity = _len; \
76 (w)->visited = (zend_bitset)((char*)(w)->stack.buf + ZEND_MM_ALIGNED_SIZE(sizeof(int) * _len)); \
77 memset((w)->visited, 0, sizeof(zend_ulong) * zend_bitset_len(_len)); \
78 } while (0)
79
80#define ZEND_WORKLIST_FREE_ALLOCA(w, use_heap) \
81 free_alloca((w)->stack.buf, use_heap)
82
83static inline void zend_worklist_prepare(zend_arena **arena, zend_worklist *worklist, int len)
84{
85 ZEND_ASSERT(len >= 0);
86 worklist->visited = (zend_bitset)zend_arena_calloc(arena, sizeof(zend_ulong), zend_bitset_len(len));
87 zend_worklist_stack_prepare(arena, &worklist->stack, len);
88}
89
90static inline int zend_worklist_len(const zend_worklist *worklist)
91{
92 return worklist->stack.len;
93}
94
95static inline bool zend_worklist_push(zend_worklist *worklist, int i)
96{
97 ZEND_ASSERT(i >= 0 && i < worklist->stack.capacity);
98
99 if (zend_bitset_in(worklist->visited, i)) {
100 return 0;
101 }
102
103 zend_bitset_incl(worklist->visited, i);
104 zend_worklist_stack_push(&worklist->stack, i);
105 return 1;
106}
107
108static inline int zend_worklist_peek(const zend_worklist *worklist)
109{
110 return zend_worklist_stack_peek(&worklist->stack);
111}
112
113static inline int zend_worklist_pop(zend_worklist *worklist)
114{
115 /* Does not clear visited flag */
116 return zend_worklist_stack_pop(&worklist->stack);
117}
118
119#endif /* _ZEND_WORKLIST_H_ */
size_t len
Definition apprentice.c:174
char * arena
Definition php_bcmath.h:37
zend_bitset visited
zend_worklist_stack stack
struct _zend_arena zend_arena
Definition zend_arena.h:26
zend_ulong * zend_bitset
Definition zend_bitset.h:29
uint32_t zend_ulong
Definition zend_long.h:43
#define ZEND_ASSERT(c)
struct _zend_worklist_stack zend_worklist_stack
struct _zend_worklist zend_worklist