diff mbox series

[FFmpeg-devel] Add extra const to FF_PFNGLSHADERSOURCEPROC.

Message ID BN7PR21MB16363C6C0288A64BE59F1BDDCBFC2@BN7PR21MB1636.namprd21.prod.outlook.com
State New
Headers show
Series [FFmpeg-devel] Add extra const to FF_PFNGLSHADERSOURCEPROC. | expand

Checks

Context Check Description
yinshiyou/commit_msg_loongarch64 warning The first line of the commit message must start with a context terminated by a colon and a space, for example "lavu/opt: " or "doc: ".
andriy/commit_msg_x86 warning The first line of the commit message must start with a context terminated by a colon and a space, for example "lavu/opt: " or "doc: ".
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

Billy O'Neal \(VC AIR\) May 31, 2024, 7:08 p.m. UTC
Resolves the following compiler error on macOS 14.5:

```console
/Library/Developer/CommandLineTools/SDKs/MacOSX14.4.sdk/System/Library/Frameworks/OpenGL.framework/Headers/gl3.h:1891:21: note: 'glShaderSource' has been explicitly marked deprecated here
GLAPI void APIENTRY glShaderSource (GLuint shader, GLsizei count, const GLchar* const *string, const GLint *length) OPENGL_DEPRECATED(10.5, 10.14);
                    ^
src/libavdevice/opengl_enc.c:482:27: error: incompatible function pointer types assigning to 'FF_PFNGLSHADERSOURCEPROC' (aka 'void (*)(unsigned int, int, const char **, const int *)') from 'void (GLuint, GLsizei, const GLchar *const *, const GLint *)' (aka 'void (unsigned int, int, const char *const *, const int *)') [-Wincompatible-function-pointer-types]
    procs->glShaderSource = glShaderSource;
                          ^ ~~~~~~~~~~~~~~
```

Signed-off-by: Billy Robert O'Neal III <bion@microsoft.com>
---
 libavdevice/opengl_enc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Andreas Rheinhardt June 1, 2024, 12:30 a.m. UTC | #1
Billy O'Neal (VC AIR) via ffmpeg-devel:
> Resolves the following compiler error on macOS 14.5:
> 
> ```console
> /Library/Developer/CommandLineTools/SDKs/MacOSX14.4.sdk/System/Library/Frameworks/OpenGL.framework/Headers/gl3.h:1891:21: note: 'glShaderSource' has been explicitly marked deprecated here
> GLAPI void APIENTRY glShaderSource (GLuint shader, GLsizei count, const GLchar* const *string, const GLint *length) OPENGL_DEPRECATED(10.5, 10.14);
>                     ^
> src/libavdevice/opengl_enc.c:482:27: error: incompatible function pointer types assigning to 'FF_PFNGLSHADERSOURCEPROC' (aka 'void (*)(unsigned int, int, const char **, const int *)') from 'void (GLuint, GLsizei, const GLchar *const *, const GLint *)' (aka 'void (unsigned int, int, const char *const *, const int *)') [-Wincompatible-function-pointer-types]
>     procs->glShaderSource = glShaderSource;
>                           ^ ~~~~~~~~~~~~~~
> ```
> 
> Signed-off-by: Billy Robert O'Neal III <bion@microsoft.com>
> ---
>  libavdevice/opengl_enc.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/libavdevice/opengl_enc.c b/libavdevice/opengl_enc.c
> index 6f7a30ff9e..691bee22ad 100644
> --- a/libavdevice/opengl_enc.c
> +++ b/libavdevice/opengl_enc.c
> @@ -117,7 +117,7 @@ typedef void   (APIENTRY *FF_PFNGLATTACHSHADERPROC) (GLuint program, GLuint shad
>  typedef GLuint (APIENTRY *FF_PFNGLCREATESHADERPROC) (GLenum type);
>  typedef void   (APIENTRY *FF_PFNGLDELETESHADERPROC) (GLuint shader);
>  typedef void   (APIENTRY *FF_PFNGLCOMPILESHADERPROC) (GLuint shader);
> -typedef void   (APIENTRY *FF_PFNGLSHADERSOURCEPROC) (GLuint shader, GLsizei count, const char* *string, const GLint *length);
> +typedef void   (APIENTRY *FF_PFNGLSHADERSOURCEPROC) (GLuint shader, GLsizei count, const char* const *string, const GLint *length);
>  typedef void   (APIENTRY *FF_PFNGLGETSHADERIVPROC) (GLuint shader, GLenum pname, GLint *params);
>  typedef void   (APIENTRY *FF_PFNGLGETSHADERINFOLOGPROC) (GLuint shader, GLsizei bufSize, GLsizei *length, char *infoLog);
>  

It seems that the extra const is apple-only, so this patch should be
restricted to it.

- Andreas
Billy O'Neal \(VC AIR\) June 3, 2024, 3:51 p.m. UTC | #2
Assigning the non-const version to the const version is valid (at least, builds on other platforms succeeded).

Would you still like Apple guards? (I'm hesitating only because most upstreams ask for minimal preprocessor use)

Thanks for the consideration!

Get Outlook for Android<https://aka.ms/AAb9ysg>
Andreas Rheinhardt June 3, 2024, 10:08 p.m. UTC | #3
Billy O'Neal (VC AIR) via ffmpeg-devel:
> Assigning the non-const version to the const version is valid (at least, builds on other platforms succeeded).
> 

It is not valid: "If a converted pointer is used to call a function
whose type is not compatible with the referenced type, the behavior is
undefined." (C11 6.3.2.3 (8))
It will mostly work, because there is no problem from an ABI point of
view. But it is nevertheless undefined behaviour (and recent version's
of Clang's undefined behavior sanitizer actually check for such mismatches).

> Would you still like Apple guards? (I'm hesitating only because most upstreams ask for minimal preprocessor use)
> 
> Thanks for the consideration!
> 
> Get Outlook for Android<https://aka.ms/AAb9ysg>
> ________________________________
> From: ffmpeg-devel <ffmpeg-devel-bounces@ffmpeg.org> on behalf of Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
> Sent: Friday, May 31, 2024 5:30:49 PM
> To: ffmpeg-devel@ffmpeg.org <ffmpeg-devel@ffmpeg.org>
> Subject: Re: [FFmpeg-devel] [PATCH] Add extra const to FF_PFNGLSHADERSOURCEPROC.
> 
> [You don't often get email from andreas.rheinhardt@outlook.com. Learn why this is important at https://aka.ms/LearnAboutSenderIdentification ]
> 
> Billy O'Neal (VC AIR) via ffmpeg-devel:
>> Resolves the following compiler error on macOS 14.5:
>>
>> ```console
>> /Library/Developer/CommandLineTools/SDKs/MacOSX14.4.sdk/System/Library/Frameworks/OpenGL.framework/Headers/gl3.h:1891:21: note: 'glShaderSource' has been explicitly marked deprecated here
>> GLAPI void APIENTRY glShaderSource (GLuint shader, GLsizei count, const GLchar* const *string, const GLint *length) OPENGL_DEPRECATED(10.5, 10.14);
>>                     ^
>> src/libavdevice/opengl_enc.c:482:27: error: incompatible function pointer types assigning to 'FF_PFNGLSHADERSOURCEPROC' (aka 'void (*)(unsigned int, int, const char **, const int *)') from 'void (GLuint, GLsizei, const GLchar *const *, const GLint *)' (aka 'void (unsigned int, int, const char *const *, const int *)') [-Wincompatible-function-pointer-types]
>>     procs->glShaderSource = glShaderSource;
>>                           ^ ~~~~~~~~~~~~~~
>> ```
>>
>> Signed-off-by: Billy Robert O'Neal III <bion@microsoft.com>
>> ---
>>  libavdevice/opengl_enc.c | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/libavdevice/opengl_enc.c b/libavdevice/opengl_enc.c
>> index 6f7a30ff9e..691bee22ad 100644
>> --- a/libavdevice/opengl_enc.c
>> +++ b/libavdevice/opengl_enc.c
>> @@ -117,7 +117,7 @@ typedef void   (APIENTRY *FF_PFNGLATTACHSHADERPROC) (GLuint program, GLuint shad
>>  typedef GLuint (APIENTRY *FF_PFNGLCREATESHADERPROC) (GLenum type);
>>  typedef void   (APIENTRY *FF_PFNGLDELETESHADERPROC) (GLuint shader);
>>  typedef void   (APIENTRY *FF_PFNGLCOMPILESHADERPROC) (GLuint shader);
>> -typedef void   (APIENTRY *FF_PFNGLSHADERSOURCEPROC) (GLuint shader, GLsizei count, const char* *string, const GLint *length);
>> +typedef void   (APIENTRY *FF_PFNGLSHADERSOURCEPROC) (GLuint shader, GLsizei count, const char* const *string, const GLint *length);
>>  typedef void   (APIENTRY *FF_PFNGLGETSHADERIVPROC) (GLuint shader, GLenum pname, GLint *params);
>>  typedef void   (APIENTRY *FF_PFNGLGETSHADERINFOLOGPROC) (GLuint shader, GLsizei bufSize, GLsizei *length, char *infoLog);
>>
> 
> It seems that the extra const is apple-only, so this patch should be
> restricted to it.
>
Billy O'Neal \(VC AIR\) June 5, 2024, 12:30 a.m. UTC | #4
Makes sense. I'm validating that a patch with the #ifdef succeeds and will attempt to add it as a reply if that works. I apologize for my misunderstanding of the situation, and the horrible Outlook signature. (And in advance if my git format-patch use afterwards accidentally makes a new thread rather than attaching it to this one)

Thanks again for the feedback and consideration,

Billy O'Neal
Visual C++ - vcpkg

I believed that

void f(GLuint shader, GLsizei count, const char**string, const GLint *length);

was compatible with

void f(GLuint shader, GLsizei count, const char* const*string, const GLint *length);

based largely on that assignment succeeding everywhere, but I was mistaken. See C11 6.7.6.3 "Function declarators (including prototypes)"/15:

> Moreover, the parameter type lists, if both are present, shall agree in the number of
> parameters and in use of the ellipsis terminator; corresponding parameters shall have
> compatible types.

OK, so this reduces to "is const char** compatible with const char* const *"

6.7.6.1 "Pointer declarators"/2:

>For two pointer types to be compatible, both shall be identically qualified and both shall
>be pointers to compatible types.

Validation build running: https://github.com/microsoft/vcpkg/pull/39132/
diff mbox series

Patch

diff --git a/libavdevice/opengl_enc.c b/libavdevice/opengl_enc.c
index 6f7a30ff9e..691bee22ad 100644
--- a/libavdevice/opengl_enc.c
+++ b/libavdevice/opengl_enc.c
@@ -117,7 +117,7 @@  typedef void   (APIENTRY *FF_PFNGLATTACHSHADERPROC) (GLuint program, GLuint shad
 typedef GLuint (APIENTRY *FF_PFNGLCREATESHADERPROC) (GLenum type);
 typedef void   (APIENTRY *FF_PFNGLDELETESHADERPROC) (GLuint shader);
 typedef void   (APIENTRY *FF_PFNGLCOMPILESHADERPROC) (GLuint shader);
-typedef void   (APIENTRY *FF_PFNGLSHADERSOURCEPROC) (GLuint shader, GLsizei count, const char* *string, const GLint *length);
+typedef void   (APIENTRY *FF_PFNGLSHADERSOURCEPROC) (GLuint shader, GLsizei count, const char* const *string, const GLint *length);
 typedef void   (APIENTRY *FF_PFNGLGETSHADERIVPROC) (GLuint shader, GLenum pname, GLint *params);
 typedef void   (APIENTRY *FF_PFNGLGETSHADERINFOLOGPROC) (GLuint shader, GLsizei bufSize, GLsizei *length, char *infoLog);