We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 5107 - Warning on implicit declaration of function 'memset_pattern4' on OSX
Summary: Warning on implicit declaration of function 'memset_pattern4' on OSX
Status: RESOLVED FIXED
Alias: None
Product: SDL
Classification: Unclassified
Component: *don't know* (show other bugs)
Version: 2.0.12
Hardware: x86_64 Mac OS X (All)
: P2 normal
Assignee: Ryan C. Gordon
QA Contact: Sam Lantinga
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-04-23 07:58 UTC by LGB
Modified: 2020-10-30 09:15 UTC (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description LGB 2020-04-23 07:58:49 UTC
Recently I get C compiler warning on OSX on every file which includes SDL2.h:

In file included from /usr/local/include/SDL2/SDL.h:32:
In file included from /usr/local/include/SDL2/SDL_main.h:25:
/usr/local/include/SDL2/SDL_stdinc.h:426:5: warning: implicit declaration of function 'memset_pattern4' is invalid in C99 [-Wimplicit-function-declaration]
    memset_pattern4(dst, &val, dwords * 4);
    ^
1 warning generated.

As far as I know (I just google'd for this), memset_pattern4() is in string.h in OSX. So I tried to include string.h before SDL.h, but interestingly the same warning ... But even if it works, I guess SDL should include the right header file for a given function by its own too. Though my project compiles regardless of the warnings, it's ugly, and may have other implications not knowing the prototype well enough by the compiler, I guess.

I use Apple's "gcc" (at least they use this name) which in fact is clang:

Apple clang version 11.0.0 (clang-1100.0.33.8)

System info:

ProductName:	Mac OS X
ProductVersion:	10.14.6
BuildVersion:	18G3020

SDL2 is from homebrew:

==> Downloading https://homebrew.bintray.com/bottles/sdl2-2.0.12_1.mojave.bottle.tar.gz

Example build output (using travis-ci.org):

https://travis-ci.org/github/lgblgblgb/xemu/jobs/678485424

Thanks for your attention!
Comment 1 LGB 2020-04-23 08:57:33 UTC
Sorry, I meant "includes SDL.h" not SDL2.h. But from SDL2 :)
Comment 2 ux 2020-10-22 13:34:45 UTC
We have the same problem in our project. It boils down to using SDL.h with POSIX features. Following is a very simple way of reproducing the issue:

    echo '#include<SDL.h>' | cc -Wall -Werror=missing-prototypes -D_POSIX_C_SOURCE=200112L $(pkg-config --cflags sdl2) -x c -c -

We use POSIX features for network stuff, and we do actually also have -Werror=missing-prototypes (it's usually a source of important bugs), which makes this warning a fatal error in our case.
Comment 3 Vitaly Novichkov 2020-10-29 07:58:43 UTC
I got on macOS 10.15.7 with the Xcode 11.4.1 the next:

---
In file included from include/SDL2/SDL_loadso.h:44:
include/SDL2/SDL_stdinc.h:426:5: error: implicit declaration of function 'memset_pattern4' [-Werror,-Wimplicit-function-declaration]
    memset_pattern4(dst, &val, dwords * 4);
    ^
---


And then:

---
In file included from include/SDL2/SDL_loadso.h:44:
include/SDL2/SDL_stdinc.h:426:5: error: implicit declaration of function 'memset_pattern4' [-Werror,-Wimplicit-function-declaration]
    memset_pattern4(dst, &val, dwords * 4);
    ^
---
Comment 4 Vitaly Novichkov 2020-10-29 08:00:23 UTC
I had to use the latest state at the top of Mercurial.
Comment 5 Vitaly Novichkov 2020-10-29 08:01:42 UTC
I got them as errors that broke the build of my project, not just warnings...
Comment 6 Ozkan Sezer 2020-10-29 11:51:28 UTC
Does it help if we define _DARWIN_C_SOURCE at top of SDL_stdinc.h?
Like:

diff --git a/include/SDL_stdinc.h b/include/SDL_stdinc.h
--- a/include/SDL_stdinc.h
+++ b/include/SDL_stdinc.h
@@ -30,6 +30,10 @@
 
 #include "SDL_config.h"
 
+#ifdef __APPLE__
+#define _DARWIN_C_SOURCE /* for memset_pattern4() */
+#endif
+
 #ifdef HAVE_SYS_TYPES_H
 #include <sys/types.h>
 #endif
Comment 7 Vitaly Novichkov 2020-10-29 12:31:04 UTC
Booting my macOS machine to verify that...
Comment 8 Vitaly Novichkov 2020-10-29 12:44:50 UTC
Nope, the error is still appear...

Anyway, what I see inside:

This condition blocks the necessary call:
```
#if __DARWIN_C_LEVEL >= __DARWIN_C_FULL
```

And the condition that defines the proper __DARWIN_C_LEVEL:
```
#if   defined(_ANSI_SOURCE)
#define __DARWIN_C_LEVEL        __DARWIN_C_ANSI
#elif defined(_POSIX_C_SOURCE) && !defined(_DARWIN_C_SOURCE) && !defined(_NONSTD_SOURCE)
#define __DARWIN_C_LEVEL        _POSIX_C_SOURCE
#else
#define __DARWIN_C_LEVEL        __DARWIN_C_FULL
#endif
```
At me I see it has _POSIX_C_SOURCE value.
Comment 9 Ozkan Sezer 2020-10-29 13:58:25 UTC
I am guessing that you include system headers, such as string.h, before
SDL_stdinc.h (or SDL.h), meaning _DARWIN_C_SOURCE has no effect anymore.
I can only suggest that you include SDL_stdinc.h (or SDL.h) before all
system headers.  Does it help if you do so?
Comment 10 Vitaly Novichkov 2020-10-29 14:13:14 UTC
I'll check a bit later, however, I can point that problem does happens at here:

https://github.com/WohlSoft/SDL-Mixer-X/blob/master/src/codecs/music_flac.c#L28

the "SDL_assert.h" was loaded before "SDL_loadso.h" which does include of "SDL_stdinc.h" from inside.
Comment 11 Vitaly Novichkov 2020-10-29 14:14:04 UTC
I may guess, the mainstream SDL_mixer will get the same build error too...
Comment 12 Vitaly Novichkov 2020-10-29 14:15:27 UTC
Probably, I will need to try define the _DARWIN_C_SOURCE globally for entire project as a small test...
Comment 13 Ozkan Sezer 2020-10-29 14:26:35 UTC
(In reply to Vitaly Novichkov from comment #10)
> I'll check a bit later, however, I can point that problem does happens at
> here:
> 
> https://github.com/WohlSoft/SDL-Mixer-X/blob/master/src/codecs/music_flac.
> c#L28
> 
> the "SDL_assert.h" was loaded before "SDL_loadso.h" which does include of
> "SDL_stdinc.h" from inside.

Because SDL_assert.h includes signal.h, and that nullifies _DARWIN_C_SOURCE

That can easily be rectified by flipping the order of SDL_assert.h and
SDL_loadso.h includes in music_flac.c and music_mpg123.c, if that is the
only issue.
Comment 14 Vitaly Novichkov 2020-10-29 15:03:04 UTC
I see, also music_cmd.c got affeted too, native_midi_macosx.c also. effects_internal.c, effect_stereoreserve.c, mixer.c, effect_position.c. To fix them I had to include SDL_stdinc.h at top of all of those files, or move the inclusion of SDL.h into the top of standard includes where also defined.
Comment 15 Vitaly Novichkov 2020-10-29 15:07:21 UTC
Yeh, once I avoided those headers being included after standard headers and the library got built.

I did a commit into new branch for a test and review: https://github.com/WohlSoft/SDL-Mixer-X/commit/2884d7bb387b916d0764db152f39dab00eaca44c
Comment 16 Vitaly Novichkov 2020-10-29 15:08:49 UTC
(btw, I forgot to include mpg123 fix as I didn't use it mainly because I didn't made my CMake build for it yet, and therefore I don't use it yet. A good reminder to resume my work and finally make the CMake build for it! I have the working build for Linux, but incomplete for other platforms...)
Comment 17 Ozkan Sezer 2020-10-29 15:13:43 UTC
Is it just me, or does bugzilla not send notification emails again?
(I got none of your replies to this bug.)
Comment 18 Vitaly Novichkov 2020-10-29 15:14:52 UTC
> emails

Me too... It got broken again...
Comment 20 Vitaly Novichkov 2020-10-29 17:14:37 UTC
Just now I backported all fixes to MixerX, and I gonna to boot up my macOS machine to verify the fix...
Comment 21 Ozkan Sezer 2020-10-29 17:21:52 UTC
(In reply to Vitaly Novichkov from comment #20)
> Just now I backported all fixes to MixerX, and I gonna to boot up my macOS
> machine to verify the fix...

For SDL_mixer side:  Will mess with music_cmd.c and native_midi later.
(music_cmd is practically a unix thing, but native_midi needs convert
to use SDL_stdinc functions.)
Comment 23 Vitaly Novichkov 2020-10-29 17:25:31 UTC
> Will mess with music_cmd.c and native_midi later.

I had to fix that at me, and I posted my message too late...
Comment 24 Ozkan Sezer 2020-10-29 17:34:24 UTC
(In reply to Vitaly Novichkov from comment #22)
> You missed up the "music_cmd.c" and "native_midi_macosx.c":
> 
> https://github.com/WohlSoft/SDL-Mixer-X/commit/
> 795ae1b0ac19cf767613f40795726c268e0915b2
> https://github.com/WohlSoft/SDL-Mixer-X/commit/
> e14681cafb8c4aba2f715dd0d3cb00a0494071c6
> 
> Also, another minor unrelated fix at native_midi_macosx.c:
> https://github.com/WohlSoft/SDL-Mixer-X/commit/
> eb88f66192c70cd24042263432f9fabe9af228d2

https://hg.libsdl.org/SDL_mixer/rev/a094e8411283
Comment 25 Vitaly Novichkov 2020-10-29 17:35:11 UTC
Okay, now build the works!

(I also had to patch the header at SDL 2.0.12 release copy I had to get build of my project)

Seems, because of this case, all past SDL2 versions are broken for newer Xcode toolchains.
Comment 26 Ozkan Sezer 2020-10-29 17:47:02 UTC
(In reply to Vitaly Novichkov from comment #25)
> Okay, now build the works!
> 
> (I also had to patch the header at SDL 2.0.12 release copy I had to get
> build of my project)

Good. Let's hear from LGB and ux who posted complaints here.

I'll possibly have to adjust other SDL projects for this, too.
Comment 27 Ozkan Sezer 2020-10-29 20:28:22 UTC
I applied include tweaks to SDL_net, SDL_ttf and SDL_image too:
https://hg.libsdl.org/SDL_net/rev/65521c4ca248
https://hg.libsdl.org/SDL_ttf/rev/703ebc7c66fd
https://hg.libsdl.org/SDL_image/rev/fec158a5ebf1

Hopefully everything should be OK.
Comment 28 ux 2020-10-30 09:10:00 UTC
(In reply to Ozkan Sezer from comment #26)
> Good. Let's hear from LGB and ux who posted complaints here.

A quick test shows that the test-case I presented seems addressed, thanks. I'll probably wait for the next release to test in the real-case project though.
Comment 29 Ozkan Sezer 2020-10-30 09:15:26 UTC
(In reply to ux from comment #28)
> A quick test shows that the test-case I presented seems addressed, thanks.
> I'll probably wait for the next release to test in the real-case project
> though.

OK then, closing as fixed.  If issues still show up, please re-open
this and drop a note here.