gpgscm: Allocate small integers in the rodata section.
authorJustus Winter <justus@g10code.com>
Thu, 23 Mar 2017 14:21:36 +0000 (15:21 +0100)
committerJustus Winter <justus@g10code.com>
Fri, 7 Apr 2017 11:50:20 +0000 (13:50 +0200)
commit8640fa880d7050917f4729f2c0cb506e165ee446
tree3fe41a235ac6af9a902555093ff9814194b44995
parentc9c3fe883271868d3b2dd287d295cf6a8f8ffc05
gpgscm: Allocate small integers in the rodata section.

* tests/gpgscm/Makefile.am (gpgscm_SOURCES): Add new file.
* tests/gpgscm/scheme-private.h (struct cell): Move number to the top
of the union so that we can initialize it.
(struct scheme): Remove 'integer_segment'.
* tests/gpgscm/scheme.c (initialize_small_integers): Remove function.
(small_integers): New variable.
(MAX_SMALL_INTEGER): Compute.
(mk_small_integer): Adapt.
(mark): Avoid marking objects already marked.  This allows us to run
the algorithm over objects in the rodata section if they are already
marked.
(scheme_init_custom_alloc): Remove initialization.
(scheme_deinit): Remove deallocation.
* tests/gpgscm/small-integers.h: New file.
--

Allocate small integers from a fixed pool in the rodata section.  This
spares us the initialization, and deduplicates integers across
different processes.  It also makes the integers immutable, increasing
memory safety.

Signed-off-by: Justus Winter <justus@g10code.com>
tests/gpgscm/Makefile.am
tests/gpgscm/scheme-private.h
tests/gpgscm/scheme.c
tests/gpgscm/small-integers.h [new file with mode: 0644]