gdjn  Diff

Differences From Artifact [7c7116050b]:

To Artifact [91836a2225]:


19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37










#define _pstrOf(a) ((pstr){.v=_strDynMem(a), .sz=_strDynSz(a)})

#define _array(t) struct {t* v; size_t sz;}
typedef _array(char) pstr;

#define _pstrLit(a) ((pstr){.v=(a),.sz=sizeof(a)-1})

#define _drop(x) ({ \
	if (x.v) { \
		_free (x.v); \
		x.v = nullptr; \
		x.sz = 0; \
	} \
})
#define _new(T, n) ((T){ \
	.v = _alloc( typeof( ((typeof(T)) {}).v ), n), \
	.sz = n, \
})


















|





|
|
|



>
>
>
>
>
>
>
>
>
>
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#define _pstrOf(a) ((pstr){.v=_strDynMem(a), .sz=_strDynSz(a)})

#define _array(t) struct {t* v; size_t sz;}
typedef _array(char) pstr;

#define _pstrLit(a) ((pstr){.v=(a),.sz=sizeof(a)-1})

#define _drop(x) { \
	if (x.v) { \
		_free (x.v); \
		x.v = nullptr; \
		x.sz = 0; \
	} \
}
#define _new(T, n) ((T){ \
	.v = _alloc( typeof( *((typeof(T)) {}).v ), n), \
	.sz = n, \
})

static inline pstr
pstrDup(pstr p) {
	if (p.v == nullptr) return p;
	if (p.sz == 0) p.sz = strlen(p.v);
	auto n = _new(pstr, p.sz + 1);
	memcpy(n.v, p.v, p.sz);
	n.v[p.sz] = 0;
	n.sz = p.sz;
	return n;
}