All of lore.kernel.org
 help / color / mirror / Atom feed
From: Costin Lupu <costin.lupu@cs.pub.ro>
To: xen-devel@lists.xenproject.org
Cc: Christian Lindig <christian.lindig@citrix.com>,
	David Scott <dave@recoil.org>, Ian Jackson <iwj@xenproject.org>,
	Wei Liu <wl@xen.org>
Subject: Re: [PATCH v2 5/5] tools/ocaml: Fix redefinition errors
Date: Fri, 30 Apr 2021 14:33:49 +0300	[thread overview]
Message-ID: <476b0736-3034-b697-a89e-1bb0e5cef4fd@cs.pub.ro> (raw)
In-Reply-To: <1a8ff6dcdd70fef83828dce47e79eb846860cbe8.1619781564.git.costin.lupu@cs.pub.ro>

@Christian: This version is slightly changed, it uses XC_PAGE_* macros
instead of PAGE_* macros and that's why I didn't add your ack.

Cheers,
Costin

On 4/30/21 2:28 PM, Costin Lupu wrote:
> If PAGE_SIZE is already defined in the system (e.g. in /usr/include/limits.h
> header) then gcc will trigger a redefinition error because of -Werror. This
> patch replaces usage of PAGE_* macros with XC_PAGE_* macros in order to avoid
> confusion between control domain page granularity (PAGE_* definitions) and
> guest domain page granularity (which is what we are dealing with here).
> 
> Same issue applies for redefinitions of Val_none and Some_val macros which
> can be already defined in the OCaml system headers (e.g.
> /usr/lib/ocaml/caml/mlvalues.h).
> 
> Signed-off-by: Costin Lupu <costin.lupu@cs.pub.ro>
> ---
>  tools/ocaml/libs/xc/xenctrl_stubs.c            | 10 ++++------
>  tools/ocaml/libs/xentoollog/xentoollog_stubs.c |  4 ++++
>  tools/ocaml/libs/xl/xenlight_stubs.c           |  4 ++++
>  3 files changed, 12 insertions(+), 6 deletions(-)
> 
> diff --git a/tools/ocaml/libs/xc/xenctrl_stubs.c b/tools/ocaml/libs/xc/xenctrl_stubs.c
> index d05d7bb30e..f9e33e599a 100644
> --- a/tools/ocaml/libs/xc/xenctrl_stubs.c
> +++ b/tools/ocaml/libs/xc/xenctrl_stubs.c
> @@ -36,14 +36,12 @@
>  
>  #include "mmap_stubs.h"
>  
> -#define PAGE_SHIFT		12
> -#define PAGE_SIZE               (1UL << PAGE_SHIFT)
> -#define PAGE_MASK               (~(PAGE_SIZE-1))
> -
>  #define _H(__h) ((xc_interface *)(__h))
>  #define _D(__d) ((uint32_t)Int_val(__d))
>  
> +#ifndef Val_none
>  #define Val_none (Val_int(0))
> +#endif
>  
>  #define string_of_option_array(array, index) \
>  	((Field(array, index) == Val_none) ? NULL : String_val(Field(Field(array, index), 0)))
> @@ -818,7 +816,7 @@ CAMLprim value stub_xc_domain_memory_increase_reservation(value xch,
>  	CAMLparam3(xch, domid, mem_kb);
>  	int retval;
>  
> -	unsigned long nr_extents = ((unsigned long)(Int64_val(mem_kb))) >> (PAGE_SHIFT - 10);
> +	unsigned long nr_extents = ((unsigned long)(Int64_val(mem_kb))) >> (XC_PAGE_SHIFT - 10);
>  
>  	uint32_t c_domid = _D(domid);
>  	caml_enter_blocking_section();
> @@ -924,7 +922,7 @@ CAMLprim value stub_pages_to_kib(value pages)
>  {
>  	CAMLparam1(pages);
>  
> -	CAMLreturn(caml_copy_int64(Int64_val(pages) << (PAGE_SHIFT - 10)));
> +	CAMLreturn(caml_copy_int64(Int64_val(pages) << (XC_PAGE_SHIFT - 10)));
>  }
>  
>  
> diff --git a/tools/ocaml/libs/xentoollog/xentoollog_stubs.c b/tools/ocaml/libs/xentoollog/xentoollog_stubs.c
> index bf64b211c2..e4306a0c2f 100644
> --- a/tools/ocaml/libs/xentoollog/xentoollog_stubs.c
> +++ b/tools/ocaml/libs/xentoollog/xentoollog_stubs.c
> @@ -53,8 +53,12 @@ static char * dup_String_val(value s)
>  #include "_xtl_levels.inc"
>  
>  /* Option type support as per http://www.linux-nantes.org/~fmonnier/ocaml/ocaml-wrapping-c.php */
> +#ifndef Val_none
>  #define Val_none Val_int(0)
> +#endif
> +#ifndef Some_val
>  #define Some_val(v) Field(v,0)
> +#endif
>  
>  static value Val_some(value v)
>  {
> diff --git a/tools/ocaml/libs/xl/xenlight_stubs.c b/tools/ocaml/libs/xl/xenlight_stubs.c
> index 352a00134d..45b8af61c7 100644
> --- a/tools/ocaml/libs/xl/xenlight_stubs.c
> +++ b/tools/ocaml/libs/xl/xenlight_stubs.c
> @@ -227,8 +227,12 @@ static value Val_string_list(libxl_string_list *c_val)
>  }
>  
>  /* Option type support as per http://www.linux-nantes.org/~fmonnier/ocaml/ocaml-wrapping-c.php */
> +#ifndef Val_none
>  #define Val_none Val_int(0)
> +#endif
> +#ifndef Some_val
>  #define Some_val(v) Field(v,0)
> +#endif
>  
>  static value Val_some(value v)
>  {
> 


      reply	other threads:[~2021-04-30 11:34 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-30 11:28 [PATCH v2 0/5] Fix redefinition errors for toolstack libs Costin Lupu
2021-04-30 11:28 ` [PATCH v2 1/5] tools/debugger: Fix PAGE_SIZE redefinition error Costin Lupu
2021-04-30 11:28 ` [PATCH v2 2/5] tools/libfsimage: Fix PATH_MAX " Costin Lupu
2021-04-30 11:28 ` [PATCH v2 3/5] tools/libs/foreignmemory: Fix PAGE_SIZE " Costin Lupu
2021-04-30 11:28 ` [PATCH v2 4/5] tools/libs/gnttab: " Costin Lupu
2021-04-30 11:28 ` [PATCH v2 5/5] tools/ocaml: Fix redefinition errors Costin Lupu
2021-04-30 11:33   ` Costin Lupu [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=476b0736-3034-b697-a89e-1bb0e5cef4fd@cs.pub.ro \
    --to=costin.lupu@cs.pub.ro \
    --cc=christian.lindig@citrix.com \
    --cc=dave@recoil.org \
    --cc=iwj@xenproject.org \
    --cc=wl@xen.org \
    --cc=xen-devel@lists.xenproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.