Re: stack module

2020-06-02 Thread Marc Nieper-Wißkirchen
So here is the updated stack module. The name "CLEAR" has been changed
to "DESTROY" as suggested by Bruno. Error checking has been included.
The macro interface remains. Although a macro interface means macros,
the macros are trivial and the type safety wins here, I think. I have
renamed STACK_BASE to STACK_CURRENT_BASE because the base may be
invalidated when items are pushed onto the stack and reallocation has
to happen.

As I haven't heard anything from the FSF yet, I wouldn't mind if you
considered the following in the public domain...

#ifndef _GL_STACK_H
#define _GL_STACK_H

#include 
#include 

#include "assure.h"
#include "xalloc.h"

#define STACK(type)\
  struct {\
type *base;\
size_t size;\
size_t allocated;\
  }

#define STACK_INIT(stack)\
  do\
{\
  (stack).base = NULL;\
  (stack).size = 0;\
  (stack).allocated = 0;\
}\
  while (0)

#define STACK_DESTROY(stack)\
  free ((stack).base)

#define STACK_EMPTY(stack)\
  ((stack).size == 0)

#define STACK_CURRENT_BASE(stack)\
  ((stack).base)

#define STACK_PUSH(stack, item)\
  do\
{\
  if ((stack).size == (stack).allocated)\
(stack).base = x2nrealloc ((stack).base, &(stack).allocated,
sizeof (item)); \
  (stack).base [(stack).size++] = item;\
}\
  while (0)

#define STACK_POP(stack)\
  (affirm (!STACK_EMPTY (stack)), (stack).base [--(stack).size])

#define STACK_DISCARD(stack)\
  (affirm (!STACK_EMPTY (stack)), (--(stack).size))

#define STACK_TOP(stack)\
  (affirm (!STACK_EMPTY (stack)), (stack).base[(stack).size - 1)

#define STACK_SIZE(stack)\
  ((stack).size)

#endif /* _GL_STACK_H */

Am So., 24. Mai 2020 um 21:26 Uhr schrieb Bruno Haible :
>
> Paul Eggert wrote:
> > I don't want to encourage programmers to supply an E with side effects, as 
> > side
> > effects are trouble here.
>
> +1
>



Re: Bundling Gnulib tests with an application

2020-06-02 Thread Marc Nieper-Wißkirchen
Am So., 31. Mai 2020 um 21:51 Uhr schrieb Bruno Haible :

> I'm not aware of a documented way to change this.
>
> Nevertheless, it is probably easy to do: When you look at the generated
> Makefile.in and search for the string 'summary for', you will see that
> it gets the text that follows it from a Makefile variable. This Makefile
> variable gets its default value from the configure file. But if you
> set a value in Makefile.am, it will override the value from the configure
> file - locally in that Makefile only.

That's a great tip, thank you. And, maybe, it is a good idea to
automatically wire this into the test suite generated by Gnulib.