Skip to content

Commit 55897d6

Browse files
committed
Reset memory manager on free; Makefile, submodule.
1 parent 300fc3f commit 55897d6

File tree

5 files changed

+178
-13
lines changed

5 files changed

+178
-13
lines changed

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "plugin/source/Simba"]
2+
path = plugin/source/Simba
3+
url = git://github.com/MerlijnWajer/Simba.git

plugin/source/Makefile

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
# Makefile for SPS, made by moparisthebest modified by Wizzup
2+
#
3+
# Currently written for and tested to run only on Linux i386 and x86_64.
4+
# Currently supports cross compilation to fpc targets i386-linux x86_64-linux i386-win32 x86_64-win64
5+
# Obviously your system must have the needed binaries and libraries to cross-compile for that to work,
6+
# but this will of course compile a native binary for your system only, if you wish.
7+
8+
.PHONY: default build rebuild unknown recursive_build clean i386-linux x86_64-linux i386-win32 x86_64-win64 all
9+
10+
# Set these
11+
ifdef LAZARUS_PATH
12+
lazaruspath := $(LAZARUS_PATH)
13+
else
14+
lazaruspath := /usr/lib/lazarus/0.9.28.2
15+
endif
16+
17+
# Shouldn't need to touch below here, unless you add a unit or something...
18+
19+
# let's detect what linux platform we are running on, so if we run build or the default target
20+
# we by default build the correct executable for our architecture...
21+
# (cross-compiling is near-impossible on windows, so this makefile doesn't need to try and support it)
22+
# as Simba supports more OSs (BSD, OSX etc) we can add support for cross compilation here too
23+
uname_S := $(shell sh -c 'uname -s 2>/dev/null || echo not')
24+
ifeq ($(uname_S),Linux)
25+
uname_M := $(shell sh -c 'uname -m 2>/dev/null || echo not')
26+
ifeq ($(uname_M),x86_64)
27+
our_target := x86_64-linux
28+
else ifeq ($(uname_M),i386)
29+
our_target := i386-linux
30+
else ifeq ($(uname_M),i486)
31+
our_target := i386-linux
32+
else ifeq ($(uname_M),i586)
33+
our_target := i386-linux
34+
else ifeq ($(uname_M),i686)
35+
our_target := i386-linux
36+
else
37+
our_target := unknown
38+
endif
39+
else
40+
our_target := unknown
41+
endif
42+
43+
CC := fpc
44+
build := $(CC)
45+
46+
# -Xd doesn't seem to cause problems when not cross-compiling, and is needed when cross-compiling, so I'm leaving it here
47+
# -Xg = External debug file (Simba.dbg)
48+
common_flags := -Xd -MObjFPC -Scgi -O2 -OoREGVAR -gl -vewnhi -l -Fu. -dLCL -Xg -fPIC
49+
units := -FuSimba/Units/MMLCore -FuSimba/Units/Misc/DCPCrypt/ -FuSimba/Units/Linux/
50+
includes := -FiSimba/Projects/Simba
51+
#units := -Fu../../Units/MMLCore/ -Fu../../Units/MMLAddon/ -Fu../../Units/MMLAddon/PSInc/ -Fu../../Units/PascalScript/ -Fu../../Units/Misc/ -Fu../../Units/Linux/ -Fu../../Units/Synapse/ -Fu../../Units/RUTIS/ -Fu../../Units/lape -Fu../../Units/Misc/DCPCrypt -Fu../../Units/Misc/DCPCrypt/Ciphers -Fu../../Units/Misc/DCPCrypt/Hashes
52+
53+
binary := sps.$(platform)
54+
# windows wants executables to end in .exe
55+
ifeq ($(widgetset),win32)
56+
binary_extension := .dll
57+
endif
58+
ifeq ($(widgetset),gtk)
59+
binary_extension := .so
60+
endif
61+
lclplatpath := $(lazaruspath)/lcl/units/$(platform)/
62+
lazarusunits := -Fu$(lazaruspath)/components/synedit/units/$(platform)/ -Fu$(lazaruspath)ideintf/units/$(platform)/ -Fu$(lclplatpath) -Fu$(lclplatpath)$(widgetset)/ -Fu$(lazaruspath)/packager/units/$(platform)/ -Fu$(lazaruspath)/components/mouseandkeyinput/
63+
64+
default: build
65+
66+
build: $(our_target)
67+
68+
rebuild: clean build
69+
70+
recursive_build: $(binary)$(binary_extension)
71+
72+
unknown:
73+
@echo Unable to auto-detect the OS and architecture you wish to build for, please specify target manually.
74+
75+
clean:
76+
# TODO CLEAN
77+
rm *.so rm *.dll
78+
79+
$(binary)$(binary_extension):
80+
$(CC) $(common_flags) $(platform_flags) -dLCL$(widgetset) $(units) $(includes) $(lazarusunits) -o$(binary)$(binary_extension) sps.lpr
81+
strip $(binary)$(binary_extension)
82+
83+
i386-linux:
84+
$(MAKE) recursive_build platform="i386-linux" widgetset="gtk2" platform_flags="-Tlinux -Pi386 -dUseCThreads"
85+
mv Simba.dbg Simba.i386-linux.dbg
86+
87+
x86_64-linux:
88+
$(MAKE) recursive_build platform="x86_64-linux" widgetset="gtk2" platform_flags="-Tlinux -Px86_64 -dUseCThreads"
89+
mv Simba.dbg Simba.x86_64-linux.dbg
90+
91+
i386-win32:
92+
$(MAKE) recursive_build platform="i386-win32" widgetset="win32" platform_flags="-Twin32 -Pi386"
93+
# Windows already names the .dbg properly...
94+
95+
x86_64-win64:
96+
$(MAKE) recursive_build platform="x86_64-win64" widgetset="win32" platform_flags="-Twin64 -Px86_64"
97+
# Windows already names the .dbg properly...
98+
99+
all: i386-linux x86_64-linux i386-win32 x86_64-win64

plugin/source/Simba

Submodule Simba added at 5fef629

plugin/source/sps.lpi

Lines changed: 62 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
<MainUnit Value="0"/>
1212
<ResourceType Value="res"/>
1313
<UseXPManifest Value="True"/>
14-
<Icon Value="0"/>
1514
<ActiveWindowIndexAtStart Value="0"/>
1615
</General>
1716
<i18n>
@@ -33,16 +32,16 @@
3332
<FormatVersion Value="1"/>
3433
</local>
3534
</RunParams>
36-
<Units Count="9">
35+
<Units Count="12">
3736
<Unit0>
3837
<Filename Value="sps.lpr"/>
3938
<IsPartOfProject Value="True"/>
4039
<UnitName Value="sps"/>
4140
<IsVisibleTab Value="True"/>
4241
<EditorIndex Value="0"/>
4342
<WindowIndex Value="0"/>
44-
<TopLine Value="25"/>
45-
<CursorPos X="8" Y="27"/>
43+
<TopLine Value="1"/>
44+
<CursorPos X="36" Y="14"/>
4645
<UsageCount Value="21"/>
4746
<Loaded Value="True"/>
4847
</Unit0>
@@ -82,12 +81,10 @@
8281
<Filename Value="C:\Simba Source\Units\MMLCore\bitmaps.pas"/>
8382
<IsPartOfProject Value="True"/>
8483
<UnitName Value="bitmaps"/>
85-
<EditorIndex Value="2"/>
8684
<WindowIndex Value="0"/>
8785
<TopLine Value="50"/>
8886
<CursorPos X="20" Y="136"/>
8987
<UsageCount Value="21"/>
90-
<Loaded Value="True"/>
9188
</Unit5>
9289
<Unit6>
9390
<Filename Value="C:\Simba Source\Units\MMLCore\mufasatypes.pas"/>
@@ -110,15 +107,39 @@
110107
<Filename Value="C:\Simba Source\Units\MMLCore\colour_conv.pas"/>
111108
<IsPartOfProject Value="True"/>
112109
<UnitName Value="colour_conv"/>
113-
<EditorIndex Value="1"/>
114110
<WindowIndex Value="0"/>
115111
<TopLine Value="34"/>
116112
<CursorPos X="1" Y="1"/>
117113
<UsageCount Value="20"/>
118-
<Loaded Value="True"/>
119114
</Unit8>
115+
<Unit9>
116+
<Filename Value="..\..\..\..\lazarus\lcl\fileutil.pas"/>
117+
<UnitName Value="FileUtil"/>
118+
<WindowIndex Value="0"/>
119+
<TopLine Value="1"/>
120+
<CursorPos X="45" Y="29"/>
121+
<UsageCount Value="10"/>
122+
</Unit9>
123+
<Unit10>
124+
<Filename Value="Simba\Units\MMLCore\os_linux.pas"/>
125+
<UnitName Value="os_linux"/>
126+
<WindowIndex Value="0"/>
127+
<TopLine Value="24"/>
128+
<CursorPos X="76" Y="45"/>
129+
<UsageCount Value="10"/>
130+
</Unit10>
131+
<Unit11>
132+
<Filename Value="Simba\Units\MMLCore\mufasabase.pas"/>
133+
<UnitName Value="mufasabase"/>
134+
<EditorIndex Value="1"/>
135+
<WindowIndex Value="0"/>
136+
<TopLine Value="13"/>
137+
<CursorPos X="81" Y="45"/>
138+
<UsageCount Value="10"/>
139+
<Loaded Value="True"/>
140+
</Unit11>
120141
</Units>
121-
<JumpHistory Count="2" HistoryIndex="1">
142+
<JumpHistory Count="9" HistoryIndex="8">
122143
<Position1>
123144
<Filename Value="sps.lpr"/>
124145
<Caret Line="104" Column="7" TopLine="84"/>
@@ -127,6 +148,34 @@
127148
<Filename Value="sps.lpr"/>
128149
<Caret Line="29" Column="23" TopLine="27"/>
129150
</Position2>
151+
<Position3>
152+
<Filename Value="sps.lpr"/>
153+
<Caret Line="38" Column="55" TopLine="25"/>
154+
</Position3>
155+
<Position4>
156+
<Filename Value="sps.lpr"/>
157+
<Caret Line="28" Column="61" TopLine="1"/>
158+
</Position4>
159+
<Position5>
160+
<Filename Value="sps.lpr"/>
161+
<Caret Line="6" Column="27" TopLine="1"/>
162+
</Position5>
163+
<Position6>
164+
<Filename Value="sps.lpr"/>
165+
<Caret Line="19" Column="73" TopLine="1"/>
166+
</Position6>
167+
<Position7>
168+
<Filename Value="sps.lpr"/>
169+
<Caret Line="7" Column="19" TopLine="1"/>
170+
</Position7>
171+
<Position8>
172+
<Filename Value="Simba\Units\MMLCore\mufasabase.pas"/>
173+
<Caret Line="1" Column="1" TopLine="1"/>
174+
</Position8>
175+
<Position9>
176+
<Filename Value="Simba\Units\MMLCore\mufasabase.pas"/>
177+
<Caret Line="32" Column="55" TopLine="13"/>
178+
</Position9>
130179
</JumpHistory>
131180
</ProjectOptions>
132181
<CompilerOptions>
@@ -136,8 +185,8 @@
136185
<Filename Value="sps"/>
137186
</Target>
138187
<SearchPaths>
139-
<IncludeFiles Value="$(ProjOutDir)"/>
140-
<OtherUnitFiles Value="$(LazarusDir)\lcl\units\$(TargetCPU)-$(TargetOS);$(LazarusDir)\lcl\units\$(TargetCPU)-$(TargetOS)\$(LCLWidgetType);C:\Lazarus\components\mouseandkeyinput\;C:\Simba Source\Units\MMLCore\;C:\Simba Source\Units\Misc\DCPCrypt\"/>
188+
<IncludeFiles Value="$(ProjOutDir);Simba\Projects\Simba"/>
189+
<OtherUnitFiles Value="$(LazarusDir)\lcl\units\$(TargetCPU)-$(TargetOS);$(LazarusDir)\lcl\units\$(TargetCPU)-$(TargetOS)\$(LCLWidgetType);$(LazarusDir)\components\mouseandkeyinput;Simba\Units\MMLCore;Simba\Units\Misc\DCPCrypt;Simba\Units\Linux"/>
141190
<UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
142191
</SearchPaths>
143192
<Linking>
@@ -154,6 +203,7 @@
154203
<CompilerMessages>
155204
<UseMsgFile Value="True"/>
156205
</CompilerMessages>
206+
<CustomOptions Value="-fPIC"/>
157207
<CompilerPath Value="$(CompPath)"/>
158208
</Other>
159209
</CompilerOptions>
@@ -170,4 +220,4 @@
170220
</Item3>
171221
</Exceptions>
172222
</Debugging>
173-
</CONFIG>
223+
</CONFIG>

plugin/source/sps.lpr

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
type
1111
T3DIntegerArray = array of T2DIntegerArray;
1212

13+
var
14+
OldMemoryManager: TMemoryMAnager;
15+
1316
(**
1417
* Retruns true if the color boxes (B1 and B2) match within the tolerance (tol).
1518
*)
@@ -149,9 +152,15 @@ function SPS_FindMapInMap(out fx, fy: integer; LargeMap, SmallMap: T3DIntegerArr
149152

150153
procedure SetPluginMemManager(MemMgr : TMemoryManager); stdcall; export;
151154
begin
155+
GetMemoryManager(OldMemoryManager);
152156
SetMemoryManager(MemMgr);
153157
end;
154158

159+
procedure OnDetach; stdcall; export;
160+
begin
161+
SetMemoryManager(OldMemoryManager);
162+
end;
163+
155164
function GetTypeCount(): Integer; stdcall; export;
156165
begin
157166
Result := 1;
@@ -223,7 +232,10 @@ function GetFunctionInfo(x: Integer; var ProcAddr: Pointer; var ProcDef: PChar):
223232
exports GetFunctionCount;
224233
exports GetFunctionInfo;
225234
exports GetFunctionCallingConv;
235+
exports OnDetach;
236+
237+
{$R *.res}
226238

227239
begin
228240
end.
229-
241+

0 commit comments

Comments
 (0)