Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  • The PX4 team uses these patches to cwhar and math.h to solve the issue. But note the comments in that code:
Code Block
    /* N.B. The following definitions are enabled at this time to allow the PX4 
 * development to continue until there is a SAFE  solution to foreign

...

 
 * (non-nuttx) header file inclusion. There is a potential of a binary

...

 
 * incompatibility and runtime errors, memory overwrites or corruption

...

 
 * VVVVVVVVVVVVVVVVVVVVVVVVVV Begin Warning VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV

...

 
 */ 


  • Some people have suggested adding the type definition of wint_t to nuttx/include/sys/types.h merely because that header file will then be included into the newlib math.h. This inclusion, of course, also very dangerous since the types in the NuttX sys/types.h header file may not agree with the types in the pre-compiled newlib math library. This solution is not recommended, in any case. The type wint_t is already correctly defined in nuttx/include/sys/wchar.h which is the one and only correct location per OpenGroup.org. It is a mystery to my why the newlib math.h header file uses wint_t without including wchar.h. If it did, then there would then this compilation issue would not exist (there could still be subtle binary compatibility issues).

...

Code Block
  commit 894ca622e6a408e5fa858a3fee46fb16f32cf86c
  Author: Xiang Xiao <xiaoxiang@xiaomi.com>
  Date:   Mon Aug 27 06:26:37 2018 -0600
Code Block
    include/sys/types:  Move wint_t and wctype_t from wchar.h to
    types.h.  This change is compatible as before since wchar.h
    include types.h indirectly.  This fixes a compilation error with
    newlib's math.h:  'unknown type name wint_t'

...

Code Block
  #ifndef _ALLOCA_H
  #define _ALLOCA_H
Code Block
  #define alloca __builtin_alloca
Code Block
  #endif /* _ALLOCA_H */


And add the path to this alloca.h to your CFLAG include path arguments. The path can specified by adding -system or -I to the CFLAGS. The path to this alloca.h must be defined last so that it has precedence.

...

Code Block
  #ifndef _MYMATH_H
  #define _MYMATH_H
  #ifndef _ALLOCA_H
  #define _ALLOCA_H
Code Block
  #define alloca __builtin_alloca
Code Block
  #endif /* _ALLOCA_H */
Code Block
  #include_next <math.h>
Code Block
  #endif /* _MYMATH_H */


This will provide the alloca() definition, then continue to include the default version of math.h. This works because the idempotence pre-processor variable _ALLOC_H matches the same idempotence variable used in the newlib alloca.h. Thus, any sneak inclusion of alloca.h with have not effect.

...