Skip to content

Commit 4ee11af

Browse files
committed
[[ ExternalsApiV5 ]] Tweaks to support and code generation to make it work on Windows.
[[ ExternalsApiV5 ]] Added revtestexternal vcproj and tweaked source for Windows.
1 parent fe510cd commit 4ee11af

5 files changed

Lines changed: 294 additions & 9 deletions

File tree

lcidlc/src/InterfaceGenerate.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1015,11 +1015,20 @@ static bool InterfaceGenerateHandlers(InterfaceRef self, CoderRef p_coder)
10151015
////////////////////////////////////////////////////////////////////////////////
10161016

10171017
static const char *s_exports_template = "\
1018+
#ifndef __WINDOWS__\n\
1019+
#define DLLEXPORT\n\
10181020
extern \"C\" MCExternalInfo *MCExternalDescribe(void) __attribute__((visibility(\"default\")));\n\
10191021
extern \"C\" bool MCExternalInitialize(MCExternalInterface *) __attribute__((visibility(\"default\")));\n\
10201022
extern \"C\" void MCExternalFinalize(void) __attribute__((visibility(\"default\")));\n\
1023+
#else\n\
1024+
#define DLLEXPORT __declspec(dllexport)\n\
1025+
extern \"C\" MCExternalInfo DLLEXPORT *MCExternalDescribe(void);\n\
1026+
extern \"C\" bool DLLEXPORT MCExternalInitialize(MCExternalInterface *);\n\
1027+
extern \"C\" void DLLEXPORT MCExternalFinalize(void);\n\
1028+
#endif\n\
1029+
\
10211030
\n\
1022-
MCExternalInfo *MCExternalDescribe(void)\n\
1031+
MCExternalInfo DLLEXPORT *MCExternalDescribe(void)\n\
10231032
{\n\
10241033
static MCExternalInfo s_info;\n\
10251034
s_info . version = 1;\n\
@@ -1029,7 +1038,7 @@ MCExternalInfo *MCExternalDescribe(void)\n\
10291038
return &s_info;\n\
10301039
}\n\
10311040
\n\
1032-
bool MCExternalInitialize(MCExternalInterface *p_interface)\n\
1041+
bool DLLEXPORT MCExternalInitialize(MCExternalInterface *p_interface)\n\
10331042
{\n\
10341043
s_interface = p_interface;\n\
10351044
\n\
@@ -1052,7 +1061,7 @@ bool MCExternalInitialize(MCExternalInterface *p_interface)\n\
10521061
return true;\n\
10531062
}\n\
10541063
\n\
1055-
void MCExternalFinalize(void)\n\
1064+
void DLLEXPORT MCExternalFinalize(void)\n\
10561065
{\n\
10571066
#ifdef kMCExternalShutdown\n\
10581067
kMCExternalShutdown();\n\

lcidlc/src/Support.mm

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,9 @@
1414
You should have received a copy of the GNU General Public License
1515
along with LiveCode. If not see <http://www.gnu.org/licenses/>. */
1616

17-
#include <pthread.h>
1817
#include <stdarg.h>
1918
#include <stdio.h>
2019
#include <stdlib.h>
21-
#include <stdint.h>
2220
#include <string.h>
2321

2422
#ifdef __OBJC__
@@ -29,6 +27,10 @@
2927

3028
#ifdef __WINDOWS__
3129
#include <windows.h>
30+
typedef unsigned int uint32_t;
31+
#else
32+
#include <pthread.h>
33+
#include <stdint.h>
3234
#endif
3335

3436
////////////////////////////////////////////////////////////////////////////////
@@ -1901,7 +1903,7 @@ LCError LCWaitCreate(unsigned int p_options, LCWaitRef* r_wait)
19011903
static void LCWaitDestroy(LCWaitRef p_wait)
19021904
{
19031905
#ifdef __WINDOWS__
1904-
CloseHandle(t_wait -> lock);
1906+
CloseHandle(p_wait -> lock);
19051907
#else
19061908
pthread_mutex_destroy(&p_wait -> lock);
19071909
#endif
@@ -2012,7 +2014,7 @@ LCError LCWaitReset(LCWaitRef p_wait)
20122014
if (p_wait -> running)
20132015
return kLCErrorWaitRunning;
20142016

2015-
LCWaitLock(&p_wait -> lock);
2017+
LCWaitLock(p_wait);
20162018
p_wait -> broken = false;
20172019
LCWaitUnlock(p_wait);
20182020

Lines changed: 222 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,222 @@
1+
<?xml version="1.0" encoding="windows-1250"?>
2+
<VisualStudioProject
3+
ProjectType="Visual C++"
4+
Version="8.00"
5+
Name="revtestexternal"
6+
ProjectGUID="{2C0F855E-2EA0-4F46-9660-3C47D673B8B8}"
7+
RootNamespace="revtestexternal"
8+
Keyword="Win32Proj"
9+
>
10+
<Platforms>
11+
<Platform
12+
Name="Win32"
13+
/>
14+
</Platforms>
15+
<ToolFiles>
16+
</ToolFiles>
17+
<Configurations>
18+
<Configuration
19+
Name="Debug|Win32"
20+
ConfigurationType="2"
21+
InheritedPropertySheets="..\rules\Global.vsprops;..\rules\Debug.vsprops"
22+
CharacterSet="1"
23+
>
24+
<Tool
25+
Name="VCPreBuildEventTool"
26+
/>
27+
<Tool
28+
Name="VCCustomBuildTool"
29+
/>
30+
<Tool
31+
Name="VCXMLDataGeneratorTool"
32+
/>
33+
<Tool
34+
Name="VCWebServiceProxyGeneratorTool"
35+
/>
36+
<Tool
37+
Name="VCMIDLTool"
38+
/>
39+
<Tool
40+
Name="VCCLCompilerTool"
41+
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;REVTESTEXTERNAL_EXPORTS"
42+
MinimalRebuild="true"
43+
BasicRuntimeChecks="3"
44+
UsePrecompiledHeader="0"
45+
DebugInformationFormat="4"
46+
/>
47+
<Tool
48+
Name="VCManagedResourceCompilerTool"
49+
/>
50+
<Tool
51+
Name="VCResourceCompilerTool"
52+
/>
53+
<Tool
54+
Name="VCPreLinkEventTool"
55+
/>
56+
<Tool
57+
Name="VCLinkerTool"
58+
LinkIncremental="2"
59+
GenerateDebugInformation="true"
60+
SubSystem="2"
61+
TargetMachine="1"
62+
/>
63+
<Tool
64+
Name="VCALinkTool"
65+
/>
66+
<Tool
67+
Name="VCManifestTool"
68+
/>
69+
<Tool
70+
Name="VCXDCMakeTool"
71+
/>
72+
<Tool
73+
Name="VCBscMakeTool"
74+
/>
75+
<Tool
76+
Name="VCFxCopTool"
77+
/>
78+
<Tool
79+
Name="VCAppVerifierTool"
80+
/>
81+
<Tool
82+
Name="VCWebDeploymentTool"
83+
/>
84+
<Tool
85+
Name="VCPostBuildEventTool"
86+
/>
87+
</Configuration>
88+
<Configuration
89+
Name="Release|Win32"
90+
ConfigurationType="2"
91+
InheritedPropertySheets="..\rules\Global.vsprops;..\rules\Release.vsprops"
92+
CharacterSet="1"
93+
WholeProgramOptimization="1"
94+
>
95+
<Tool
96+
Name="VCPreBuildEventTool"
97+
/>
98+
<Tool
99+
Name="VCCustomBuildTool"
100+
/>
101+
<Tool
102+
Name="VCXMLDataGeneratorTool"
103+
/>
104+
<Tool
105+
Name="VCWebServiceProxyGeneratorTool"
106+
/>
107+
<Tool
108+
Name="VCMIDLTool"
109+
/>
110+
<Tool
111+
Name="VCCLCompilerTool"
112+
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;REVTESTEXTERNAL_EXPORTS"
113+
UsePrecompiledHeader="0"
114+
DebugInformationFormat="3"
115+
/>
116+
<Tool
117+
Name="VCManagedResourceCompilerTool"
118+
/>
119+
<Tool
120+
Name="VCResourceCompilerTool"
121+
/>
122+
<Tool
123+
Name="VCPreLinkEventTool"
124+
/>
125+
<Tool
126+
Name="VCLinkerTool"
127+
LinkIncremental="1"
128+
GenerateDebugInformation="true"
129+
SubSystem="2"
130+
TargetMachine="1"
131+
/>
132+
<Tool
133+
Name="VCALinkTool"
134+
/>
135+
<Tool
136+
Name="VCManifestTool"
137+
/>
138+
<Tool
139+
Name="VCXDCMakeTool"
140+
/>
141+
<Tool
142+
Name="VCBscMakeTool"
143+
/>
144+
<Tool
145+
Name="VCFxCopTool"
146+
/>
147+
<Tool
148+
Name="VCAppVerifierTool"
149+
/>
150+
<Tool
151+
Name="VCWebDeploymentTool"
152+
/>
153+
<Tool
154+
Name="VCPostBuildEventTool"
155+
/>
156+
</Configuration>
157+
</Configurations>
158+
<References>
159+
<ProjectReference
160+
ReferencedProjectIdentifier="{7321A225-FAC4-45D6-BAE4-B0E943102B7E}"
161+
RelativePathToProject=".\lcidlc\lcidlc.vcproj"
162+
/>
163+
</References>
164+
<Files>
165+
<Filter
166+
Name="Source Files"
167+
Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
168+
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
169+
>
170+
<File
171+
RelativePath=".\src\revtestexternal.cpp"
172+
>
173+
</File>
174+
</Filter>
175+
<Filter
176+
Name="Header Files"
177+
Filter="h;hpp;hxx;hm;inl;inc;xsd"
178+
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
179+
>
180+
</Filter>
181+
<Filter
182+
Name="Resource Files"
183+
Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav"
184+
UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"
185+
>
186+
</Filter>
187+
<Filter
188+
Name="Derived Source"
189+
>
190+
<File
191+
RelativePath=".\revtestexternal.lcidl.cpp"
192+
>
193+
</File>
194+
</Filter>
195+
<File
196+
RelativePath=".\revtestexternal.lcidl"
197+
>
198+
<FileConfiguration
199+
Name="Debug|Win32"
200+
>
201+
<Tool
202+
Name="VCCustomBuildTool"
203+
CommandLine="&quot;$(OutDir)\lcidlc.exe&quot; &quot;$(InputPath)&quot; &quot;$(InputPath).cpp&quot;"
204+
AdditionalDependencies="$(OutDir)lcidlc.exe"
205+
Outputs="$(InputPath).cpp"
206+
/>
207+
</FileConfiguration>
208+
<FileConfiguration
209+
Name="Release|Win32"
210+
>
211+
<Tool
212+
Name="VCCustomBuildTool"
213+
CommandLine="&quot;$(OutDir)\lcidlc.exe&quot; &quot;$(InputPath)&quot; &quot;$(InputPath).cpp&quot;"
214+
AdditionalDependencies="$(OutDir)lcidlc.exe"
215+
Outputs="$(InputPath).cpp"
216+
/>
217+
</FileConfiguration>
218+
</File>
219+
</Files>
220+
<Globals>
221+
</Globals>
222+
</VisualStudioProject>

revtestexternal/src/revtestexternal.cpp

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,59 @@
2222
////////////////////////////////////////////////////////////////////////////////
2323

2424
#if defined(__WINDOWS__)
25+
#include <windows.h>
26+
#include <process.h>
27+
28+
typedef void *(*windows_thread_function)(void *p_context);
29+
struct windows_thread_info
30+
{
31+
windows_thread_function m_function;
32+
void * m_context;
33+
};
34+
35+
static unsigned int __stdcall windows_thread_callback(void *p_context)
36+
{
37+
windows_thread_info *t_info = (windows_thread_info*)p_context;
38+
39+
unsigned int t_result;
40+
t_result = (unsigned int)t_info->m_function(t_info->m_context);
41+
42+
free(t_info);
43+
return t_result;
44+
}
45+
46+
void thread_sleep(unsigned int p_seconds)
47+
{
48+
Sleep(p_seconds * 1000);
49+
}
50+
51+
void *thread_begin(void *(*p_callback)(void *), void *p_context)
52+
{
53+
windows_thread_info *t_info = NULL;
54+
t_info = (windows_thread_info *)malloc(sizeof(windows_thread_info));
55+
56+
t_info -> m_function = p_callback;
57+
t_info -> m_context = p_context;
58+
59+
HANDLE t_thread;
60+
t_thread = (HANDLE)_beginthreadex(NULL, 0, windows_thread_callback, t_info, 0, NULL);
61+
62+
return (void *)t_thread;
63+
}
64+
65+
void *thread_finish(void *p_thread)
66+
{
67+
WaitForSingleObject((HANDLE)p_thread, INFINITE);
68+
CloseHandle((HANDLE)p_thread);
69+
return NULL;
70+
}
2571
#else
2672
#include <pthread.h>
2773
#include <unistd.h>
2874

2975
void thread_sleep(unsigned int p_seconds)
3076
{
31-
usleep(p_seconds * 1000);
77+
usleep(p_seconds * 1000 * 1000);
3278
}
3379

3480
void *thread_begin(void *(*p_callback)(void *), void *p_context)
@@ -52,7 +98,7 @@ void *thread_finish(void *p_thread)
5298

5399
static void *test_wait_callback(void *p_handle)
54100
{
55-
usleep(10 * 1000 * 1000);
101+
thread_sleep(10);
56102
LCWaitBreak((LCWaitRef)p_handle);
57103
return NULL;
58104
}

stage.sln

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "kernel-standalone", "engine
9191
EndProject
9292
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "lcidlc", "lcidlc\lcidlc.vcproj", "{7321A225-FAC4-45D6-BAE4-B0E943102B7E}"
9393
EndProject
94+
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "revtestexternal", "revtestexternal\revtestexternal.vcproj", "{2C0F855E-2EA0-4F46-9660-3C47D673B8B8}"
95+
EndProject
9496
Global
9597
GlobalSection(SolutionConfigurationPlatforms) = preSolution
9698
Debug|Win32 = Debug|Win32
@@ -241,6 +243,10 @@ Global
241243
{7321A225-FAC4-45D6-BAE4-B0E943102B7E}.Debug|Win32.Build.0 = Debug|Win32
242244
{7321A225-FAC4-45D6-BAE4-B0E943102B7E}.Release|Win32.ActiveCfg = Release|Win32
243245
{7321A225-FAC4-45D6-BAE4-B0E943102B7E}.Release|Win32.Build.0 = Release|Win32
246+
{2C0F855E-2EA0-4F46-9660-3C47D673B8B8}.Debug|Win32.ActiveCfg = Debug|Win32
247+
{2C0F855E-2EA0-4F46-9660-3C47D673B8B8}.Debug|Win32.Build.0 = Debug|Win32
248+
{2C0F855E-2EA0-4F46-9660-3C47D673B8B8}.Release|Win32.ActiveCfg = Release|Win32
249+
{2C0F855E-2EA0-4F46-9660-3C47D673B8B8}.Release|Win32.Build.0 = Release|Win32
244250
EndGlobalSection
245251
GlobalSection(SolutionProperties) = preSolution
246252
HideSolutionNode = FALSE

0 commit comments

Comments
 (0)