diff -r ddfead6ea863 -r 4784c14aa639 src/ucx/stack.c --- a/src/ucx/stack.c Sun Aug 23 22:02:01 2020 +0200 +++ b/src/ucx/stack.c Sun Aug 23 23:04:17 2020 +0200 @@ -1,7 +1,7 @@ /* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * - * Copyright 2016 Olaf Wintermann. All rights reserved. + * Copyright 2017 Mike Becker, Olaf Wintermann All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: @@ -26,7 +26,8 @@ * POSSIBILITY OF SUCH DAMAGE. */ -#include "stack.h" +#include "ucx/stack.h" + #include static size_t ucx_stack_align(size_t n) { @@ -119,13 +120,15 @@ return; } - size_t len = ucx_stack_topsize(stack); - if (len > n) { - len = n; + if (dest) { + size_t len = ucx_stack_topsize(stack); + if (len > n) { + len = n; + } + + memcpy(dest, stack->top, len); } - memcpy(dest, stack->top, len); - ucx_stack_free(stack, stack->top); } @@ -141,3 +144,22 @@ return 0; } } + +void *ucx_stack_push(UcxStack *stack, size_t n, const void *data) { + void *space = ucx_stack_malloc(stack, n); + if (space) { + memcpy(space, data, n); + } + return space; +} + +void *ucx_stack_pusharr(UcxStack *stack, + size_t nelem, size_t elsize, const void *data) { + + // skip the memset by using malloc + void *space = ucx_stack_malloc(stack, nelem*elsize); + if (space) { + memcpy(space, data, nelem*elsize); + } + return space; +}