Re: [PATCH 4/7] builtin: directly predefine builtin macros

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




On 05/06/18 00:12, Luc Van Oostenryck wrote:
> Use the newly created predefine()/predefinef() to
> define the builtin macros.
> 
> Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@xxxxxxxxx>
> ---
>  lib.c | 84 ++++++++++++++++++++++++++++++++---------------------------
>  1 file changed, 46 insertions(+), 38 deletions(-)
> 
> diff --git a/lib.c b/lib.c
> index 30d1cf6d1..9271bc5cd 100644
> --- a/lib.c
> +++ b/lib.c
> @@ -477,8 +477,8 @@ static void handle_arch_m64_finalize(void)
>  	switch (arch_m64) {
>  	case ARCH_X32:
>  		max_int_alignment = 8;
> -		add_pre_buffer("#weak_define __ILP32__ 1\n");
> -		add_pre_buffer("#weak_define _ILP32 1\n");
> +		predefine("__ILP32__", 1, "1");
> +		predefine("_ILP32", 1, "1");
>  		goto case_x86_64;
>  	case ARCH_LP32:
>  		/* default values */
> @@ -488,15 +488,15 @@ static void handle_arch_m64_finalize(void)
>  		max_int_alignment = 8;
>  		size_t_ctype = &ulong_ctype;
>  		ssize_t_ctype = &long_ctype;
> -		add_pre_buffer("#weak_define __LP64__ 1\n");
> -		add_pre_buffer("#weak_define _LP64 1\n");
> +		predefine("__LP64__", 1, "1");
> +		predefine("_LP64", 1, "1");
>  		goto case_64bit_common;
>  	case ARCH_LLP64:
>  		bits_in_long = 32;
>  		max_int_alignment = 8;
>  		size_t_ctype = &ullong_ctype;
>  		ssize_t_ctype = &llong_ctype;
> -		add_pre_buffer("#weak_define __LLP64__ 1\n");
> +		predefine("__LLP64__", 1, "1");
>  		goto case_64bit_common;
>  	case_64bit_common:
>  		bits_in_pointer = 64;
> @@ -504,8 +504,8 @@ static void handle_arch_m64_finalize(void)
>  		/* fall through */
>  	case_x86_64:
>  #if defined(__x86_64__) || defined(__x86_64)
> -		add_pre_buffer("#weak_define __x86_64__ 1\n");
> -		add_pre_buffer("#weak_define __x86_64   1\n");
> +		predefine("__x86_64__", 1, "1");
> +		predefine("__x86_64", 1, "1");
>  #endif
>  		break;
>  	}
> @@ -1111,14 +1111,20 @@ static char **handle_switch(char *arg, char **next)
>  
>  static void predefined_sizeof(const char *name, unsigned bits)
>  {
> -	add_pre_buffer("#weak_define __SIZEOF_%s__ %d\n", name, bits/8);
> +	char *buf;
> +
> +	asprintf(&buf, "__SIZEOF_%s__", name);

asprintf() is a GNU extension, that is not in the C or POSIX
standards, although I think it may be in _some_ BSDs. Also, if
it should fail to allocate memory for the result, it will return
-1 and the 'buf' return will be undefined.

I don't think you should use this non-standard function.

> +	predefinef(buf, 1, "%d", bits/8);
>  }
>  
>  static void predefined_max(const char *name, const char *suffix, unsigned bits)
>  {
>  	unsigned long long max = (1ULL << (bits - 1 )) - 1;
> +	char *buf, *val;
>  
> -	add_pre_buffer("#weak_define __%s_MAX__ %#llx%s\n", name, max, suffix);
> +	asprintf(&buf, "__%s_MAX__", name);
> +	asprintf(&val, "%#llx%s", max, suffix);

ditto times two. ;-)

ATB,
Ramsay Jones
--
To unsubscribe from this list: send the line "unsubscribe linux-sparse" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Newbies FAQ]     [LKML]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Trinity Fuzzer Tool]

  Powered by Linux