libgpg-error.git
5 weeks agocore: Avoid using estream_t in the public API. master
Werner Koch [Mon, 11 Dec 2017 15:33:37 +0000 (16:33 +0100)]
core: Avoid using estream_t in the public API.

* src/gpg-error.h.in: Always use gpgrt_stream-t.
--

estream_t can only be used if GPGRT_ENABLE_ES_MACROS is defined.

Fixes-commit: 1865c0ba1769b407a3c504f1ab0a4278704a9fc1
Signed-off-by: Werner Koch <wk@gnupg.org>
6 weeks agocore: Rename the gpgrt_log_levels enum values.
Werner Koch [Fri, 8 Dec 2017 12:31:07 +0000 (13:31 +0100)]
core: Rename the gpgrt_log_levels enum values.

* src/gpg-error.h.in (gprt_log_levels): Rename to GPGRT_LOGLVL.
--

Explicitly naming them and not distinguishing them from the other log
constants is a Good Thing anyway.  It also helps against the symbol name
clash with the GPGRT enum values from gnupg's logging module.

Signed-off-by: Werner Koch <wk@gnupg.org>
7 weeks agocore: Wrap blocking system calls of the spawn functions.
Werner Koch [Wed, 29 Nov 2017 20:13:11 +0000 (21:13 +0100)]
core: Wrap blocking system calls of the spawn functions.

Signed-off-by: Werner Koch <wk@gnupg.org>
7 weeks agocore: Unify syscall_clamp functions.
Werner Koch [Wed, 29 Nov 2017 19:22:06 +0000 (20:22 +0100)]
core: Unify syscall_clamp functions.

* src/estream.c (_gpgrt_set_syscall_clamp)
(_gpgrt_get_syscall_clamp): Move to ...
* src/syscall-clamp.c: new file.
(_gpgrt_pre_syscall, _gpgrt_post_syscall): New.
* src/Makefile.am (libgpg_error_la_SOURCES): Add that file.
* src/estream.c: Replace the syscall wrapper with the new functions.
* src/posix-lock.c: Ditto.
* src/w32-lock.c: Ditto.
* src/posix-thread.c: Ditto.
* src/w32-thread.c: Ditto.

Signed-off-by: Werner Koch <wk@gnupg.org>
7 weeks agocore: Implement the spawn functions.
Werner Koch [Wed, 29 Nov 2017 18:29:18 +0000 (19:29 +0100)]
core: Implement the spawn functions.

* src/gpg-error.h.in  (GPGRT_SPAWN_NONBLOCK): New const.
(GPGRT_SPAWN_RUN_ASFW): New const.
(GPGRT_SPAWN_DETACHED): New const.
(gpgrt_make_pipe): New function.
(gpgrt_create_pipe): New macro.
(gpgrt_create_inbound_pipe): New macro.
(gpgrt_create_outbound_pipe): New macro.
(gpgrt_spawn_process): New function.
(gpgrt_spawn_process_fd): New function.
(gpgrt_spawn_process_detached): New function.
(gpgrt_wait_process): New function.
(gpgrt_wait_processes): New function.
(gpgrt_kill_process): New function.
(gpgrt_release_process): New function.
* src/gpg-error.def.in, src/gpg-error.vers: Add new functions.
* src/visibility.c, src/visibility.h: Add wrappers for new functions.
* src/spawn-posix.c: Rework to better fit the use in gpgrt.  Rename
all public function with a _gpgrt prefix.
* src/spawn-w32.c: Ditto.
* src/gpgrt-int.h: Likewise.
* src/Makefile.am (arch_sources): Add spawn-posix.c and spawn-w32.c.
* src/w32-add.h: Add pid_t typedef as a temporary hack.
* configure.ac: Check for signal.h and getrlimit.
(AC_FUNC_FORK): New.
--

This does build but porting the tests and further changes are
required.  Don't assume that the API for the new fucntions is stable.

Signed-off-by: Werner Koch <wk@gnupg.org>
7 weeks agoImport and relicense exechelp* functions from GnuPG.
Werner Koch [Wed, 29 Nov 2017 10:48:52 +0000 (11:48 +0100)]
Import and relicense exechelp* functions from GnuPG.

* src/spawn-posix.c: New.  Taken from GnuPG's exechelp-posix.c.
* src/spawn-w32.c: New.  Taken from GnuPG's exechelp-w32.c.
* src/gpgrt-int.h: Include prototypes from GnuPG's exechelp.h.
--

The original files were under (LGPL-3.0+ OR GPL-2.0+) and have
entirely been written by g10 Code employees.  Being the responsible
person at g10 Code, I endorse the license change to LGPL-2.1.

Signed-off-by: Werner Koch <wk@gnupg.org>
7 weeks agocore: Change new functions to return gpg_err_code_t.
Werner Koch [Tue, 28 Nov 2017 15:36:12 +0000 (16:36 +0100)]
core: Change new functions to return gpg_err_code_t.

* src/gpg-error.h.in (gpgrt_sentenv, gpgrt_mkdir, gpgrt_chdir): Change
return type to gpg_err_code_t.
* src/sysutils.c (_gpgrt_setenv): Implement that.
(_gpgrt_mkdir): Ditto.
(_gpgrt_chdir): Ditto.
* gpgscm/ffi.c (do_setenv, do_mkdir): Adjust for this change.
--

The functions are already a bit different and thus it is useful to let
them return a gpg-error style error code and don't let the user
implement that for each call.

Signed-off-by: Werner Koch <wk@gnupg.org>
7 weeks agogpgscm: Some adjustments for use in gpgrt.
Werner Koch [Tue, 28 Nov 2017 15:17:23 +0000 (16:17 +0100)]
gpgscm: Some adjustments for use in gpgrt.

* gpgscm/Makefile.am: Remove cruft leftover from GnuPG.  Link to the
just build libgpg-error.
* gpgscm/private.h: Include gpgrt.h and provide i18n macros.
(xfree, xtrymalloc, xtrycalloc, xtryrealloc): New macros.
(xmalloc, xstrdup): New inline functions.
* gpgscm/main.c: Remove inclusion of gcrypt.h and gpg-error.h.  Remove
all other gnupg specific headers.
(opts, parse_arguments): Temporary comment out.
(main): Adjust for use with gpgrt.  Temporary comment out some stuff.
* gpgscm/ffi-private.h: Include local gpgrt.h instead of gpg-error.h.
* gpgscm/ffi.h: Ditto.
* gpgscm/ffi.c: Remove gpg-error.h and headers from GnuPG.
(do_getenv): Use gpgrt_getenv.
(do_setenv): Use gpgrt_setenv.
(do_mkdtemp): Temporary return an error.
(unlink_recursively): Use gpgrt_bsprintf.
(do_getcwd): Use gpgrt_getcwd.
(do_mkdir): Use gpgrt_mkdir.
(do_get_isotime): Temporary return an error.
(do_get_time): Directly use time().
--

Note that this does not yet compile because the spawn functions from
GnuPG are missing.  There are two other problems as well:

 - We don't have GnuPG's isotime fucntions.  We need to see whether we
   want to support them in gpgrt.  That might be useful in libksba.

 - gpgrt_mkdtemp does not work.  We do not want to link to Libgcrypt,
   which is the way mkdtemp was written for GnuPG.  We should get a
   more straight implementation.

Signed-off-by: Werner Koch <wk@gnupg.org>
7 weeks agocore: New API functions gpgrt_mkdir, gpgrt_chdir, gpgrt_getcwd.
Werner Koch [Tue, 28 Nov 2017 14:39:56 +0000 (15:39 +0100)]
core: New API functions gpgrt_mkdir, gpgrt_chdir, gpgrt_getcwd.

* src/gpg-error.h.in (gpgrt_mkdir, gpgrt_chdir, gpgrt_getcwd): New.
* src/visibility.c, src/visibility.h: Add wrappers.
* src/gpg-error.vers, src/gpg-error.def.in: Add them.
* src/sysutils.c (modestr_to_mode): New.
(_gpgrt_mkdir, _gpgrt_chdir, _gpgrt_getcwd): New.
* m4/gnupg-misc.m4: New.
* m4/Makefile.am (EXTRA_DIST): Add new M4 file.
* configure.ac: Call new GNUPG_FUNC_MKDIR_TAKES_ONE_ARG.
(AC_CHECK_FUNCS): Add stat.
--

The code has been taken from GnuPG.  _gpgrt_mkdir was originally
written by me as gnupg_mkdir and here relicensed to LGPLv2.1+.
_gpgrt_getcwd was originally written by in 2007 and also here
relicensed to LGPLv2.1.  The new M4 macro was also written by me for
use in in GnuPG; it has been taken from GnUPG's acinclude.m4, moved to
its own file here, and relicensed to FSFULLR.

Signed-off-by: Werner Koch <wk@gnupg.org>
7 weeks agocore: Prepare to build with gpgscm.
Werner Koch [Tue, 28 Nov 2017 11:54:13 +0000 (12:54 +0100)]
core: Prepare to build with gpgscm.

* configure.ac: New option --enable-gpgscm.  Create gpgscm/Makefile.
(GPGRT_ENABLE_LOG_MACROS): Define.
* Makefile.am (SUBDIRS): Add gpgscm
* src/logging.c (_gpgrt_logv_clock): Do not use the log_debug macro.
--

Note that gpscm does not yet build.

Signed-off-by: Werner Koch <wk@gnupg.org>
7 weeks agocore: New API functions gpgrt_getenv and gpgrt_setenv.
Werner Koch [Tue, 28 Nov 2017 11:34:12 +0000 (12:34 +0100)]
core: New API functions gpgrt_getenv and gpgrt_setenv.

* src/gpg-error.h.in (gpgrt_getenv, gpgrt_setenv): New.
(gpgrt_unsetenv): New macro.
* src/gpg-error.vers, src/gpg-error.def.in: Add them.
* src/visibility.c (gpgrt_getenv, gpgrt_setenv): New.
* src/visibility.h: Add them.
* src/sysutils.c: Include string.h and on Windows windows.h.
(_gpgrt_getenv): New.
(_gpgrt_setenv): New.
--

These functions are wrappers to cope with Windows problems.  The code
is similar to what we have in GnuPG but not identical.

Requires better testing.

Signed-off-by: Werner Koch <wk@gnupg.org>
7 weeks agocore: Install new files gpgrt.m4 and gpgrt-config.
Werner Koch [Mon, 27 Nov 2017 14:40:01 +0000 (15:40 +0100)]
core: Install new files gpgrt.m4 and gpgrt-config.

* src/gpgrt.m4: New.  Bascially a copy of libgpg-error.m4
* src/gpg-error-config.in: Decide which name to print.
* src/Makefile.am (nodist_bin_SCRIPTS): Add gpgrt-config.
(m4data_DATA): Add gpgrt.m4
(EXTRA_DIST): Add gpgrt.m4.
(BUILT_SOURCES): Add gpgrt-config.
(CLEANFILES): Add gpgrt-config.
(gpgrt-config): Create from gpg-error-config.
--

These files can be used instead of gpg-error-config or gpg-error.m4.
The hope is that providing them early will ease an eventual migration
from libgpg-error to libgpgrt easier.

Signed-off-by: Werner Koch <wk@gnupg.org>
7 weeks agodoc: Add a comment to the Windows registry functions.
Werner Koch [Mon, 27 Nov 2017 13:48:15 +0000 (14:48 +0100)]
doc: Add a comment to the Windows registry functions.

--

7 weeks agocore: Avoid endless recursion if log_set_sink has not been used.
Werner Koch [Mon, 27 Nov 2017 13:47:11 +0000 (14:47 +0100)]
core: Avoid endless recursion if log_set_sink has not been used.

* src/logging.c (_gpgrt_log_set_sink): Do not call gf_is_valid if the
default sink has been requested.

Signed-off-by: Werner Koch <wk@gnupg.org>
7 weeks agocore: Add new macro log_assert to the API.
Werner Koch [Mon, 27 Nov 2017 12:40:23 +0000 (13:40 +0100)]
core: Add new macro log_assert to the API.

* src/gpg-error.h.in (log_assert): New macro.

Signed-off-by: Werner Koch <wk@gnupg.org>
8 weeks agocore: Do not use the estream_t alias in gpg-error.h.
Werner Koch [Wed, 22 Nov 2017 10:26:06 +0000 (11:26 +0100)]
core: Do not use the estream_t alias in gpg-error.h.

* src/gpg-error.h.in: Use gpgrt_stream_t in prototypes.
--

estream_t is not necessary enabled so to keep the namespace clean.

Signed-off-by: Werner Koch <wk@gnupg.org>
2 months agow32: Avoid unused code warning.
Werner Koch [Fri, 17 Nov 2017 16:34:04 +0000 (17:34 +0100)]
w32: Avoid unused code warning.

* src/w32-estream.c (_gpgrt_w32_poll) [!ENABLE_TRACING]: Do not use
waitinfo.
--

Signed-off-by: Werner Koch <wk@gnupg.org>
2 months agow32: Add new API fucntion gpgrt_w32_reg_query_string.
Werner Koch [Fri, 17 Nov 2017 16:25:58 +0000 (17:25 +0100)]
w32: Add new API fucntion gpgrt_w32_reg_query_string.

* src/w32-reg.c: New.
* src/w32-add.h: Add gpgrt_w32_reg_query_string.
* src/visibility.c (gpgrt_w32_reg_query_string): New wrapper.
* src/gpg-error.def.in: Add gpgrt_w32_reg_query_string.
* configure.ac (ac_check_funcs): Add stpcpy.
* src/Makefile.am (arch_sources): Add w32-reg.c
(socklibs): New.
(libgpg_error_la_LIBADD): Add socklibs.
* src/gpgrt-int.h (xfree, xtrymalloc, xtrycalloc)
(xtryrealloc): New internal macros.
(_gpgrt_stpcpy, stpcpy): New replacement fucntion and macro.
* src/logging.c (_gpgrt_logv_internal): Use new registry query
function and add standard registry key.
--

This also fixes the build failure on Widnwos for logging.c.

The code for gpgrt_w32_reg_query_string has been taken from the
function read_w32_registry_string in w32-utils.c in the GPGME package.

Signed-off-by: Werner Koch <wk@gnupg.org>
2 months agocore: New API functions gpgrt_strdup and gpgrt_strconcat.
Werner Koch [Fri, 17 Nov 2017 10:26:03 +0000 (11:26 +0100)]
core: New API functions gpgrt_strdup and gpgrt_strconcat.

* src/visibility.c (gpgrt_strdup): New API fucntion.
(gpgrt_strconcat): New API fucntion.
* src/visibility.h: Add corresponding macros.
* src/gpg-error.def.in: Add them.
* src/gpg-error.vers: Add them.
* src/gpgrt-int.h (DIM): New macro.
* src/init.c (_gpgrt_strdup): New.
(_gpgrt_strconcat_core): New.
(_gpgrt_strconcat): New.
--

Signed-off-by: Werner Koch <wk@gnupg.org>
2 months agocore: New API functions gpgrt_malloc, gpgrt_calloc, and gpgrt_realloc.
Werner Koch [Fri, 17 Nov 2017 10:00:39 +0000 (11:00 +0100)]
core: New API functions gpgrt_malloc, gpgrt_calloc, and gpgrt_realloc.

* src/visibility.c (gpgrt_realloc): New API function.
(gpgrt_malloc): New API function.
(gpgrt_calloc): New API function.
* src/visibility.h: Add corresponding macros.
* src/gpg-error.def.in: Add them.
* src/gpg-error.vers: Add them.
* src/init.c (_gpgrt_calloc): New.
* src/gpg-error.h.in: Add prototypes.

Signed-off-by: Werner Koch <wk@gnupg.org>
2 months agocore: Add logging API.
Werner Koch [Fri, 17 Nov 2017 08:37:54 +0000 (09:37 +0100)]
core: Add logging API.

* src/visibility.c (gpgrt_get_errorcount): New API.
(gpgrt_inc_errorcount): New API.
(gpgrt_log_set_sink): New API.
(gpgrt_log_set_socket_dir_cb): New API.
(gpgrt_log_set_pid_suffix_cb): New API.
(gpgrt_log_set_prefix): New API.
(gpgrt_log_get_prefix): New API.
(gpgrt_log_test_fd): New API.
(gpgrt_log_get_fd): New API.
(gpgrt_log_get_stream): New API.
(gpgrt_log): New API.
(gpgrt_logv): New API.
(gpgrt_logv_prefix): New API.
(gpgrt_log_string): New API.
(gpgrt_log_info): New API.
(gpgrt_log_error): New API.
(gpgrt_log_fatal): New API.
(gpgrt_log_bug): New API.
(gpgrt_log_debug): New API.
(gpgrt_log_debug_string): New API.
(gpgrt_log_printf): New API.
(gpgrt_log_flush): New API.
(gpgrt_log_printhex): New API.
(gpgrt_log_clock): New API.
(_gpgrt_log_assert): New function for the ABI.
* src/visibility.h: Add corresponding macros.
* src/gpg-error.def.in: Add new functions.
* src/gpg-error.vers: Add new functions.
* src/gpg-error.h.in (GPGRT_LOG_WITH_PREFIX): New constant.
(GPGRT_LOG_WITH_TIME): New constant.
(GPGRT_LOG_WITH_PID): New constant.
(GPGRT_LOG_RUN_DETACHED): New constant.
(GPGRT_LOG_NO_REGISTRY): New constant.
(GPGRT_LOG_BEGIN): New enum value.
(GPGRT_LOG_CONT): New enum value.
(GPGRT_LOG_INFO): New enum value.
(GPGRT_LOG_WARN): New enum value.
(GPGRT_LOG_ERROR): New enum value.
(GPGRT_LOG_FATAL): New enum value.
(GPGRT_LOG_BUG): New enum value.
(GPGRT_LOG_DEBUG): New enum value.
(log_get_errorcount, log_inc_errorcount, log_set_file, log_set_fd)
(log_set_stream, log_set_socket_dir_cb, log_set_pid_suffix_cb)
(log_set_prefix, log_get_prefix, log_test_fd, log_get_fd)
(log_get_stream, log_log, log_logv, log_logv_prefix, log_string)
(log_bug, log_fatal, log_error, log_info, log_debug, log_debug_string)
(log_printf, log_printhex, log_clock)
(log_flush) [GPGRT_ENABLE_LOG_MACROS]: New wrapper macros.
(gpgrt_assert): New macro.
* src/gpgrt-int.h: Add prototypes for logging.c.
(gpgrt_assert): Redefine for internal use.
* src/logging.h: Remove.
* src/logging.c: Include gpgrt-int.h instead of the stuff from GnuPG.
Use _gpgrt malloc funcsions and the internal versions of the estream
functions.  Rename all public fucntions with a _gpgrt_ prefix.
(print_prefix): Return the printed length.
(_gpgrt_logv_internal): Ditto.
(_gpgrt_log_printhex): Change order of args and turn into a printf
like function.
(_gpgrt_logv_printhex): New. Take the core of the former
log_printhex.
(_gpgrt_log_clock): Turn into a printf like functions.
(_gpgrt_logv_clock): New.  Take the core of the former log_clock.
--

This logging API is a slightly modified version of what we are using
in GnuPG.

Signed-off-by: Werner Koch <wk@gnupg.org>
2 months agoNew configure options and macros for internal use.
Werner Koch [Fri, 17 Nov 2017 08:18:13 +0000 (09:18 +0100)]
New configure options and macros for internal use.

* configure.ac: Add option --enable-log-clock.
* configure.ac: Add option --enable-werror.
* src/sysutils.c: New.
* src/Makefile.am (libgpg_error_la_SOURCES): Add sysutils.c
* src/gpgrt-int.h: Add internal i18n macros and hacks to make working
with sockets easier.
(es_stdin, es_stdout, es_stderr): New internal macros.
(snprintf): New macro.

Signed-off-by: Werner Koch <wk@gnupg.org>
3 months agocore: Change license of logging.[ch] to LGPLv2.1
Werner Koch [Thu, 5 Oct 2017 18:56:06 +0000 (20:56 +0200)]
core: Change license of logging.[ch] to LGPLv2.1

--

This file has a long history.  I was first written by me in 1998 for
GnuPG under the name logger.c.  In 2010 it was renamed to
logging.c. Almost everything was written by me.  A few minor fixes are
from g10 Code employees and some other people.

Signed-off-by: Werner Koch <wk@gnupg.org>
3 months agocore: Import of logging.[ch] from GnuPG
Werner Koch [Thu, 5 Oct 2017 18:34:03 +0000 (20:34 +0200)]
core: Import of logging.[ch] from GnuPG

--

Taken from GnuPG master
commit 98c260e057e7829580da99f0c8e0037a3896bfae

Signed-off-by: Werner Koch <wk@gnupg.org>
3 months agogpgscm: Add required configure checks.
Werner Koch [Thu, 5 Oct 2017 16:38:21 +0000 (18:38 +0200)]
gpgscm: Add required configure checks.

* configure.ac: Add new checks.
* m4/readline.m4: New.  Taken from gnupg.
* m4/Makefile.am (EXTRA_DIST): Add it.

Signed-off-by: Werner Koch <wk@gnupg.org>
3 months agogpgscm: Change license from GPLv3+ to LGPLv2.1+
Werner Koch [Thu, 5 Oct 2017 16:10:39 +0000 (18:10 +0200)]
gpgscm: Change license from GPLv3+ to LGPLv2.1+

--

All changes to TinySCHEME were done by employees of g10 Code GmbH and
some minor things by a contractor.

Signed-off-by: Werner Koch <wk@gnupg.org>
3 months agogpgscm: Import gpgscm subdir from the gnupg repo
Werner Koch [Thu, 5 Oct 2017 15:29:28 +0000 (17:29 +0200)]
gpgscm: Import gpgscm subdir from the gnupg repo

--

The gpgscm directory has been filtered out from GnuPG master at
commit 98c260e057e7829580da99f0c8e0037a3896bfae

3 months agogpgscm: Move files to a gpgscm subdirectory.
Werner Koch [Thu, 5 Oct 2017 15:27:09 +0000 (17:27 +0200)]
gpgscm: Move files to a gpgscm subdirectory.

--

Note that we used

  git filter-branch --subdirectory-filter tests/gpgscm

in gnupg master to filter out the gpgscm part.  This commit merely
moves these files to a subdirectory which will be used in libgpg-error
for gpgscm.

Signed-off-by: Werner Koch <wk@gnupg.org>
4 months agogpgscm: Fix -Wimplicit-fallthrough warnings.
Justus Winter [Mon, 21 Aug 2017 12:49:29 +0000 (14:49 +0200)]
gpgscm: Fix -Wimplicit-fallthrough warnings.

* tests/gpgscm/scheme.c (CASE): Rearrange so that the case statement
is at the front.
(Eval_Cycle): Improve fallthrough annotations.

Signed-off-by: Justus Winter <justus@g10code.com>
5 months agobuild: New configure option --enable-all-tests.
Werner Koch [Tue, 8 Aug 2017 15:28:25 +0000 (17:28 +0200)]
build: New configure option --enable-all-tests.

* configure.ac: New option --enable-all-tests.
* tests/gpgscm/ffi.c (ffi_init): New gloabl var *run-all-tests*.
* tests/openpgp/all-tests.scm (all-tests): Use that var instead
of *maintainer-mode*.
* Makefile.am (AM_DISTCHECK_CONFIGURE_FLAGS): Add --enable-all-tests.
--

It is better to have a separate option to run all tests than to put
this on top of --enable-maintainer-mode.  This way we can also make
sure to run all tests during "make distcheck".

Signed-off-by: Werner Koch <wk@gnupg.org>
5 months agogpgscm: Make the test summary stand out
Werner Koch [Tue, 8 Aug 2017 11:47:00 +0000 (13:47 +0200)]
gpgscm: Make the test summary stand out

* tests/gpgscm/tests.scm (test-pool): Add delimiter lines.
--

This is to make those summaries a bit more simlar to those from
automake.

Signed-off-by: Werner Koch <wk@gnupg.org>
5 months agotests: Do not run all tests unless in maintainer mode.
Justus Winter [Mon, 7 Aug 2017 09:15:56 +0000 (11:15 +0200)]
tests: Do not run all tests unless in maintainer mode.

* configure.ac: Leak the maintainer mode flag into 'config.h'.
* tests/gpgscm/ffi.c: Pass it into the scheme environment.
* tests/openpgp/all-tests.scm: Only run tests against non-default
configurations (keyring, extended-key-format) in maintainer mode.
--

Werner is concerned that the tests do take up too much time and asked
me to reduce the runtime of the tests for normal users.

Signed-off-by: Justus Winter <justus@g10code.com>
6 months agogpgscm,w32: Fix testing for absolute paths.
Justus Winter [Tue, 18 Jul 2017 14:15:45 +0000 (16:15 +0200)]
gpgscm,w32: Fix testing for absolute paths.

* tests/gpgscm/main.c (path_absolute_p): New function.
(load): Use new function.

Signed-off-by: Justus Winter <justus@g10code.com>
6 months agogpgscm: Library improvements.
Justus Winter [Fri, 14 Jul 2017 10:57:41 +0000 (12:57 +0200)]
gpgscm: Library improvements.

* tests/gpgscm/repl.scm (prompt-yes-no?): New function.
* tests/gpgscm/tests.scm (pathsep-split): Likewise.
(pathsep-join): Likewise.
(with-path): Use the new function.

Signed-off-by: Justus Winter <justus@g10code.com>
6 months agogpgscm: Fail early if the test setup fails.
Justus Winter [Fri, 14 Jul 2017 10:55:01 +0000 (12:55 +0200)]
gpgscm: Fail early if the test setup fails.

* tests/gpgscm/tests.scm (make-environment-cache): Check status code
of setup script.

Signed-off-by: Justus Winter <justus@g10code.com>
6 months agogpgscm: Make loading of modules less verbose.
Justus Winter [Thu, 13 Jul 2017 14:29:25 +0000 (16:29 +0200)]
gpgscm: Make loading of modules less verbose.

* tests/gpgscm/main.c (load): Increase logging threshold.

Signed-off-by: Justus Winter <justus@g10code.com>
6 months agogpgscm: Make it impossible to catch '*interpreter-exit*'.
Justus Winter [Tue, 11 Jul 2017 14:07:39 +0000 (16:07 +0200)]
gpgscm: Make it impossible to catch '*interpreter-exit*'.

* tests/gpgscm/init.scm (throw'): Make it impossible to catch
'*interpreter-exit*'.  This fixes 'exit' (and with it 'fail') inside
'catch' statements.

Signed-off-by: Justus Winter <justus@g10code.com>
6 months agosyscfg: Add lock-obj-pub file for ia64-unknown-linux-gnu.
Werner Koch [Wed, 5 Jul 2017 10:08:26 +0000 (12:08 +0200)]
syscfg: Add lock-obj-pub file for ia64-unknown-linux-gnu.

* src/syscfg/lock-obj-pub.ia64-unknown-linux-gnu.h: new.
* src/Makefile.am (lock_obj_pub): Add it.
--

GnuPG-bug-id: 3242
Signed-off-by: Werner Koch <wk@gnupg.org>
6 months agoyat2m: Change bug report address.
Werner Koch [Wed, 5 Jul 2017 08:18:53 +0000 (10:18 +0200)]
yat2m: Change bug report address.

--

6 months agoyat2m: Use version from libgpg-error.
Werner Koch [Wed, 5 Jul 2017 08:14:00 +0000 (10:14 +0200)]
yat2m: Use version from libgpg-error.

* doc/yat2m.c (VERSION): Define as PACKAGE_VERSION.
* doc/Makefile.am (yat2m): Pass PACKAGE_VERSION with -D.

Signed-off-by: Werner Koch <wk@gnupg.org>
6 months agobuild: Install yat2m.
Werner Koch [Wed, 5 Jul 2017 08:08:13 +0000 (10:08 +0200)]
build: Install yat2m.

* doc/Makefile.am (install-exec-hook): New.
(uninstall-local): Uninstall yat2m.

Signed-off-by: Werner Koch <wk@gnupg.org>
6 months agoyat2m: Take care of SOURCE_DATE_EPOCH.
Werner Koch [Wed, 5 Jul 2017 07:14:38 +0000 (09:14 +0200)]
yat2m: Take care of SOURCE_DATE_EPOCH.

* doc/yat2m.c (main): Set a default for OPT_DATE.

Signed-off-by: Werner Koch <wk@gnupg.org>
6 months agodoc: Typo fix
Werner Koch [Wed, 5 Jul 2017 07:01:59 +0000 (09:01 +0200)]
doc: Typo fix

--

6 months agodoc: minor fix for @xref.
NIIBE Yutaka [Tue, 20 Sep 2016 06:41:36 +0000 (15:41 +0900)]
doc: minor fix for @xref.

* doc/yat2m.c (proc_texi_cmd): Captalize "see" for xref.

6 months agodoc: Implement simple '@ref'erences.
Justus Winter [Mon, 19 Sep 2016 13:25:01 +0000 (15:25 +0200)]
doc: Implement simple '@ref'erences.

* doc/yat2m.c (proc_texi_cmd): Handle '@ref'.

Signed-off-by: Justus Winter <justus@g10code.com>
7 months agogpgscm: Limit the number of parallel jobs.
Justus Winter [Mon, 19 Jun 2017 14:31:25 +0000 (16:31 +0200)]
gpgscm: Limit the number of parallel jobs.

* ffi.c (do_wait_processes): Suppress the timeout error.
* tests.scm (semaphore): New definition.
(test-pool): Only run a bounded number of tests in parallel.
(test::started?): New function.
(run-tests-parallel): Do not report results, do not start the tests.
(run-tests-sequential): Adapt.
(run-tests): Parse the number of parallel jobs.
--

This change limits the number of tests that are run in parallel.  This
way we do not overwhelm the operating systems' scheduler.  As a
side-effect, we also get more accurate runtime information, and it
will be easy to implement timeouts on top of this.

Use TESTFLAGS to limit the number of jobs:

    $ make check-all TESTFLAGS=--parallel=16

Signed-off-by: Justus Winter <justus@g10code.com>
7 months agogpgscm: Improve option parsing.
Justus Winter [Mon, 19 Jun 2017 14:29:08 +0000 (16:29 +0200)]
gpgscm: Improve option parsing.

* tests/gpgscm/tests.scm (flag): Accept arguments of the form
'--foo=bar'.

Signed-off-by: Justus Winter <justus@g10code.com>
7 months agogpgscm: Improve error handling of foreign functions.
Justus Winter [Mon, 19 Jun 2017 14:24:18 +0000 (16:24 +0200)]
gpgscm: Improve error handling of foreign functions.

* tests/gpgscm/ffi.scm (ffi-fail): Do not needlessly join the error
message.

Signed-off-by: Justus Winter <justus@g10code.com>
7 months agogpgscm: Improve error reporting.
Justus Winter [Mon, 19 Jun 2017 14:13:24 +0000 (16:13 +0200)]
gpgscm: Improve error reporting.

* tests/gpgscm/init.scm (throw'): Guard against 'args' being atomic.
* tests/gpgscm/scheme.c (Eval_Cycle): Remove any superfluous colons in
error messages.

Signed-off-by: Justus Winter <justus@g10code.com>
7 months agoAlign 'es_poll' semantics closer with POSIX.
Justus Winter [Wed, 17 May 2017 13:42:34 +0000 (15:42 +0200)]
Align 'es_poll' semantics closer with POSIX.

* src/estream.c (_gpgrt_poll): Do not return early if some streams are
found to be ready before even polling the others.
--

POSIX mandates that all streams are examined and returning early
violates that.  It also imposes an order on how the callee serves the
streams, which might be incompatible with the order the callee wants
to serve them, leading to deadlocks.

Signed-off-by: Justus Winter <justus@g10code.com>
7 months agobuild: Prepend the maintainer CFLAGS.
Justus Winter [Wed, 17 May 2017 13:41:48 +0000 (15:41 +0200)]
build: Prepend the maintainer CFLAGS.

* configure.ac: Prepend the maintainer CFLAGS making it possible to
override e.g. the optimization level for debugging.

Signed-off-by: Justus Winter <justus@g10code.com>
7 months agoFix memory leak for estream.
NIIBE Yutaka [Tue, 30 May 2017 11:46:12 +0000 (20:46 +0900)]
Fix memory leak for estream.

* src/estream.c (do_list_remove): Free the item.
(do_close): Free the buffer.

Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
8 months agogpgscm: Fix checking for opcode arguments.
Justus Winter [Wed, 17 May 2017 14:10:37 +0000 (16:10 +0200)]
gpgscm: Fix checking for opcode arguments.

* tests/gpgscm/scheme.c (Eval_Cycle): Update 'pcd' after dispatching
an instruction.

Fixes-commit: 9c6407d17e0cb9f4a370b1b83e7816577ec7d29d
Signed-off-by: Justus Winter <justus@g10code.com>
8 months agotests: Make it possible to run all tests using our infrastructure.
Justus Winter [Mon, 20 Mar 2017 09:30:08 +0000 (10:30 +0100)]
tests: Make it possible to run all tests using our infrastructure.

* Makefile.am (TESTS_ENVIRONMENT): New variable.
(check-all): New phony target to run all tests.
* tests/gpgme/gpgme-defs.scm (have-gpgme?): New function that tests
whether the GPGME test suite is available instead of exiting the
process.
* tests/gpgscm/init.scm (export): New macro.
* tests/gpgscm/tests.scm (run-tests): New function.
(load-tests): Likewise.
* tests/gpgme/run-tests.scm: Simplify and move the parsing of the list
of tests to 'all-tests.scm'.
* tests/gpgsm/run-tests.scm: Likewise.
* tests/migrations/run-tests.scm: Likewise.
* tests/openpgp/run-tests.scm: Likewise.
* tests/gpgme/Makefile.am: To select the tests to run, use the
variable 'TESTS'.  This harmonizes the interface with the automake
test suite.
* tests/gpgsm/Makefile.am: Likewise.
* tests/migrations/Makefile.am: Likewise.
* tests/openpgp/Makefile.am: Likewise.
* tests/openpgp/README: Likewise.
* agent/all-tests.scm: New file.
* common/all-tests.scm: Likewise.
* g10/all-tests.scm: Likewise.
* g13/all-tests.scm: Likewise.
* tests/gpgme/all-tests.scm: Likewise.
* tests/gpgsm/all-tests.scm: Likewise.
* tests/migrations/all-tests.scm: Likewise.
* tests/openpgp/all-tests.scm: Likewise.
* tests/run-tests.scm: Likewise.
--

This change allows us to run all tests in parallel and write one XML
report capturing the results of every test.  It also lays the
foundation to parametrize test suites.

Signed-off-by: Justus Winter <justus@g10code.com>
8 months agotests: Move the makefile parser.
Justus Winter [Mon, 20 Mar 2017 09:21:06 +0000 (10:21 +0100)]
tests: Move the makefile parser.

* tests/gpgme/gpgme-defs.scm (parse-makefile, parse-makefile-expand):
Move...
* tests/gpgscm/makefile.scm: ... here.
* tests/gpgscm/Makefile.am (EXTRA_DIST): Add new file.

Signed-off-by: Justus Winter <justus@g10code.com>
8 months agogpgscm: Make it possible to set the logfile name.
Justus Winter [Thu, 11 May 2017 12:44:33 +0000 (14:44 +0200)]
gpgscm: Make it possible to set the logfile name.

* tests/gpgscm/tests.scm (test): Only set the default log filename
when it has not been set before.

Signed-off-by: Justus Winter <justus@g10code.com>
8 months agotests: Support tests that are expected to fail.
Justus Winter [Thu, 4 May 2017 13:12:49 +0000 (15:12 +0200)]
tests: Support tests that are expected to fail.

* tests/gpgscm/tests.scm (test-pool): Rework reporting.  Filter using
the computed test status instead of the return value.  Also print the
new categories 'failed expectedly' and 'passed unexpectedly'.
(test): If a test ends with a bang (!), it is expected to fail.  Adapt
status, status-string, and xml accordingly.
--

Allow tests to be marked as being expected to fail by appending a bang
(!) to the tests name.  If such a test fails, it will not be counted
as failure, but will still be prominently displayed in the report.  If
it succeeds unexpectedly, this is counted as a failure.

Fixes T3134.

GnuPG-bug-id: 3134
Signed-off-by: Justus Winter <justus@g10code.com>
8 months agogpgscm: Create and re-use frame objects.
Justus Winter [Thu, 6 Apr 2017 09:52:36 +0000 (11:52 +0200)]
gpgscm: Create and re-use frame objects.

* tests/gpgscm/scheme-private.h (struct scheme): New field
'frame_freelist'.
* tests/gpgscm/scheme.c (enum scheme_types): New type 'T_FRAME'.
(type_to_string): Handle new type.
(settype): New macro.
(gc_disable): Make sure there is at least one frame in the free list.
(mark): Handle frame objects.
(finalize_cell): Likewise.
(dump_stack_initialize): Initialize free list.
(dump_stack_free): Simplify.
(frame_length): New variable.
(dump_stack_make_frame): New function.
(frame_slots): Likewise.
(frame_payload): New macro.
(dump_stack_allocate_frame): New function.
(dump_stack_deallocate_frame): Likewise.
(dump_stack_preallocate_frame): Likewise.
(_s_return): Unpack frame object and deallocate it.
(s_save): Wrap state in an frame object.
(dump_stack_mark): Mark the free list.
--

TinySCHEME being a SECD-machine needs to push frames onto the dump
stack.  Previously, the dump stack was a list.  This required four
cells for the spine, as well as up to one additional cell to encode
the current opcode.  This was quite inefficient despite the fact that
we recovered the spine as well as the integer cell.

We introduce frame objects, which are a special variant of vectors of
length four.  Since the length is fixed, this frees up the length
field of the vector object to store the unboxed opcode.  A frame
object now fits in two cells.

Saving two or three cells is a mere byproduct, the performance gain
comes from increased locality, unboxed opcode representation, and the
ability to easily put the objects in a free list, keeping the garbage
collector out of the continuous motion of the virtual machine.

Signed-off-by: Justus Winter <justus@g10code.com>
8 months agogpgscm: Merge opexe_0.
Justus Winter [Wed, 5 Apr 2017 15:30:44 +0000 (17:30 +0200)]
gpgscm: Merge opexe_0.

* tests/gpgscm/scheme-private.h (struct scheme): Remove field 'op'.
* tests/gpgscm/scheme.c (opexe_0): Inline into 'Eval_Cycle'.
(_Error_1): Return the opcode to evaluate next.
(Error_1): Do not return, but set the opcode and goto dispatch.
(Error_0): Likewise.
(s_goto): Likewise.
(s_return): Likewise.
(s_return_enable_gc): Likewise.
(s_thread_to): Remove superfluous cast.
(_s_return): Return the opcode to evaluate next.
(scheme_init_custom_alloc): Adapt to removal of field 'op'.

Signed-off-by: Justus Winter <justus@g10code.com>
8 months agoSpelling fixes in docs and comments.
NIIBE Yutaka [Fri, 28 Apr 2017 01:06:33 +0000 (10:06 +0900)]
Spelling fixes in docs and comments.

--

In addition, fix trailing spaces in tests/inittests.

GnuPG-bug-id: 3121
Reported-by: ka7 (klemens)
Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
8 months agogpgscm: Refactor cell finalization.
Justus Winter [Thu, 20 Apr 2017 15:39:41 +0000 (17:39 +0200)]
gpgscm: Refactor cell finalization.

* tests/gpgscm/scheme.c (finalize_cell): Use switch, return whether
the cell may be freed.
(gc): Update callsite.

Signed-off-by: Justus Winter <justus@g10code.com>
8 months agogpgscm: Tweak error message display.
Justus Winter [Thu, 20 Apr 2017 15:38:43 +0000 (17:38 +0200)]
gpgscm: Tweak error message display.

* tests/gpgscm/init.scm (throw'): If the first argument to the error
is a string, display it as such.

Signed-off-by: Justus Winter <justus@g10code.com>
8 months agogpgscm: Fix test.
Justus Winter [Thu, 20 Apr 2017 15:32:25 +0000 (17:32 +0200)]
gpgscm: Fix test.

* tests/gpgscm/t-child.scm: Use 'string-length' on the string.

Signed-off-by: Justus Winter <justus@g10code.com>
8 months agogpgscm: Improve syntax checking.
Justus Winter [Thu, 20 Apr 2017 13:09:13 +0000 (15:09 +0200)]
gpgscm: Improve syntax checking.

* tests/gpgscm/scheme.c (opexe_0): Make sure closure arguments are
symbols.

Signed-off-by: Justus Winter <justus@g10code.com>
8 months agogpgscm: Emit JUnit-style XML reports.
Justus Winter [Tue, 18 Apr 2017 16:51:06 +0000 (18:51 +0200)]
gpgscm: Emit JUnit-style XML reports.

* tests/gpgscm/Makefile.am (EXTRA_DIST): Add new file.
* tests/gpgscm/lib.scm (string-translate): New function.
* tests/gpgscm/main.c (main): Load new file.
* tests/gpgscm/tests.scm (dirname): New function.
(test-pool): Record execution times, emit XML report.
(test): Record execution times, record log file name, emit XML report.
(run-tests-parallel): Write XML report.
(run-tests-sequential): Likewise.
* tests/gpgscm/xml.scm: New file.
* tests/gpgme/Makefile.am (CLEANFILES): Add 'report.xml'.
* tests/gpgsm/Makefile.am: Likewise.
* tests/migrations/Makefile.am: Likewise.
* tests/openpgp/Makefile.am: Likewise.

Signed-off-by: Justus Winter <justus@g10code.com>
8 months agogpgscm: Make logging less verbose and more useful.
Justus Winter [Thu, 20 Apr 2017 09:49:17 +0000 (11:49 +0200)]
gpgscm: Make logging less verbose and more useful.

* tests/gpgscm/tests.scm (call-with-io): When being verbose, include
the pid in the output, and avoid duplicating the command arguments.

Signed-off-by: Justus Winter <justus@g10code.com>
8 months agogpgscm: Make test framework less functional.
Justus Winter [Tue, 18 Apr 2017 10:27:49 +0000 (12:27 +0200)]
gpgscm: Make test framework less functional.

* tests/gpgscm/tests.scm (test-pool, tests): Previously, these methods
updated objects by creating new updated copies of the object being
manipulated.  This made the code awkward without any benefit,
therefore I change it to just update the object.

Signed-off-by: Justus Winter <justus@g10code.com>
8 months agotests: Locate resources and scripts relative to top source dir.
Justus Winter [Wed, 22 Mar 2017 11:40:42 +0000 (12:40 +0100)]
tests: Locate resources and scripts relative to top source dir.

--

Locate every resource and every script used in the tests using a path
relative to the top of the source tree.

This is a purely mechanical change, mostly done using regular
expressions, with a few manual fixups here and there.

Signed-off-by: Justus Winter <justus@g10code.com>
8 months agogpgscm: Move 'trace' and 'stringify'.
Justus Winter [Wed, 19 Apr 2017 14:09:44 +0000 (16:09 +0200)]
gpgscm: Move 'trace' and 'stringify'.

* tests/gpgscm/tests.scm (trace, stringify): Move...
* tests/gpgscm/lib.scm: ... here.

Signed-off-by: Justus Winter <justus@g10code.com>
8 months agogpgscm: Avoid fruitless garbage collection cycles.
Justus Winter [Thu, 20 Apr 2017 13:04:52 +0000 (15:04 +0200)]
gpgscm: Avoid fruitless garbage collection cycles.

* tests/gpgscm/scheme-private.h (CELL_MINRECOVER): New macro.
* tests/gpgscm/scheme.c (_get_cell): Move the heuristic to get more
cells...
(gc): ... here where every caller benefits from the optimization.

Signed-off-by: Justus Winter <justus@g10code.com>
9 months agoMinor clean up.
NIIBE Yutaka [Wed, 19 Apr 2017 04:32:36 +0000 (13:32 +0900)]
Minor clean up.

* src/b64dec.c (_gpgrt_b64dec_proc): Add a comment.
* src/estream.c (_gpgrt_fread, _gpgrt_fwrite): Use &&.
* src/mkheader.c (xstrdup): Use memcpy as we know length.

Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
9 months agogpgscm: Fix test program.
NIIBE Yutaka [Wed, 12 Apr 2017 03:05:53 +0000 (12:05 +0900)]
gpgscm: Fix test program.

* tests/gpgscm/t-child.c (main): Fix for setmode.

Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
9 months agotests: Fix distcheck.
Justus Winter [Tue, 11 Apr 2017 09:50:54 +0000 (11:50 +0200)]
tests: Fix distcheck.

* tests/gpgscm/Makefile.am (EXTRA_DIST): Add 'gnupg.scm'.

Fixes-commit: ccd2187212c12b84c86a10fd4417a16536243179
Signed-off-by: Justus Winter <justus@g10code.com>
9 months agotests: Move common functionality.
Justus Winter [Tue, 11 Apr 2017 08:43:52 +0000 (10:43 +0200)]
tests: Move common functionality.

* tests/openpgp/defs.scm (with-home-directory,
with-ephemeral-home-directory): Move...
* tests/gpgscm/gnupg.scm: ... to this new file.
* tests/gpgscm/main.c (main): Load the new file.

Signed-off-by: Justus Winter <justus@g10code.com>
9 months agogpgscm: Fix opcode dispatch.
Justus Winter [Wed, 5 Apr 2017 14:56:46 +0000 (16:56 +0200)]
gpgscm: Fix opcode dispatch.

* tests/gpgscm/scheme.c (opexe_0): Consider 'op', not 'sc->op'.  The
former is the opcode we are currently executing.

Signed-off-by: Justus Winter <justus@g10code.com>
9 months agogpgscm: Mmap script files.
Justus Winter [Wed, 5 Apr 2017 12:11:57 +0000 (14:11 +0200)]
gpgscm: Mmap script files.

* tests/gpgscm/main.c (load): Try to mmap the script.
* tests/gpgscm/scheme.c (scheme_load_memory): New function, a
generalization of 'scheme_load_string'.
* tests/gpgscm/scheme.h (scheme_load_memory): New prototype.

Signed-off-by: Justus Winter <justus@g10code.com>
9 months agogpgscm: Refactor checking for opcode arguments.
Justus Winter [Mon, 3 Apr 2017 09:25:49 +0000 (11:25 +0200)]
gpgscm: Refactor checking for opcode arguments.

* tests/gpgscm/scheme.c (op_code_info): Fix type, add forward
declaration.
(check_arguments): New function.
(Eval_cycle): Use the new function.

Signed-off-by: Justus Winter <justus@g10code.com>
9 months agogpgscm: Improve syntax dispatch.
Justus Winter [Wed, 29 Mar 2017 16:10:17 +0000 (18:10 +0200)]
gpgscm: Improve syntax dispatch.

* tests/gpgscm/scheme.c (assign_syntax): Add opcode parameter, store
opcode in the tag.
(syntaxnum): Add sc parameter, retrieve opcode from tag.
(opexe_0): Adapt callsite.
(scheme_init_custom_alloc): Likewise.

Signed-off-by: Justus Winter <justus@g10code.com>
9 months agogpgscm: Make tags mandatory.
Justus Winter [Wed, 29 Mar 2017 16:05:33 +0000 (18:05 +0200)]
gpgscm: Make tags mandatory.

* tests/gpgscm/opdefines.h: Make tags mandatory.
* tests/gpgscm/scheme.c: Likewise.
* tests/gpgscm/scheme.h: Likewise.
--

Tags provide a constant-time lookup mechanism for almost every object.
This is useful for the interpreter itself, and the code for tags is
tiny.

Signed-off-by: Justus Winter <justus@g10code.com>
9 months agogpgscm: Add and use opcode for reversing a list in place.
Justus Winter [Tue, 4 Apr 2017 10:02:54 +0000 (12:02 +0200)]
gpgscm: Add and use opcode for reversing a list in place.

* tests/gpgscm/lib.scm (string-split-pln): Use 'reverse!'.
(string-rtrim): Likewise.
* tests/gpgscm/opdefines.h (reverse!): New opcode.
* tests/gpgscm/scheme.c (opexe_0): Handle new opcode.

Signed-off-by: Justus Winter <justus@g10code.com>
9 months agogpgscm: Deduplicate code.
Justus Winter [Wed, 29 Mar 2017 15:09:01 +0000 (17:09 +0200)]
gpgscm: Deduplicate code.

* tests/gpgscm/scheme.c (oblist_add_by_name): Deduplicate.
(new_slot_spec_in_env): Likewise.

Fixes-commit: 6a3f857224eab108ae38e6259194b01b0ffdad8b
Signed-off-by: Justus Winter <justus@g10code.com>
9 months agogpgscm: Move dispatch table into rodata.
Justus Winter [Wed, 29 Mar 2017 14:32:36 +0000 (16:32 +0200)]
gpgscm: Move dispatch table into rodata.

* tests/gpgscm/opdefines.h: Use 0 instead of NULL.
* tests/gpgscm/scheme.c (op_code_info): Use char arrays instead of
pointers, make arity parameters smaller.
(INF_ARG): Adapt.
(_OP_DEF): Likewise.
(dispatch_table): Likewise.
(procname): Likewise.
(Eval_cycle): Likewise.
(scheme_init_custom_alloc): Likewise.

Signed-off-by: Justus Winter <justus@g10code.com>
9 months agogpgscm: Use more threaded code.
Justus Winter [Wed, 29 Mar 2017 12:24:49 +0000 (14:24 +0200)]
gpgscm: Use more threaded code.

* tests/gpgscm/scheme.c (opexe_0): Use 's_thread_to' instead of
's_goto' wherever possible.

Signed-off-by: Justus Winter <justus@g10code.com>
9 months agogpgscm: Remove now obsolete dispatcher function from the opcodes.
Justus Winter [Wed, 29 Mar 2017 12:11:58 +0000 (14:11 +0200)]
gpgscm: Remove now obsolete dispatcher function from the opcodes.

* tests/gpgscm/opdefines.h: Remove now obsolete dispatcher function
from the opcodes.
* tests/gpgscm/scheme-private.h (_OP_DEF): Adapt.
* tests/gpgscm/scheme.c (dispatch_func): Remove type declaration.
(op_code_info): Remove 'func'.
(_OP_DEF): Adapt.
(Eval_Cycle): Always call 'opexe_0'.

Signed-off-by: Justus Winter <justus@g10code.com>
9 months agogpgscm: Merge 'opexe_6'.
Justus Winter [Wed, 29 Mar 2017 12:05:22 +0000 (14:05 +0200)]
gpgscm: Merge 'opexe_6'.

* tests/gpgscm/scheme.c (opexe_6): Merge into 'opexe_0'.
* tests/gpgscm/opdefines.h: Adapt.
--

Having separate functions to execute opcodes reduces our ability to
thread the code and prevents the dispatch_table from being moved to
rodata.

Signed-off-by: Justus Winter <justus@g10code.com>
9 months agogpgscm: Merge 'opexe_5'.
Justus Winter [Wed, 29 Mar 2017 11:57:54 +0000 (13:57 +0200)]
gpgscm: Merge 'opexe_5'.

* tests/gpgscm/scheme.c (opexe_5): Merge into 'opexe_0'.
* tests/gpgscm/opdefines.h: Adapt.
--

Having separate functions to execute opcodes reduces our ability to
thread the code and prevents the dispatch_table from being moved to
rodata.

Signed-off-by: Justus Winter <justus@g10code.com>
9 months agogpgscm: Merge 'opexe_4'.
Justus Winter [Wed, 29 Mar 2017 11:47:54 +0000 (13:47 +0200)]
gpgscm: Merge 'opexe_4'.

* tests/gpgscm/scheme.c (opexe_4): Merge into 'opexe_0'.
* tests/gpgscm/opdefines.h: Adapt.
--

Having separate functions to execute opcodes reduces our ability to
thread the code and prevents the dispatch_table from being moved to
rodata.

Signed-off-by: Justus Winter <justus@g10code.com>
9 months agogpgscm: Merge 'opexe_3'.
Justus Winter [Wed, 29 Mar 2017 11:45:25 +0000 (13:45 +0200)]
gpgscm: Merge 'opexe_3'.

* tests/gpgscm/scheme.c (opexe_3): Merge into 'opexe_0'.
* tests/gpgscm/opdefines.h: Adapt.
--

Having separate functions to execute opcodes reduces our ability to
thread the code and prevents the dispatch_table from being moved to
rodata.

Signed-off-by: Justus Winter <justus@g10code.com>
9 months agogpgscm: Merge 'opexe_2'.
Justus Winter [Wed, 29 Mar 2017 11:40:01 +0000 (13:40 +0200)]
gpgscm: Merge 'opexe_2'.

* tests/gpgscm/scheme.c (opexe_2): Merge into 'opexe_0'.
* tests/gpgscm/opdefines.h: Adapt.
--

Having separate functions to execute opcodes reduces our ability to
thread the code and prevents the dispatch_table from being moved to
rodata.

Signed-off-by: Justus Winter <justus@g10code.com>
9 months agogpgscm: Merge 'opexe_1'.
Justus Winter [Wed, 29 Mar 2017 11:32:38 +0000 (13:32 +0200)]
gpgscm: Merge 'opexe_1'.

* tests/gpgscm/scheme.c (opexe_1): Merge into 'opexe_0'.
* tests/gpgscm/opdefines.h: Adapt.
--

Having separate functions to execute opcodes reduces our ability to
thread the code and prevents the dispatch_table from being moved to
rodata.

Signed-off-by: Justus Winter <justus@g10code.com>
9 months agogpgscm: Allocate small integers in the rodata section.
Justus Winter [Thu, 23 Mar 2017 14:21:36 +0000 (15:21 +0100)]
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>
9 months agogpgscm: Make global data constant when possible.
Justus Winter [Thu, 23 Mar 2017 11:50:27 +0000 (12:50 +0100)]
gpgscm: Make global data constant when possible.

* tests/gpgscm/scheme-private.h (struct scheme): Make 'vptr' const.
* tests/gpgscm/scheme.c (num_zero): Statically initialize and turn
into constant.
(num_one): Likewise.
(charnames): Change type so that it can be stored in rodata.
(is_ascii_name): Adapt slightly.
(assign_proc): Make argument const char *.
(op_code_info): Make some fields const char *.
(tests): Make const.
(dispatch_table): Make const.  At least it can be made read-only after
relocation.
(Eval_Cycle): Adapt slightly.
(vtbl): Make const.

Signed-off-by: Justus Winter <justus@g10code.com>
9 months agogpgscm: Remove arbitrary limit on number of cell segments.
Justus Winter [Wed, 22 Mar 2017 15:22:57 +0000 (16:22 +0100)]
gpgscm: Remove arbitrary limit on number of cell segments.

* tests/gpgscm/scheme-private.h (struct scheme): Remove fixed-size
arrays for cell segments, replace them with a pointer to the new
'struct cell_segment' instead.
* tests/gpgscm/scheme.c (struct cell_segment): New definition.
(_alloc_cellseg): Allocate the header within the segment, return a
pointer to the header.
(_dealloc_cellseg): New function.
(alloc_cellseg): Insert the segments into a list.
(_get_cell): Allocate a new segment if less than a quarter of
CELL_SIGSIZE is recovered during garbage collection.
(initialize_small_integers): Adapt callsite.
(gc): Walk the list of segments.
(scheme_init_custom_alloc): Remove initialization of removed field.
(scheme_deinit): Adapt deallocation.
--

Previously the number of cells that could be allocated was a
compile-time limit.  Remove this limit.

Signed-off-by: Justus Winter <justus@g10code.com>
9 months agogpgscm: Fix compact vector encoding.
Justus Winter [Fri, 7 Apr 2017 10:27:47 +0000 (12:27 +0200)]
gpgscm: Fix compact vector encoding.

* tests/gpgscm/scheme-private.h (struct cell): Use uintptr_t for
'_flags'.  This way, '_flags' has the size of a machine word.
--

The compact vector representation introduced in 49e2ae65 requires that
we can tell apart pointers and type flags.  This did not work on
64-bit big-endian architectures.

Fixes a crash on 64-bit big-endian architectures.

Hat-tip-to: gniibe
Fixes-commit: 49e2ae65e892f93be7f87cfaae3392b50a99e4b1
Signed-off-by: Justus Winter <justus@g10code.com>
9 months agogpgscm: Avoid mutating integer.
Justus Winter [Thu, 6 Apr 2017 14:24:49 +0000 (16:24 +0200)]
gpgscm: Avoid mutating integer.

* tests/gpgscm/scheme.c (opexe_5): Do not modify the integer in-place
while printing an vector.  Integer objects may be shared, so they must
not be mutated.

Signed-off-by: Justus Winter <justus@g10code.com>
9 months agogpgscm: Initialize unused slots in vectors.
Justus Winter [Thu, 6 Apr 2017 14:21:48 +0000 (16:21 +0200)]
gpgscm: Initialize unused slots in vectors.

* tests/gpgscm/scheme.c (get_vector_object): Initialize unused slots
at the end of vectors.
--

They should not be used for anything, but let's just initialize them
to something benign to be sure.

GnuPG-bug-id: 3014
Signed-off-by: Justus Winter <justus@g10code.com>
9 months agogpgscm: Fix copying values.
Justus Winter [Tue, 4 Apr 2017 15:36:45 +0000 (17:36 +0200)]
gpgscm: Fix copying values.

* tests/gpgscm/scheme.c (copy_value): New function.
(mk_tagged_value): Use new function.
(opexe_4): Likewise for OP_SAVE_FORCED.
--

Occasionally, we need to copy a value from one location in the storage
to another.  Scheme objects are fine.  Some primitive objects,
however, require finalization, usually to free resources.

For these values, we either make a copy or acquire a reference.

Fixes e.g. a double free if a delayed expression evaluating to a
string is forced.

Signed-off-by: Justus Winter <justus@g10code.com>
9 months agogpgscm: Simplify get-output-string operation.
Justus Winter [Tue, 4 Apr 2017 15:38:50 +0000 (17:38 +0200)]
gpgscm: Simplify get-output-string operation.

* tests/gpgscm/scheme.c (opexe_4): Simplify 'get-output-string'.

Signed-off-by: Justus Winter <justus@g10code.com>
9 months agogpgscm: Simplify substring operation.
Justus Winter [Tue, 4 Apr 2017 12:28:45 +0000 (14:28 +0200)]
gpgscm: Simplify substring operation.

* tests/gpgscm/scheme.c (opexe_2): Simplify 'substring'.

Signed-off-by: Justus Winter <justus@g10code.com>
9 months agogpgscm: Slightly improve the procedure dispatch.
Justus Winter [Thu, 30 Mar 2017 10:19:01 +0000 (12:19 +0200)]
gpgscm: Slightly improve the procedure dispatch.

* tests/gpgscm/scheme.c (procnum): Procedures always have an integer
number, so we can safely use the cheaper 'ivalue_unchecked'.

Signed-off-by: Justus Winter <justus@g10code.com>