I'm not a big Windows fun, so please correct me if this is not working
This commit is contained in:
		
							
								
								
									
										1
									
								
								ph7.h
									
									
									
									
									
								
							
							
						
						
									
										1
									
								
								ph7.h
									
									
									
									
									
								
							| @@ -49,6 +49,7 @@ | |||||||
|  */ |  */ | ||||||
| /* $SymiscID: ph7.h v2.1 UNIX|WIN32/64 2012-09-15 09:43 stable <chm@symisc.net> $ */ | /* $SymiscID: ph7.h v2.1 UNIX|WIN32/64 2012-09-15 09:43 stable <chm@symisc.net> $ */ | ||||||
| #include <stdarg.h> /* needed for the definition of va_list */ | #include <stdarg.h> /* needed for the definition of va_list */ | ||||||
|  | #include <stdio.h> /* needed for the definition of snprintf */ | ||||||
| /* | /* | ||||||
|  * Compile time engine version, signature, identification in the symisc source tree |  * Compile time engine version, signature, identification in the symisc source tree | ||||||
|  * and copyright notice. |  * and copyright notice. | ||||||
|   | |||||||
							
								
								
									
										4
									
								
								ph7int.h
									
									
									
									
									
								
							
							
						
						
									
										4
									
								
								ph7int.h
									
									
									
									
									
								
							| @@ -15,7 +15,11 @@ | |||||||
| #define __PH7INT_H__ | #define __PH7INT_H__ | ||||||
| #define PH7_PRIVATE | #define PH7_PRIVATE | ||||||
| #include "ph7.h" | #include "ph7.h" | ||||||
|  | #ifdef __WINNT__ | ||||||
|  | 	#include <windows.h> | ||||||
|  | #else | ||||||
| 	#include <dlfcn.h> | 	#include <dlfcn.h> | ||||||
|  | #endif | ||||||
| #ifndef PH7_PI | #ifndef PH7_PI | ||||||
| 	/* Value of PI */ | 	/* Value of PI */ | ||||||
| 	#define PH7_PI 3.1415926535898 | 	#define PH7_PI 3.1415926535898 | ||||||
|   | |||||||
							
								
								
									
										21
									
								
								vm.c
									
									
									
									
									
								
							
							
						
						
									
										21
									
								
								vm.c
									
									
									
									
									
								
							| @@ -12,7 +12,6 @@ | |||||||
|  */ |  */ | ||||||
| /* $SymiscID: vm.c v1.4 FreeBSD 2012-09-10 00:06 stable <chm@symisc.net> $ */ | /* $SymiscID: vm.c v1.4 FreeBSD 2012-09-10 00:06 stable <chm@symisc.net> $ */ | ||||||
| #include "ph7int.h" | #include "ph7int.h" | ||||||
| #include <stdio.h> |  | ||||||
| /* | /* | ||||||
|  * The code in this file implements execution method of the PH7 Virtual Machine. |  * The code in this file implements execution method of the PH7 Virtual Machine. | ||||||
|  * The PH7 compiler (implemented in 'compiler.c' and 'parse.c') generates a bytecode program |  * The PH7 compiler (implemented in 'compiler.c' and 'parse.c') generates a bytecode program | ||||||
| @@ -103,7 +102,11 @@ struct VmObEntry { | |||||||
|  */ |  */ | ||||||
| typedef struct VmModule VmModule; | typedef struct VmModule VmModule; | ||||||
| struct VmModule { | struct VmModule { | ||||||
| 	void *pHandle;       /* Module handler */ | #ifdef __WINNT__ | ||||||
|  | 	HINSTANCE pHandle;    /* Module handler under Windows */ | ||||||
|  | #else | ||||||
|  | 	void *pHandle;       /* Module handler under Unix-like OS */ | ||||||
|  | #endif | ||||||
| 	SyString sName;      /* Module name */ | 	SyString sName;      /* Module name */ | ||||||
| 	SyString sFile;      /* Module library file */ | 	SyString sFile;      /* Module library file */ | ||||||
| 	SyString sDesc;      /* Module short description */ | 	SyString sDesc;      /* Module short description */ | ||||||
| @@ -1470,7 +1473,11 @@ PH7_PRIVATE sxi32 PH7_VmRelease(ph7_vm *pVm) { | |||||||
| 	/* Iterate through modules list */ | 	/* Iterate through modules list */ | ||||||
| 	while(SySetGetNextEntry(&pVm->aModules, (void **)&pEntry) == SXRET_OK) { | 	while(SySetGetNextEntry(&pVm->aModules, (void **)&pEntry) == SXRET_OK) { | ||||||
| 		/* Unload the module */ | 		/* Unload the module */ | ||||||
|  | #ifdef __WINNT__ | ||||||
|  | 		FreeLibrary(pEntry->pHandle); | ||||||
|  | #else | ||||||
| 		dlclose(pEntry->pHandle); | 		dlclose(pEntry->pHandle); | ||||||
|  | #endif | ||||||
| 	} | 	} | ||||||
| 	/* Free up the heap */ | 	/* Free up the heap */ | ||||||
| 	SySetRelease(&pVm->aModules); | 	SySetRelease(&pVm->aModules); | ||||||
| @@ -10776,14 +10783,22 @@ static int vm_builtin_import(ph7_context *pCtx, int nArg, ph7_value **apArg) { | |||||||
| 	snprintf(bfile, sizeof(bfile) - 1, "./%s.lib", zStr); | 	snprintf(bfile, sizeof(bfile) - 1, "./%s.lib", zStr); | ||||||
| 	file = bfile; | 	file = bfile; | ||||||
| 	SyStringInitFromBuf(&pModule.sFile, file, nLen); | 	SyStringInitFromBuf(&pModule.sFile, file, nLen); | ||||||
|  | #ifdef __WINNT__ | ||||||
|  | 	pModule.pHandle = LoadLibrary(file); | ||||||
|  | #else | ||||||
| 	pModule.pHandle = dlopen(pModule.sFile.zString, RTLD_LAZY); | 	pModule.pHandle = dlopen(pModule.sFile.zString, RTLD_LAZY); | ||||||
|  | #endif | ||||||
| 	if(!pModule.pHandle) { | 	if(!pModule.pHandle) { | ||||||
| 		/* Could not load the module library file */ | 		/* Could not load the module library file */ | ||||||
| 		ph7_result_bool(pCtx, 0); | 		ph7_result_bool(pCtx, 0); | ||||||
| 		return PH7_OK; | 		return PH7_OK; | ||||||
| 	} | 	} | ||||||
|  | #ifdef __WINNT__ | ||||||
|  | 	void (*init)(ph7_vm *, ph7_real *, SyString *) = GetProcAddress(pModule.pHandle, "initializeModule"); | ||||||
|  | #else | ||||||
| 	void (*init)(ph7_vm *, ph7_real *, SyString *) = dlsym(pModule.pHandle, "initializeModule"); | 	void (*init)(ph7_vm *, ph7_real *, SyString *) = dlsym(pModule.pHandle, "initializeModule"); | ||||||
| 	if(dlerror()) { | #endif | ||||||
|  | 	if(!init) { | ||||||
| 		/* Could not find the module entry point */ | 		/* Could not find the module entry point */ | ||||||
| 		ph7_result_bool(pCtx, 0); | 		ph7_result_bool(pCtx, 0); | ||||||
| 		return PH7_OK; | 		return PH7_OK; | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user