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 3765

Summary: os/2 bits
Product: SDL Reporter: Ozkan Sezer <sezeroz>
Component: *don't know*Assignee: Sam Lantinga <slouken>
Status: RESOLVED FIXED QA Contact: Sam Lantinga <slouken>
Severity: normal    
Priority: P2 CC: icculus
Version: HG 2.0   
Hardware: x86   
OS: OS/2   
Attachments: cpuinfo patch
dynapi patch
thread.h patch

Description Ozkan Sezer 2017-08-21 19:55:19 UTC
Here are the last of the bits I can submit to mainstream,
would be nice to have in 2.0.6.

1. SDL_cpuinfo.c: add os/2 support to SDL_GetCPUCount() and SDL_GetSystemRAM().

2. SDL_dynapi.h: disable dynapi for os/2.

3. SDL_thread.h: add missing os/2 defines.
 (essentially replicates the windows case || SDL1.2 case.)
Comment 1 Ozkan Sezer 2017-08-21 19:55:46 UTC
Created attachment 2870 [details]
cpuinfo patch
Comment 2 Ozkan Sezer 2017-08-21 19:56:08 UTC
Created attachment 2871 [details]
dynapi patch
Comment 3 Ozkan Sezer 2017-08-21 19:56:33 UTC
Created attachment 2872 [details]
thread.h patch
Comment 5 Ryan C. Gordon 2017-08-22 05:11:54 UTC
(In reply to Ozkan Sezer from comment #0)
> 2. SDL_dynapi.h: disable dynapi for os/2.

This isn't super-urgent, but is there any reason this _can't_ work on OS/2, other than we still need to fill in some DosLoadModule/DosQueryProcAddr calls?

--ryan.
Comment 6 Ozkan Sezer 2017-08-22 06:29:36 UTC
> This isn't super-urgent, but is there any reason this
> _can't_ work on OS/2, other than we still need to fill
> in some DosLoadModule/DosQueryProcAddr calls?

No, there is not.
Comment 7 Ozkan Sezer 2017-08-22 07:08:15 UTC
>> This isn't super-urgent, but is there any reason this
>> _can't_ work on OS/2, other than we still need to fill
>> in some DosLoadModule/DosQueryProcAddr calls?
> 
> No, there is not.

Well I forgot that there is this: if I do the following in SDL_dynapi.c
and define SDL_DYNAMIC_API as 1, it builds yes, but nothing is exported
in the dll, so I gave up without a fight.  (The original 2.0.4 port by
Andrey possibly had the same issue.)

#elif defined(__OS2__)
#define INCL_DOS
#define INCL_DOSERRORS
#include <dos.h>
static SDL_INLINE void *get_sdlapi_entry(const char *fname, const char *sym)
{
    HMODULE hmodule;
    PFN retval = NULL;
    char error[256];
    if (NO_ERROR == DosLoadModule(&error, sizeof(error), fname, &hmodule)) {
        if (NO_ERROR == DosQueryProcAddr(handle, 0, sym, &retval)) {
            DosFreeModule(hmodule);
        }
    }
    return retval;
}
Comment 8 Ryan C. Gordon 2017-08-22 19:51:32 UTC
> Well I forgot that there is this: if I do the following in SDL_dynapi.c
> and define SDL_DYNAMIC_API as 1, it builds yes, but nothing is exported
> in the dll, so I gave up without a fight.

I've put this code in revision control: https://hg.libsdl.org/SDL/rev/6120f75935f9

Is BUILD_SDL defined when this code compiles? That's the magic in begin_code.h that tells OpenWatcom that DECLSPEC symbols should be exported, and should make SDL_DYNAPI_entry export in that file (at least, it _should_ do that...).

Also, while we're talking: one of our Linux buildbots has OpenWatcom available on it, so if all this OS/2 work gets far enough along, we can have it start doing OS/2 builds on each commit.  :)   I already do this with PhysicsFS, fwiw: https://physfs-buildbot.icculus.org/builders/physfs-os2

--ryan.
Comment 9 Ozkan Sezer 2017-08-22 20:21:47 UTC
> I've put this code in revision control: https://hg.libsdl.org/SDL/rev/6120f75935f9

Well, it won't compile: I obviously pasted an old experiment
(it's a mess on my hard drive), here's a one that really builds:

diff -r 6120f75935f9 src/dynapi/SDL_dynapi.c
--- a/src/dynapi/SDL_dynapi.c
+++ b/src/dynapi/SDL_dynapi.c
@@ -24,6 +24,12 @@
 
 #if SDL_DYNAMIC_API
 
+#if defined(__OS2__)
+#define INCL_DOS
+#define INCL_DOSERRORS
+#include <dos.h>
+#endif
+
 #include "SDL.h"
 
 /* !!! FIXME: Shouldn't these be included in SDL.h? */
@@ -232,16 +238,13 @@
 }
 
 #elif defined(__OS2__)
-#define INCL_DOS
-#define INCL_DOSERRORS
-#include <dos.h>
 static SDL_INLINE void *get_sdlapi_entry(const char *fname, const char *sym)
 {
     HMODULE hmodule;
     PFN retval = NULL;
     char error[256];
     if (NO_ERROR == DosLoadModule(&error, sizeof(error), fname, &hmodule)) {
-        if (NO_ERROR == DosQueryProcAddr(handle, 0, sym, &retval)) {
+        if (NO_ERROR == DosQueryProcAddr(hmodule, 0, sym, &retval)) {
             DosFreeModule(hmodule);
         }
     }


> Is BUILD_SDL defined when this code compiles? That's the magic in begin_code.h
> that tells OpenWatcom that DECLSPEC symbols should be exported, and should
> make SDL_DYNAPI_entry export in that file (at least, it _should_ do that...).

It is indeed defined by the makefile. However, my first comment was not
completely correct, because :

1. SOME of the exports are missing, such as SDL_Log, e.g. testsuite fails
  like this:
Error! E2028: SDL_Log is an undefined reference
file testsprite2.obj(test/testsprite2.c): undefined symbol SDL_Log
file SDL_test_common.obj(src/test/SDL_test_common.c): undefined symbol SDL_Log

2. dynapi.c, is missing SDLCALL everywhere in its table defines, so
  it requires work if one really wants to build with dynapi enabled.


> Also, while we're talking: one of our Linux buildbots has OpenWatcom
> available on it, so if all this OS/2 work gets far enough along, we
> can have it start doing OS/2 builds on each commit.  :)

It would be cool. However, there are some fixes that needs to go in
before a build can succeed:

Bug #3740: otherwise testime.c won't build
Bug #3767: because watcom doesn't ship with scalbn(),
  except for the v2 fork at github

Optionals: bug #3769 and bug #3739

Besides, I don't know how you can build without the os/2 implementation
files themselves. Andrey still haven't responded to me.  (I can send to
your private email, though, if you want.)

> I already do this with PhysicsFS, fwiw:
> https://physfs-buildbot.icculus.org/builders/physfs-os2

OK.
Comment 10 Ozkan Sezer 2017-08-24 02:07:01 UTC
OK, after several hours of pulling out my hair, found the culprit:
wlib is not case-sensitive by default, and it discarded SDL_Log()
in favor of SDL_log(). Using its -c switch when creating the import
lib fixes everything. Created bug #3771.
Comment 11 Ryan C. Gordon 2017-08-25 15:32:19 UTC
(In reply to Ozkan Sezer from comment #9)
> Well, it won't compile: I obviously pasted an old experiment
> (it's a mess on my hard drive), here's a one that really builds:

This patch is now https://hg.libsdl.org/SDL/rev/6e1d0d1e2a5b, thanks!

> Besides, I don't know how you can build without the os/2 implementation
> files themselves. Andrey still haven't responded to me.  (I can send to
> your private email, though, if you want.)

Yeah, I was just talking about the future.  :)

--ryan.