Open SCAP Library
Loading...
Searching...
No Matches
_sexp-value.h
1/*
2 * Copyright 2009 Red Hat Inc., Durham, North Carolina.
3 * All Rights Reserved.
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 *
19 * Authors:
20 * "Daniel Kopecek" <dkopecek@redhat.com>
21 */
22
23#pragma once
24#ifndef _SEXP_VALUE_H
25#define _SEXP_VALUE_H
26
27#include <stddef.h>
28#include <stdint.h>
29#include <stdbool.h>
30#include "_sexp-types.h"
31#include "../../../common/util.h"
32
33
34typedef uint8_t SEXP_valtype_t;
35
36#define SEXP_VALTYPE_EMPTY 0
37#define SEXP_VALTYPE_STRING 1
38#define SEXP_VALTYPE_NUMBER 2
39#define SEXP_VALTYPE_LIST 3
40
41typedef struct {
42 uint32_t refs;
43 size_t size;
45
46typedef struct {
47 uintptr_t ptr;
48 SEXP_valhdr_t *hdr;
49 void *mem;
50 SEXP_valtype_t type;
52
53#define SEXP_VALP_ALIGN (4 > sizeof(void *) ? 4 : sizeof(void *))
54#define SEXP_VALP_MASK (UINTPTR_MAX << 2)
55#define SEXP_VALT_MASK 3
56#define SEXP_VALP_HDR(p) ((SEXP_valhdr_t *)(((uintptr_t)(p)) & SEXP_VALP_MASK))
57
58int SEXP_val_new (SEXP_val_t *dst, size_t vmemsize, SEXP_valtype_t type);
59void SEXP_val_dsc (SEXP_val_t *dst, uintptr_t ptr);
60uintptr_t SEXP_val_ptr (SEXP_val_t *dsc);
61
62uintptr_t SEXP_rawval_incref (uintptr_t valp);
63int SEXP_rawval_decref (uintptr_t valp);
64
65#define SEXP_DEFNUM(s,T) struct SEXP_val_num_##s { T n; SEXP_numtype_t t; }
66#define SEXP_NCASTP(s,p) ((struct SEXP_val_num_##s *)(p))
67#define SEXP_NTYPEP(sz,p) *((SEXP_numtype_t *)(((uint8_t *)(p)) + (sz) - sizeof (SEXP_numtype_t)))
68
69SEXP_numtype_t SEXP_rawval_number_type (SEXP_val_t *dsc);
70
71SEXP_DEFNUM(b, bool);
72SEXP_DEFNUM(f, double);
73SEXP_DEFNUM(i8, int8_t);
74SEXP_DEFNUM(u8, uint8_t);
75SEXP_DEFNUM(i16, int16_t);
76SEXP_DEFNUM(u16, uint16_t);
77SEXP_DEFNUM(i32, int32_t);
78SEXP_DEFNUM(u32, uint32_t);
79SEXP_DEFNUM(i64, int64_t);
80SEXP_DEFNUM(u64, uint64_t);
81
82/*
83 * List
84 */
85
87 void *b_addr;
88 uint16_t offset;
89};
90
91#define SEXP_LCASTP(p) ((struct SEXP_val_list *)(p))
92
94 uintptr_t nxsz;
95 uint16_t real;
96 uint16_t refs;
97 SEXP_t *memb;
98};
99
100size_t SEXP_rawval_list_length (struct SEXP_val_list *list);
101uintptr_t SEXP_rawval_list_copy (uintptr_t s_valp);
102
103uintptr_t SEXP_rawval_lblk_copy (uintptr_t lblkp, uint16_t n_skip);
104uintptr_t SEXP_rawval_lblk_new (uint8_t sz);
105uintptr_t SEXP_rawval_lblk_incref (uintptr_t lblkp);
106int SEXP_rawval_lblk_decref (uintptr_t lblkp);
107
108uintptr_t SEXP_rawval_lblk_fill (uintptr_t lblkp, SEXP_t *s_exp[], uint16_t s_exp_count);
109uintptr_t SEXP_rawval_lblk_add (uintptr_t lblkp, const SEXP_t *s_exp);
110uintptr_t SEXP_rawval_lblk_add1 (uintptr_t lblkp, const SEXP_t *s_exp);
111uintptr_t SEXP_rawval_lblk_last (uintptr_t lblkp);
112SEXP_t *SEXP_rawval_lblk_nth (uintptr_t lblkp, uint32_t n);
113uintptr_t SEXP_rawval_lblk_replace (uintptr_t lblkp, uint32_t n, const SEXP_t *n_val, SEXP_t **o_val);
114int SEXP_rawval_lblk_cb (uintptr_t lblkp, int (*func) (SEXP_t *, void *), void *arg, uint32_t n);
115void SEXP_rawval_lblk_free (uintptr_t lblkp, void (*func) (SEXP_t *));
116void SEXP_rawval_lblk_free1 (uintptr_t lblkp, void (*func) (SEXP_t *));
117
118#define SEXP_LBLK_ALIGN (16 > sizeof(void *) ? 16 : sizeof(void *))
119#define SEXP_LBLKP_MASK (UINTPTR_MAX << 4)
120#define SEXP_LBLKS_MASK 0x0f
121
122#define SEXP_VALP_LBLK(valp) ((struct SEXP_val_lblk *)((uintptr_t)(valp) & SEXP_LBLKP_MASK))
123
124uintptr_t SEXP_rawval_copy(uintptr_t s_valp);
125
126
127#endif /* _SEXP_VALUE_H */
Definition _sexp-value.h:93
Definition _sexp-value.h:86
Definition _sexp-value.h:46
Definition _sexp-value.h:41
Definition sexp-types.h:82