qemu-devel
[Top][All Lists]
Advanced

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

Re: [Qemu-devel] [PATCH] configure: Define NCURSES_WIDECHAR if we're usi


From: Laszlo Ersek
Subject: Re: [Qemu-devel] [PATCH] configure: Define NCURSES_WIDECHAR if we're using curses
Date: Sat, 3 Jun 2017 18:08:00 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.1.1

On 06/03/17 11:43, Kamil Rytarowski wrote:
> On 02.06.2017 23:58, Laszlo Ersek wrote:
>> On 06/02/17 16:35, Peter Maydell wrote:
>>> We want the wide character functions from the ncurses header.
>>> Unfortunately it doesn't provide them by default, but only
>>> if either:
>>>  * NCURSES_WIDECHAR is defined (for ncurses 20111030 and up)
>>>  * _XOPEN_SOURCE/_XOPEN_SOURCE_EXTENDED are suitably defined
>>>
>>> So far we have been implicitly relying on the latter, because
>>> for GNU libc when we define _GNU_SOURCE this causes libc
>>> to define the _XOPEN_SOURCE macros for us. Unfortunately
>>> this doesn't work on all libcs, because some (like OSX and
>>> musl libc) do not define _XOPEN_SOURCE when _GNU_SOURCE
>>> is defined.
>>>
>>> We can't fix this by defining _XOPEN_SOURCE ourselves, because
>>> that also means "and don't provide any functions that aren't in
>>> that standard", and not all libcs provide any way to override
>>> that to also get the non-standard functions. In particular
>>> FreeBSD has no such mechanism, and OSX's _DARWIN_C_SOURCE
>>> doesn't reenable everything (for instance getpagesize()
>>> is still not prototyped if _DARWIN_C_SOURCE and _XOPEN_SOURCE
>>> are both defined).
>>>
>>> So we have to define NCURSES_WIDECHAR. (This will only work
>>> if your ncurses is at least 20111030, as older versions
>>> don't honour this macro.)
>>>
>>> Signed-off-by: Peter Maydell <address@hidden>
>>> ---
>>> Testing from the people with musl libc and OSX-with-ncurses
>>> appreciated, as I don't have any systems which have the bug
>>> which this patch is attempting to fix...
>>>
>>>  configure | 2 ++
>>>  1 file changed, 2 insertions(+)
>>>
>>> diff --git a/configure b/configure
>>> index 0586ec9..6aca5d1 100755
>>> --- a/configure
>>> +++ b/configure
>>> @@ -3053,6 +3053,8 @@ int main(void) {
>>>  EOF
>>>    IFS=:
>>>    for curses_inc in $curses_inc_list; do
>>> +    # Make sure we get the wide character prototypes
>>> +    curses_inc="-DNCURSES_WIDECHAR $curses_inc"
>>>      IFS=:
>>>      for curses_lib in $curses_lib_list; do
>>>        unset IFS
>>>
>>
>> Given that we're already consciously using non-portable functions,
>> this solution looks the least messy to me.
>>
>
> These functions are enough portable to work on NetBSD curses(3).

Sorry, that's not what I meant by "non-portable functions".

Peter wrote,

>>> We can't fix this by defining _XOPEN_SOURCE ourselves, because
>>> that also means "and don't provide any functions that aren't in
>>> that standard", and not all libcs provide any way to override
>>> that to also get the non-standard functions.

So basically, if we only used standard (SUSv2, SUSv3 or SUSv4, i.e.
_XOPEN_SOURCE=500, =600 or =700) functions, then the wide char curses
functions could also be declared just through _XOPEN_SOURCE:

  http://pubs.opengroup.org/onlinepubs/007908799/xcurses/implement.html

(

Note that X/Open Curses, Issue 4 Version 2, does provide the wide char
stuff; see for example the add_wch() function at
<http://pubs.opengroup.org/onlinepubs/007908799/xcurses/add_wch.html>,
and my "/usr/include/curses.h" has:

  #ifndef NCURSES_WIDECHAR
  #if defined(_XOPEN_SOURCE_EXTENDED) || (defined(_XOPEN_SOURCE) && 
(_XOPEN_SOURCE - 0 >= 500))
  #define NCURSES_WIDECHAR 1
  #else
  #define NCURSES_WIDECHAR 0
  #endif
  #endif /* NCURSES_WIDECHAR */
  ...
  #if NCURSES_WIDECHAR
  ...
  extern NCURSES_EXPORT(int) add_wch (const cchar_t *);                   /* 
generated:WIDEC */

)

Since we can't use _XOPEN_SOURCE (because of our reliance on non-std
functions), we have to go with "whatever works" (basically abandoning
any benefit that the SUS / POSIX standardization brings), and then
NCURSES_WIDECHAR looks simple enough.

Thanks
Laszlo



reply via email to

[Prev in Thread] Current Thread [Next in Thread]