Commit Graph

14 Commits

Author SHA1 Message Date
Peter Wang
2be2e7468c Do not use _snprintf functions directly in place of snprintf functions.
The Windows _snprintf family of functions do not guarantee null
termination when the output is truncated so cannot be used as direct
replacements for the snprintf functions. Also, the _snprintf functions
have different return values from the C99 snprintf functions when output
is truncated (like some older snprintf implementations).

Furthermore, on Windows snprintf/vsnprintf may be synonyms for
_snprintf/_vsnprintf so cannot be relied upon to terminate their outputs
either, even if the functions exist.

runtime/mercury_string.c:
runtime/mercury_string.h:
    Define MR_snprintf and MR_vsnprintf as macro synonyms for
    snprintf/vsnprintf ONLY if _snprintf/_vsnprintf do not exist.

    Otherwise, implement MR_snprintf and MR_vsnprintf functions
    that behave like the C99 functions, in terms of _vsnprintf.

    Require that either snprintf/vsnprintf or _snprintf/_vsnprintf
    are available. This should be true on all systems still in use.

runtime/mercury_debug.c:
runtime/mercury_ml_expand_body.h:
runtime/mercury_runtime_util.c:
runtime/mercury_stack_layout.c:
runtime/mercury_stack_trace.c:
runtime/mercury_stacks.c:
runtime/mercury_tabling.c:
runtime/mercury_threadscope.c:
runtime/mercury_trace_base.c:
runtime/mercury_wrapper.c:
trace/mercury_trace_completion.c:
trace/mercury_trace_internal.c:
trace/mercury_trace_spy.c:
trace/mercury_trace_vars.c:
bytecode/mb_disasm.c:
    Use MR_snprintf instead of snprintf/_snprintf
    and MR_vsnprintf instead of vsnprintf/_vsnprintf.

    Drop code paths using sprintf as a fallback.
2018-07-23 10:26:29 +10:00
Mark Brown
d465fa53cb Update the COPYING.LIB file and references to it.
Discussion of these changes can be found on the Mercury developers
mailing list archives from June 2018.

COPYING.LIB:
    Add a special linking exception to the LGPL.

*:
    Update references to COPYING.LIB.

    Clean up some minor errors that have accumulated in copyright
    messages.
2018-06-09 17:43:12 +10:00
Zoltan Somogyi
53b573692a Convert C code to use // style comments.
runtime/*.[ch]:
trace/*.[chyl]:
    As above. In some places, improve comments, e.g. by expanding contractions
    such as "we've". Add #ifndef guards against double inclusion around
    the trace/*.h files that did not already have them.

tools/*:
    Make the corresponding changes in shell scripts that generate .[ch] files
    in the runtime.

tests/*:
    Conform to a slight change in the text of a message.
2016-07-14 13:57:35 +02:00
Zoltan Somogyi
67326f16e4 Fix style issues in the runtime.
Move all .h and .c files to four-space indentation without tabs,
if they weren't there already.

Use the same vim line for all .h and .c files.

Align all backslashes at the ends of lines in macro definitions.
Align close comment signs.

In some places, fix inconsistent indentation.

Fix a bunch of comments. Add XXXs to a few of them.
2016-07-09 12:14:00 +02:00
Peter Wang
e0f5e1b556 Avoid strerror_s on MinGW-w64 for compatibility with Windows XP.
runtime/mercury_runtime_util.c:
	As above.
2014-09-11 11:09:56 +10:00
Peter Wang
4c79744ffc Assume standard strerror_r unless using glibc.
We followed the feature test macros from the Linux man page for
strerror_r to figure out which function we have actually got, but that
only applies when using the GNU C library.  When using any other C
library, we should assume that strerror_r is the POSIX-standard
strerror_r.

Commit 533f5f874f worked around
this bug for Mac OS X only.

runtime/mercury_runtime_util.c:
	Explicitly include string.h for strerror_r, just in case.

	If __GNU_LIBRARY__ is not defined then assume we have the
	POSIX-standard strerror_r.  Only follow the feature test
	macros otherwise.

	Assign the return values of strerror_r to variables of the
	expected types.  The compiler should warn about conversions
	between integer and pointer types if the detection was wrong.

	Fix argument order in a call to generic_strerror.
2014-06-27 10:16:38 +10:00
Julien Fischer
533f5f874f Fix a segmentation fault in the runtime on Mac OS X.
runtime/mercury_runtime_util.c:
	On Mac OS X, strerror_r also does not populate its buffer
	if it fails.
2014-06-26 13:06:54 +10:00
Peter Wang
31d3897e22 Thread-safe alternative to strerror.
Add MR_strerror as a thread-safe alternative to strerror.
The current implementation wraps strerror_r(), strerror_s()
or sys_errlist as appropriate for the platform.  Bug #340.

configure.ac:
runtime/mercury_conf.h.in:
	Check for strerror_r, strerror_s.

	Delete irrelevant code in the sockets test for the external debugger.

runtime/mercury_runtime_util.c:
runtime/mercury_runtime_util.h:
	Add MR_strerror and use it.

library/io.m:
	Use MR_strerror.  In particular, mercury_output_error was not
	thread-safe.

	Pass errno to mercury_output_error explicitly for clarity.

	Delete req_lock parameter in ML_maybe_make_err_msg macro which is not
	needed any more.

compiler/prog_event.m:
runtime/mercury_deep_profiling.c:
runtime/mercury_misc.c:
runtime/mercury_term_size.c:
runtime/mercury_trace_base.c:
trace/mercury_trace_cmd_developer.c:
trace/mercury_trace_cmd_exp.c:
trace/mercury_trace_cmd_misc.c:
trace/mercury_trace_declarative.c:
trace/mercury_trace_external.c:
trace/mercury_trace_internal.c:
	Use MR_strerror.

compiler/notes/coding_standards.html:
	Update coding standard.

extras/net/sockets.m:
extras/net/tcp.m:
	Use MR_strerror.

NEWS:
	Announce change.
2014-06-25 17:32:58 +10:00
Peter Ross
4b0663b520 Avoid using a string after calling MR_free.
Estimated hours taken: 0.1
Branches: main

runtime/mercury_runtime_util.c:
	Avoid using a string after calling MR_free.
2006-11-29 00:37:25 +00:00
Peter Ross
bc85aed613 Get the sytem building under mingw and cygwin.
Estimated hours taken: 6
Branches: main

Get the sytem building under mingw and cygwin.

README.MinGW:
	Document the new packages you need to install for the
	system to build.

configure.in:
runtime/mercury_conf.h.in:
	Test for the presence of the setenv and putenv functions.

configure.in:
	Comment out some code which breaks with autoconf 2.60.

runtime/mercury_runtime_util.c:
runtime/mercury_runtime_util.h:
	Add MR_setenv which is an implementation of setenv in terms
	of either setenv or putenv.

runtime/mercury_trace_base.c:
	Call MR_setenv.

trace/Mmakefile:
	Mingw and cygwin only have flex 2.5.4 available, so use
	the options compatible with that version.
2006-11-28 06:57:43 +00:00
Zoltan Somogyi
c959a1657f Convert all remaining C source files to four-space indentation.
Estimated hours taken: 0.5
Branches: main

runtime/*.c:
	Convert all remaining C source files to four-space indentation.
	Fix some deviations from our style guide.
2006-11-14 00:15:41 +00:00
Peter Ross
efecdba25b Add a missing MR_HAVE_UNISTD_H around #include of unistd.h.
Estimated hours taken: 0.25
Branches: main

runtime/mercury_runtime_util.c:
	Add a missing MR_HAVE_UNISTD_H around #include of unistd.h.
2002-10-22 13:55:56 +00:00
Simon Taylor
c66cea0665 Add MR_ prefixes to uses of configuration macros.
Estimated hours taken: 2.5
Branches: main

Add MR_ prefixes to uses of configuration macros.
Bootcheck now succeeds with MR_NO_CONF_BACKWARDS_COMPAT.

Mmake.common.in:
	Define MR_NO_CONF_BACKWARDS_COMPAT when checking
	for namespace cleanliness.

RESERVED_MACRO_NAMES:
	Remove the configuration macros.

runtime/mercury_conf_bootstrap.h:
	Remove a duplicate definition of BOXED_FLOAT.

configure.in:
*/*.c:
*/*.h:
*/*.m:
	Add MR_ prefixes.
2002-02-13 09:56:49 +00:00
Zoltan Somogyi
b456621269 New module for utility functions. Contains the checked versions of
Estimated hours taken: 1
Branches: main

runtime/mercury_runtime_util.[ch]:
	New module for utility functions. Contains the checked versions of
	fopen, fclose, atexit which used to be static in mercury_prof.c,
	and the backup version of strerror which used to be in
	mercury_strerror.c.

runtime/mercury_strerror.[ch]:
	Deleted this now obsolete module.

runtime/mercury_prof.c:

runtime/Mmakefile:
	Mention the new module and delete references to the deleted module.

runtime/mercury_deep_profiling.c:
runtime/mercury_trace_base.c:
	Add #includes of the new module.
2001-12-27 07:08:11 +00:00