diff options
| author | Tyge Løvset <[email protected]> | 2021-09-08 21:16:00 +0200 |
|---|---|---|
| committer | Tyge Løvset <[email protected]> | 2021-09-08 21:16:00 +0200 |
| commit | c86e3d30299baea44f98f153c4b01ea5e244feaa (patch) | |
| tree | 7de3a473408bdee0017d8efa452dd5a095b61177 /include/stc/cstack.h | |
| parent | b9e58749fb77715f4635a45377350a75ce7e0948 (diff) | |
| download | STC-modified-c86e3d30299baea44f98f153c4b01ea5e244feaa.tar.gz STC-modified-c86e3d30299baea44f98f153c4b01ea5e244feaa.zip | |
Updated most examples to newstyle. Some changes in cpque/cstack.
Diffstat (limited to 'include/stc/cstack.h')
| -rw-r--r-- | include/stc/cstack.h | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/include/stc/cstack.h b/include/stc/cstack.h index 42717ee8..984b8fad 100644 --- a/include/stc/cstack.h +++ b/include/stc/cstack.h @@ -32,14 +32,14 @@ #include "template.h"
#if !defined i_fwd
- cx_deftypes(_c_cstack_types, Self, i_val);
+cx_deftypes(_c_cstack_types, Self, i_val);
#endif
typedef i_valraw cx_rawvalue_t;
STC_INLINE Self cx_memb(_init)(void)
{ return (Self){0, 0, 0}; }
-STC_INLINE Self cx_memb(_init_with_capacity)(size_t cap) {
+STC_INLINE Self cx_memb(_with_capacity)(size_t cap) {
Self out = {(cx_value_t *) c_malloc(cap*sizeof(cx_value_t)), 0, cap};
return out;
}
@@ -65,11 +65,13 @@ STC_INLINE cx_value_t* cx_memb(_top)(const Self* self) { return &self->data[self->size - 1]; }
STC_INLINE void cx_memb(_pop)(Self* self)
- { --self->size; }
+ { --self->size; i_valdel(&self->data[self->size]); }
STC_INLINE void cx_memb(_push)(Self* self, cx_value_t value) {
- if (self->size == self->capacity)
- self->data = (cx_value_t *) c_realloc(self->data, (self->capacity = self->size*3/2 + 4)*sizeof value);
+ if (self->size == self->capacity) {
+ self->capacity = self->size*3/2 + 4;
+ self->data = (cx_value_t *)c_realloc(self->data, self->capacity*sizeof value);
+ }
self->data[ self->size++ ] = value;
}
|
