[PATCH] Replace errs and mem subroutines to separate files

Dmitry V. Levin ldv at altlinux.org
Mon Jun 26 21:21:52 UTC 2017


On Mon, Jun 26, 2017 at 09:05:31PM +0300, Edgar Kaziahmedov wrote:
> According to the current state of affairs, strace.c contains
> functions, which could be replaced to separate file, for instance,
> file with functions printing errors. Also it could be useful for
> the future, because other binaries, included to the strace package,
> will use wrappers for printing errors, thus it would avoid the
> duplication of code. Now, all common prototypes are placed in common.h.
> NOTE: asinfo also needs these subroutines.

While I fully support the idea of moving some declarations from defs.h
to separate header files for later use outside strace, ...

[...]
> --- /dev/null
> +++ b/common.h
> @@ -0,0 +1,62 @@
> +/*
> + * Copyright (c) 2001-2017 The strace developers.
> + * All rights reserved.
> + *
> + * Redistribution and use in source and binary forms, with or without
> + * modification, are permitted provided that the following conditions
> + * are met:
> + * 1. Redistributions of source code must retain the above copyright
> + *    notice, this list of conditions and the following disclaimer.
> + * 2. Redistributions in binary form must reproduce the above copyright
> + *    notice, this list of conditions and the following disclaimer in the
> + *    documentation and/or other materials provided with the distribution.
> + * 3. The name of the author may not be used to endorse or promote products
> + *    derived from this software without specific prior written permission.
> + *
> + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
> + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
> + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
> + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
> + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
> + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
> + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
> + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
> + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
> + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
> + */
> +
> +#ifndef STRACE_COMMON_H
> +#define STRACE_COMMON_H
> +
> +#include <stdbool.h>
> +#include <stdint.h>
> +#include <stdio.h>
> +#include <stdlib.h>
> +#include <string.h>
> +#include <sys/types.h>
> +#include <unistd.h>
> +
> +#include "kernel_types.h"
> +#include "gcc_compat.h"

... I think we should avoid introducing more defs.h-like umbrella headers.
In particular, I don't see any use in creating headers that include other
headers without any reason besides including them in a single place.
defs.h is a legacy we have to deal with, let's do better this time.

> +
> +#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]) + MUST_BE_ARRAY(a))
> +
> +void error_msg(const char *fmt, ...) ATTRIBUTE_FORMAT((printf, 1, 2));
> +void perror_msg(const char *fmt, ...) ATTRIBUTE_FORMAT((printf, 1, 2));
> +void perror_msg_and_die(const char *fmt, ...)
> +	ATTRIBUTE_FORMAT((printf, 1, 2)) ATTRIBUTE_NORETURN;
> +void error_msg_and_help(const char *fmt, ...)
> +	ATTRIBUTE_FORMAT((printf, 1, 2)) ATTRIBUTE_NORETURN;
> +void error_msg_and_die(const char *fmt, ...)
> +	ATTRIBUTE_FORMAT((printf, 1, 2)) ATTRIBUTE_NORETURN;
> +void die_out_of_memory(void) ATTRIBUTE_NORETURN;
> +
> +void *xcalloc(size_t nmemb, size_t size)
> +	ATTRIBUTE_MALLOC ATTRIBUTE_ALLOC_SIZE((1, 2));
> +void *xmalloc(size_t size) ATTRIBUTE_MALLOC ATTRIBUTE_ALLOC_SIZE((1));
> +void *xreallocarray(void *ptr, size_t nmemb, size_t size)
> +	ATTRIBUTE_ALLOC_SIZE((2, 3));
> +char *xstrdup(const char *str) ATTRIBUTE_MALLOC;
> +char *xstrndup(const char *str, size_t n) ATTRIBUTE_MALLOC;

This looks to me like three different groups of declarations.


-- 
ldv
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 801 bytes
Desc: not available
URL: <http://lists.strace.io/pipermail/strace-devel/attachments/20170627/d068fb64/attachment.bin>


More information about the Strace-devel mailing list