[libcamera-devel] libcamera: media_object: Undef major/minor system macros

Message ID 20190107155427.10124-1-kieran.bingham@ideasonboard.com
State Rejected
Headers show
Series
  • [libcamera-devel] libcamera: media_object: Undef major/minor system macros
Related show

Commit Message

Kieran Bingham Jan. 7, 2019, 3:54 p.m. UTC
GCC 7.3.0 defines conflicting macros within <sys/types.h> which are
deprecated and removed in later versions.

To support compilation with this toolchain, ensure that any previous
definition is removed before the class definitions.

Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
---
 src/libcamera/include/media_object.h | 9 +++++++++
 1 file changed, 9 insertions(+)

Comments

Laurent Pinchart Jan. 7, 2019, 4:27 p.m. UTC | #1
Hi Kieran,

Thank you for the patch.

On Monday, 7 January 2019 17:54:27 EET Kieran Bingham wrote:
> GCC 7.3.0 defines conflicting macros within <sys/types.h> which are
> deprecated and removed in later versions.
> 
> To support compilation with this toolchain, ensure that any previous
> definition is removed before the class definitions.
> 
> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
> ---
>  src/libcamera/include/media_object.h | 9 +++++++++
>  1 file changed, 9 insertions(+)
> 
> diff --git a/src/libcamera/include/media_object.h
> b/src/libcamera/include/media_object.h index 950a33286690..00772fd11234
> 100644
> --- a/src/libcamera/include/media_object.h
> +++ b/src/libcamera/include/media_object.h
> @@ -12,6 +12,15 @@
> 
>  #include <linux/media.h>
> 
> +/*
> + * In the GNU C Library, "major" and "minor" are defined by
> <sys/sysmacros.h>. + * GCC 7.3.0 also defines this in <sys/types.h> for
> historical compatibility. + * To prevent conflicting with the major() and
> minor() member functions we + * unconditionally undef these here.
> + */
> +#undef major
> +#undef minor

I don't think we should do this, as it would prevent users of media_object.h 
from using the glibc macros (or at least interfere with their usage, 
potentially creating more problems). Let's instead rename the two conflicting 
functions, to deviceMinor() and deviceMajor() (or other similar names).

>  namespace libcamera {
> 
>  class MediaDevice;
Kieran Bingham Jan. 7, 2019, 5:10 p.m. UTC | #2
Hi Laurent,

On 07/01/2019 16:27, Laurent Pinchart wrote:
> Hi Kieran,
> 
> Thank you for the patch.
> 
> On Monday, 7 January 2019 17:54:27 EET Kieran Bingham wrote:
>> GCC 7.3.0 defines conflicting macros within <sys/types.h> which are
>> deprecated and removed in later versions.
>>
>> To support compilation with this toolchain, ensure that any previous
>> definition is removed before the class definitions.
>>
>> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
>> ---
>>  src/libcamera/include/media_object.h | 9 +++++++++
>>  1 file changed, 9 insertions(+)
>>
>> diff --git a/src/libcamera/include/media_object.h
>> b/src/libcamera/include/media_object.h index 950a33286690..00772fd11234
>> 100644
>> --- a/src/libcamera/include/media_object.h
>> +++ b/src/libcamera/include/media_object.h
>> @@ -12,6 +12,15 @@
>>
>>  #include <linux/media.h>
>>
>> +/*
>> + * In the GNU C Library, "major" and "minor" are defined by
>> <sys/sysmacros.h>. + * GCC 7.3.0 also defines this in <sys/types.h> for
>> historical compatibility. + * To prevent conflicting with the major() and
>> minor() member functions we + * unconditionally undef these here.
>> + */
>> +#undef major
>> +#undef minor
> 
> I don't think we should do this, as it would prevent users of media_object.h 
> from using the glibc macros (or at least interfere with their usage, 
> potentially creating more problems). Let's instead rename the two conflicting 
> functions, to deviceMinor() and deviceMajor() (or other similar names).

I agree. I've sent an updated patch.



> 
>>  namespace libcamera {
>>
>>  class MediaDevice;
>

Patch

diff --git a/src/libcamera/include/media_object.h b/src/libcamera/include/media_object.h
index 950a33286690..00772fd11234 100644
--- a/src/libcamera/include/media_object.h
+++ b/src/libcamera/include/media_object.h
@@ -12,6 +12,15 @@ 
 
 #include <linux/media.h>
 
+/*
+ * In the GNU C Library, "major" and "minor" are defined by <sys/sysmacros.h>.
+ * GCC 7.3.0 also defines this in <sys/types.h> for historical compatibility.
+ * To prevent conflicting with the major() and minor() member functions we
+ * unconditionally undef these here.
+ */
+#undef major
+#undef minor
+
 namespace libcamera {
 
 class MediaDevice;