Commit graph

48 commits

Author SHA1 Message Date
Ozkan Sezer 9f21bed729 dynapi: cast GetProcAddress() result to void* 2023-02-03 17:40:40 +03:00
Ozkan Sezer 2ec9a20204 SDL_dynapi.c: add extern "C" guards, just in case.. 2023-01-12 14:01:32 +03:00
Sam Lantinga fde78d12f2 Updated copyright for 2023 2023-01-09 09:41:41 -08:00
Ozkan Sezer 929da2c28e SDL_dynapi.c: LoadLibraryA() returns HMODULE. 2022-12-30 11:11:10 +03:00
Sam Lantinga 63724c113b Removed the vi format comments from the source
Vim users can use the [editorconfig plugin](https://github.com/editorconfig/editorconfig-vim) to automatically set tab spacing for the SDL coding style.

Fixes https://github.com/libsdl-org/SDL/issues/6903
2022-12-26 11:17:23 -08:00
Daniel Gibson 28b93451dc Make WinRT's SDL_main header-only
As the implementation requires C++, the user will have to include
SDL_main.h in a C++ source file (that needs to be compiled with /ZW).
It's ok to keep the standard main() implementation in plain C and use
an otherwise empty C++ source file for the SDL_main implementation part,
if both source files #include <SDL3/SDL_main.h>

Including SDL_main.h in a C source file will print a message at
compilation (when building for WinRT or possibly other not yet implemented
platforms that require C++ for main), to remind the user of also
including it in a .cpp source file. This message/warning can be disabled
with #define SDL_MAIN_NOIMPL before including SDL_main.h in the C file.
When including it in a .cpp file, there will be a compiler error with
helpful message if it's not compiled with /ZW

For this I renamend _SDL_MAIN_NOIMPL to SDL_MAIN_NOIMPL, because now it's
not for internal use only anymore, but also useful for users (that want
their main() function in a different file than the SDL_main implementation)

Add a project for the testdraw2.c test to the WinRT solution to at least
get some minimal testing on WinRT.
I won't add all tests because it's a lot of manual clicking per test,
but this should be better than nothing :)
2022-12-15 08:01:01 -08:00
Daniel Gibson ca2fe7be1a Implement SDL_main as header-only lib for Win32
(remaining platforms will follow)

SDL_main.h is *not* included by SDL.h anymore, users are supposed to
include it directly now, usually only in the file they implement main() in.
If they need the header elsewhere or don't want SDL_main to implement
main() (but only call SDL_SetMainReady() or whatever), they
can #define SDL_MAIN_HANDLED first, same as before.
For SDL-internal usage, I added _SDL_MAIN_NOIMPL, which *also* skips the
implementation and `#define main SDL_main`, but still defines
SDL_MAIN_AVAILABLE and SDL_MAIN_NEEDED in SDL_main.h, as before.

To make the implementaion in the header shorter and avoid including windows.h,
I moved most of the Win32 SDL_main code into SDL3.dll via SDL_Win32RunApp(),
so the header-only part is just the different main functions calling
SDL_Win32RunApp(SDL_main, NULL)

Note that I changed changed the return value and type of OutOfMemory()
to return -1 instead of FALSE, so main() (or WinMain() or whatever)
returns -1 instead of 0 in case of an out-of-memory error

Compared to original Win32 SDL_main, I tweaked the part of the
implementation in SDL_main_impl.h a bit to avoid linker warnings
and conflicts with stuff from windows.h:

- replaced windows.h with own define of WINAPI
  and typedef-ing HINSTANCE and LPSTR.
  This prevents conflicts between all the generically-named #defines and
  types in windows.h and user code (like DrawState in some SDL tests)
- only using one of main() or wmain() gets rid of a MSVC linker error
  ("warning LNK4067: ambiguous entry point")
  If this still causes problems, we might try getting rid of wmain(),
  seemed to me like MSVC can use regular main() in UNICODE mode as well
- simplified the UNICODE logic for that - while this is not exactly
  equivalent to the old, it should make sense and Works For Me
2022-12-15 08:01:01 -08:00
Sylvain 778b8926b4
Small format changed (using clang-format 15.0.2-1) 2022-12-01 09:39:08 +01:00
Sam Lantinga 5750bcb174
Update for SDL3 coding style (#6717)
I updated .clang-format and ran clang-format 14 over the src and test directories to standardize the code base.

In general I let clang-format have it's way, and added markup to prevent formatting of code that would break or be completely unreadable if formatted.

The script I ran for the src directory is added as build-scripts/clang-format-src.sh

This fixes:
#6592
#6593
#6594
2022-11-30 12:51:59 -08:00
Ryan C. Gordon a3225ae6de
dynapi: Abstract out the environment variable name. 2022-11-29 14:13:07 -05:00
Sam Lantinga 0a48abc860 Switch header convention from #include "SDL.h" to #include <SDL3/SDLh>
I ran this script in the include directory:
```sh
sed -i '' -e 's,#include "\(SDL.*\)",#include <SDL3/\1>,' *.h
```

I ran this script in the src directory:
```sh
for i in ../include/SDL3/SDL*.h
do hdr=$(basename $i)
   if [ x"$(echo $hdr | egrep 'SDL_main|SDL_name|SDL_test|SDL_syswm|SDL_opengl|SDL_egl|SDL_vulkan')" != x ]; then
        find . -type f -exec sed -i '' -e 's,#include "\('$hdr'\)",#include <SDL3/\1>,' {} \;
    else
        find . -type f -exec sed -i '' -e '/#include "'$hdr'"/d' {} \;
    fi
done
```

Fixes https://github.com/libsdl-org/SDL/issues/6575
2022-11-26 22:15:18 -08:00
Ryan C. Gordon 80c1ddbe97
dynapi: Bumped dynapi version to 2, so SDL2 libs don't conflict. 2022-11-26 09:49:18 -05:00
Sam Lantinga 63f307fe1f Remove SDL_config.h from the public headers
The SDL headers are no longer dependent on the build configuration.

Fixes https://github.com/libsdl-org/SDL/issues/6643 and https://github.com/libsdl-org/SDL/issues/6641
2022-11-26 04:48:36 -08:00
Ozkan Sezer 5cedc2f1ff removed QNX support. 2022-11-22 20:23:40 +03:00
Ozkan Sezer 8d6fda4810 removed os2 support & support for building SDL with watcom. 2022-11-22 19:18:47 +03:00
Sam Lantinga 2c4159b99a First pass at changing SDL 2.0 to SDL 3.0 2022-11-21 20:28:58 -08:00
Ryan C. Gordon 2d7816e358
dynapi: Disable support for API call logging by default.
We can manually enable it if necessary, but it bloats the library to
leave it on just in case.

Fixes #6381.
2022-10-12 09:59:31 -04:00
Ryan C. Gordon 17322e2be6
dynapi: Optionally log every call into the SDL API.
This will only log things going through dynapi, which means it won't
do anything if dynapi is disabled for a given build, but also things
that call the `*_REAL` version of an API won't log either (which is
to say, if an internal piece of SDL calls a public API, it won't log
it, but if an application calls that same entry point, it will).

Since this just inserts a different function pointer, unless you
explicitly request this at runtime, it won't add any overhead, and,
of course, the entire thing can be turned off with a single #define
so it doesn't even add extra unused code to the shared library if
the kill switch is flipped.
2022-10-10 13:17:07 -04:00
chalonverse f317d619cc
Xbox GDKX support (#5869)
* Xbox GDK support (14 squashed commits)

* Added basic keyboard testing

* Update readme

* Code review fixes

* Fixed issue where controller add/removal wasn't working (since the device notification events don't work on Xbox, have to use the joystick thread to poll XInput)
2022-07-01 13:59:14 -07:00
Sam Lantinga 1d1fb95a61 Removed double va_end() 2022-06-28 06:21:45 -07:00
Sylvain f815580dde
Fix SIGSEV in SDL_error. Re-apply same pattern on this uncompiled code (see #5795) 2022-06-28 13:09:38 +02:00
Sam Lantinga cbd0187475 Removed the limit on the size of the SDL error message
Also added SDL_GetOriginalMemoryFunctions()

Fixes https://github.com/libsdl-org/SDL/issues/5795
2022-06-27 16:59:50 -07:00
Sam Lantinga 120c76c84b Updated copyright for 2022 2022-01-03 09:40:21 -08:00
Cameron Cawley 25a614bc3e Add SDL_asprintf and SDL_vasprintf 2021-09-22 11:53:46 -07:00
Sam Lantinga 432ee7d8ad Fixed building SDL_dynapi.c without stdio support 2021-09-22 09:29:21 -07:00
Sam Lantinga 9130f7c377 Updated copyright for 2021 2021-01-02 10:25:38 -08:00
Sam Lantinga a8780c6a28 Updated copyright date for 2020 2020-01-16 20:49:25 -08:00
Sylvain Becker 3d100df36f Readability: remove const-qualifation from function declaration
const-qualification of parameters only has an effect in function definitions
2019-10-30 15:43:49 +01:00
Ryan C. Gordon ec04110d8e dynapi: Deal with failure cases better, other fixes.
Fixes Bugzilla #4803.
2019-10-14 12:41:06 -04:00
Ozkan Sezer ceee7def84 minor build fixes. 2019-07-31 00:05:28 +03:00
Sam Lantinga 5e13087b0f Updated copyright for 2019 2019-01-04 22:01:14 -08:00
Ozkan Sezer cbacb0f1ea add missing include. 2018-10-14 23:50:50 +03:00
Ryan C. Gordon e2619f1dcf dynapi: don't let system loader resolve the initializer to the wrong version.
Fixes problems launching Firewatch on Linux (which statically links SDL but
also dynamically loads a system-wide copy from a plugin shared library) with
a newer SDL build.
2018-05-17 12:50:46 -04:00
sezero 40b27fd51b revert the recent typecast assignment changes (see bug #4079)
also change the void* typedefs for the two vulkan function
pointers added in vulkan_internal.h  into generic function
pointer typedefs.
2018-02-12 17:00:00 +03:00
Sam Lantinga 90e72bf4e2 Fixed ISO C99 compatibility
SDL now builds with gcc 7.2 with the following command line options:
-Wall -pedantic-errors -Wno-deprecated-declarations -Wno-overlength-strings --std=c99
2018-01-30 18:08:34 -08:00
Sam Lantinga e3cc5b2c6b Updated copyright for 2018 2018-01-03 10:03:25 -08:00
Sam Lantinga 37ce9f2773 Fixed typedef redefinition errors when including both SDL_vulkan.h and vulkan.h
You should always include vulkan/vulkan.h first, then include SDL_vulkan.h
2017-08-27 23:13:15 -07:00
Sam Lantinga b7c5d15152 SDL_dynapi.c: add missing SDLCALL to macros. 2017-08-27 18:53:30 -07:00
Sam Lantinga a38f127e88 Swapped conditional arguments for standard SDL readability 2017-08-27 18:52:43 -07:00
Ryan C. Gordon 8c39d1d0b5 OS/2: fixed inverted logic bug (thanks, Ozkan!). 2017-08-25 12:27:18 -04:00
Ryan C. Gordon 2213077a95 OS/2: proper fix for dynapi (thanks, Ozkan!). 2017-08-25 11:31:12 -04:00
Ryan C. Gordon a3890ff6d7 dynapi: fill in OS/2 loading code (thanks, Ozkan!).
Partially fixes Bugzilla #3765.
2017-08-22 15:50:39 -04:00
Ryan C. Gordon 22241ed0b0 Support for QNX 7.0 (thanks, Elad!).
Fixes Bugzilla #3686.
2017-07-01 17:50:47 -04:00
Sam Lantinga 45b774e3f7 Updated copyright for 2017 2017-01-01 18:33:28 -08:00
Sam Lantinga 9a8642bd6a Fixed bug 3478 - Patch Haiku to use dlopen instead of load_add_on
Kai Sterker

SDL2 on Haiku so far uses Haiku-specific APIs for loading dynamic objects as add-ons, instead of using dlopen to load them as libraries. This, for example, leads to SDL_mixer not being able to load its audio backends, when compiled with standard settings.

As discussed at https://www.freelists.org/post/haikuports/SDL2-mixer-ogg-music-not-playing-and-other-stuff,2 , the best way to deal with this would be using dlopen instead of load_add_on. The following patch implements this change by dropping the Haiku-specific bits and using dlopen instead.
2016-11-01 10:30:46 -07:00
Ryan C. Gordon fa8c83c1c1 Remove almost all instances of "volatile" keyword.
As Tiffany pointed out in Bugzilla, volatile is not useful for thread safety:

https://software.intel.com/en-us/blogs/2007/11/30/volatile-almost-useless-for-multi-threaded-programming/

Some of these volatiles didn't need to be, some were otherwise protected by
spinlocks or mutexes, and some got moved over to SDL_atomic_t data, etc.

Fixes Bugzilla #3220.
2016-01-03 06:50:50 -05:00
Sam Lantinga 42065e785d Updated copyright to 2016 2016-01-02 10:10:34 -08:00
Philipp Wiesemann 0e45984fa0 Fixed crash if initialization of EGL failed but was tried again later.
The internal function SDL_EGL_LoadLibrary() did not delete and remove a mostly
uninitialized data structure if loading the library first failed. A later try to
use EGL then skipped initialization and assumed it was previously successful
because the data structure now already existed. This led to at least one crash
in the internal function SDL_EGL_ChooseConfig() because a NULL pointer was
dereferenced to make a call to eglBindAPI().
2015-06-21 17:33:46 +02:00