Skip to content

Commit

Permalink
Win32:
Browse files Browse the repository at this point in the history
Guard some fdlibm.h defines to avoid warnings on Win32.
Make sure the msvc makefile suite builds a UNICODE VM (why doesn't the cygwin
makefile suite do the same?!?!?).
Don't add ".dll" to the end of module names that already have ".dll" added.
  • Loading branch information
eliotmiranda committed May 7, 2020
1 parent 6d13e91 commit acaf284
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 30 deletions.
2 changes: 1 addition & 1 deletion build.win32x86/common/Makefile.msvc.tools
Expand Up @@ -62,7 +62,7 @@ NOBUILTIN:=-D_MT
MACHINE:=x86

DEFS:= $(COGDEFS) $(MEMACCESS) $(WINVER) \
-DWIN32=1 -DWIN32_FILE_SUPPORT -DNO_ISNAN -DNO_SERVICE \
-DWIN32=1 -DUNICODE=1 -DWIN32_FILE_SUPPORT -DNO_ISNAN -DNO_SERVICE \
$(NDEBUG) -DLSB_FIRST -D'VM_NAME="$(VM_NAME)"' $(XDEFS) $(CROQUET)

#############################################################################
Expand Down
2 changes: 1 addition & 1 deletion build.win64x64/common/Makefile.msvc.tools
Expand Up @@ -70,7 +70,7 @@ NOBUILTIN:=-D_MT
MACHINE:=x64

DEFS:= -D$(VM)VM=1 $(COGDEFS) $(MEMACCESS) $(WINVER) \
-DWIN32=1 -DWIN32_FILE_SUPPORT -DNO_ISNAN -DNO_SERVICE \
-DWIN32=1 -DUNICODE=1 -DWIN32_FILE_SUPPORT -DNO_ISNAN -DNO_SERVICE \
$(NDEBUG) -DLSB_FIRST -D'VM_NAME="$(VM_NAME)"' $(XDEFS) $(CROQUET)

#############################################################################
Expand Down
14 changes: 8 additions & 6 deletions platforms/Cross/third-party/fdlibm/fdlibm.h
Expand Up @@ -81,12 +81,14 @@ struct exception {

#define X_TLOSS 1.41484755040568800000e+16

#define DOMAIN 1
#define SING 2
#define OVERFLOW 3
#define UNDERFLOW 4
#define TLOSS 5
#define PLOSS 6
#if !defined(DOMAIN)
# define DOMAIN 1
# define SING 2
# define OVERFLOW 3
# define UNDERFLOW 4
# define TLOSS 5
# define PLOSS 6
#endif

/*
* ANSI/POSIX
Expand Down
54 changes: 32 additions & 22 deletions platforms/win32/vm/sqWin32ExternalPrims.c
Expand Up @@ -11,12 +11,14 @@
* 1) Currently, we're looking for DLLs named either sample.dll or sample32.dll
*
*****************************************************************************/

#include <Windows.h>
#include <stdio.h>
#include <assert.h>
#include "sq.h"

HANDLE tryLoading(TCHAR *prefix, TCHAR *baseName, TCHAR *postfix)
static HANDLE
tryLoading(TCHAR *prefix, TCHAR *baseName, TCHAR *postfix)
{
TCHAR libName[300];
HANDLE h;
Expand All @@ -34,33 +36,42 @@ HANDLE tryLoading(TCHAR *prefix, TCHAR *baseName, TCHAR *postfix)
return h;
}

/* Return the module entry for the given module name */
void *ioLoadModule(char *pluginName)
/* Return the module entry for the given module name, or null if not found */
void *
ioLoadModule(char *pluginName)
{
HANDLE handle;
TCHAR *name;

int nameLen = pluginName ? (int)strlen(pluginName) : 0;
int endsInDLL = nameLen > 4 && !strcmp(pluginName + nameLen - 4, ".dll");

#ifdef UNICODE
int len = MultiByteToWideChar(CP_UTF8, 0, pluginName, -1, NULL, 0);
if (len <= 0) return 0; /* invalid UTF8 ? */
if (len <= 0)
return 0; /* invalid UTF8 ? */
name = alloca(len*sizeof(WCHAR));
if (MultiByteToWideChar(CP_UTF8, 0, pluginName, -1, name, len) == 0) return 0;
if (MultiByteToWideChar(CP_UTF8, 0, pluginName, -1, name, len) == 0)
return 0;
#else
name = pluginName;
#endif

handle = tryLoading(TEXT(""),name,TEXT(""));
if(handle) return handle;
handle = tryLoading(TEXT(""),name,TEXT(".dll"));
if(handle) return handle;
handle = tryLoading(TEXT(""),name,TEXT("32.dll"));
if(handle) return handle;
handle = tryLoading(imagePath,name,TEXT(""));
if(handle) return handle;
handle = tryLoading(imagePath,name,TEXT(".dll"));
if(handle) return handle;
handle = tryLoading(imagePath,name,TEXT("32.dll"));
if(handle) return handle;
if ((handle = tryLoading(TEXT(""),name,TEXT(""))))
return handle;
if (!endsInDLL) {
if ((handle = tryLoading(TEXT(""),name,TEXT(".dll"))))
return handle;
if ((handle = tryLoading(TEXT(""),name,TEXT("32.dll"))))
return handle;
}
if ((handle = tryLoading(imagePath,name,TEXT(""))))
return handle;
if (!endsInDLL) {
if ((handle = tryLoading(imagePath,name,TEXT(".dll"))))
return handle;
if ((handle = tryLoading(imagePath,name,TEXT("32.dll"))))
return handle;
}
return 0;
}

Expand Down Expand Up @@ -94,7 +105,6 @@ ioFindExternalFunctionIn(char *lookupName, void *moduleHandle)
}
#endif /* SPURVM */

sqInt ioFreeModule(void *moduleHandle)
{
return FreeLibrary((HANDLE) moduleHandle);
}
sqInt
ioFreeModule(void *moduleHandle)
{ return FreeLibrary((HANDLE) moduleHandle); }

0 comments on commit acaf284

Please sign in to comment.