[libcamera-devel] [PATCH] libcamera: ipu3: Fix compilation issues with gcc5

Jacopo Mondi jacopo at jmondi.org
Wed Aug 5 09:10:29 CEST 2020


Hi Laurent,

On Wed, Aug 05, 2020 at 02:00:34AM +0300, Laurent Pinchart wrote:
> Hi Jacopo,
>
> Thank you for the patch.
>
> On Mon, Aug 03, 2020 at 06:28:11PM +0200, Jacopo Mondi wrote:
> > GCC5 does not provide prototypes for the math library functions defined
> > in the math.h header for the std:: namespace.
> >
> > Include the C++ <cmath> header in place of <math.h> as it defines
> > overloads for the std::abs and std::fmod function.
> >
> > This goes intentionally against the libcamera coding guidelines, and
> > is reported as warning by checkpatch.py.
>
> I'm considering adjusting the guidelines specifically for cmath, as the
> math function overloads are really nice to have, and should do the right
> thing by default.

What about

--- a/Documentation/coding-style.rst
+++ b/Documentation/coding-style.rst
@@ -198,7 +198,14 @@ std namespace, and may declare the same names in the global namespace. The C
 compatibility headers declare names in the global namespace, and may declare
 the same names in the std namespace. Usage of the C compatibility headers is
 strongly preferred. Code shall not rely on the optional declaration of names in
-the global or std namespace.
+the global or std namespace. An exception to this rule is represented by the
+[cmath|math.h] header files. As the type of the argument is particularly
+relevant for mathematical operations, the former (cmath) defines in the std
+namespace overloads of the same function that accept different parameter types,
+while the latter (math.h) requires the developer to pick the right function for
+the function arguments at hand. As an example, cmath defines std::abs(int) and
+std::abs(float) while math.h defines abs(int) and fabs(float). For this reason
+the inclusion of <cmath> is preferred over <math.h>.

>
> > Fixes: 968ab9bad0ed ("libcamera: ipu3: imgu: Calculate ImgU pipe configuration")
> > Signed-off-by: Jacopo Mondi <jacopo at jmondi.org>
>
> Reviewed-by: Laurent Pinchart <laurent.pinchart at ideasonboard.com>
>
> Please push :-)

Thanks
   j
>
> > ---
> >  src/libcamera/pipeline/ipu3/imgu.cpp | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/src/libcamera/pipeline/ipu3/imgu.cpp b/src/libcamera/pipeline/ipu3/imgu.cpp
> > index b7593ceb3672..eb829e096561 100644
> > --- a/src/libcamera/pipeline/ipu3/imgu.cpp
> > +++ b/src/libcamera/pipeline/ipu3/imgu.cpp
> > @@ -7,8 +7,8 @@
> >
> >  #include "imgu.h"
> >
> > +#include <cmath>
> >  #include <limits>
> > -#include <math.h>
> >
> >  #include <linux/media-bus-format.h>
> >
>
> --
> Regards,
>
> Laurent Pinchart


More information about the libcamera-devel mailing list