FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
livecode/libfoundation/src/foundation-core.cpp at develop · livecode/livecode · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
This repository was archived by the owner on Aug 31, 2021. It is now read-only.
livecode
/
livecode
Public archive
Notifications
You must be signed in to change notification settings
Fork
223
Star
517
Code
Pull requests
189
Actions
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Security and quality
Insights
Expand file tree
Breadcrumbs
livecode
/
libfoundation
/
src
/
foundation-core.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
362 lines (297 loc) · 7.55 KB
Breadcrumbs
livecode
/
libfoundation
/
src
/
foundation-core.cpp
Copy path
File metadata and controls
362 lines (297 loc) · 7.55 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
/*
Copyright (C) 2003-2015 LiveCode Ltd.
This file is part of LiveCode.
LiveCode is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License v3 as published by the Free
Software Foundation.
LiveCode is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with LiveCode. If not see <http://www.gnu.org/licenses/>.
*/
#
include
<
foundation.h
>
#
include
<
foundation-auto.h
>
#
include
<
foundation-stdlib.h
>
#
include
"
foundation-private.h
"
#
include
"
foundation-hash.h
"
#
include
"
foundation-string-hash.h
"
#
if
defined(__WINDOWS__)
#
include
<
Windows.h
>
#
endif
//
//////////////////////////////////////////////////////////////////////////////
#
ifdef
__LINUX__
const
char
*__MCSysCharset;
#
endif
//
//////////////////////////////////////////////////////////////////////////////
bool
MCInitialize
(
void
)
{
if
(!
__MCUnicodeInitialize
())
return
false
;
if
(!
__MCValueInitialize
())
return
false
;
if
(!
__MCStringInitialize
())
return
false
;
if
(!
__MCNameInitialize
())
return
false
;
if
(!
__MCErrorInitialize
())
return
false
;
if
(!
__MCTypeInfoInitialize
())
return
false
;
if
(!
__MCForeignValueInitialize
())
return
false
;
if
(!
__MCNumberInitialize
())
return
false
;
if
(!
__MCArrayInitialize
())
return
false
;
if
(!
__MCListInitialize
())
return
false
;
if
(!
__MCSetInitialize
())
return
false
;
if
(!
__MCDataInitialize
())
return
false
;
if
(!
__MCRecordInitialize
())
return
false
;
if
(!
__MCLocaleInitialize
())
return
false
;
if
(!
__MCProperListInitialize
())
return
false
;
if
(!
__MCStreamInitialize
())
return
false
;
if
(!
__MCJavaInitialize
())
return
false
;
if
(!
__MCObjcInitialize
())
return
false
;
return
true
;
}
void
MCFinalize
(
void
)
{
__MCStreamFinalize
();
__MCProperListFinalize
();
__MCLocaleFinalize
();
__MCRecordFinalize
();
__MCDataFinalize
();
__MCSetFinalize
();
__MCListFinalize
();
__MCArrayFinalize
();
__MCNumberFinalize
();
__MCForeignValueFinalize
();
__MCTypeInfoFinalize
();
__MCErrorFinalize
();
__MCNameFinalize
();
__MCStringFinalize
();
__MCUnicodeFinalize
();
__MCJavaFinalize
();
__MCObjcFinalize
();
//
Finalize values last
__MCValueFinalize
();
}
//
//////////////////////////////////////////////////////////////////////////////
MC_DLLEXPORT_DEF
bool
MCMemoryAllocate
(
size_t
p_size,
void
*& r_block)
{
void
*t_block;
t_block =
malloc
(p_size !=
0
? p_size :
4
);
if
(t_block != nil)
{
r_block = t_block;
return
true
;
}
return
MCErrorThrowOutOfMemory
();
}
MC_DLLEXPORT_DEF
bool
MCMemoryAllocateCopy
(
const
void
*p_block,
size_t
p_block_size,
void
*& r_block)
{
if
(
MCMemoryAllocate
(p_block_size, r_block))
{
MCMemoryCopy
(r_block, p_block, p_block_size);
return
true
;
}
return
MCErrorThrowOutOfMemory
();
}
MC_DLLEXPORT_DEF
bool
MCMemoryReallocate
(
void
*p_block,
size_t
p_new_size,
void
*& r_new_block)
{
void
*t_new_block;
t_new_block =
realloc
(p_block, p_new_size !=
0
? p_new_size :
4
);
if
(t_new_block != nil)
{
r_new_block = t_new_block;
return
true
;
}
return
MCErrorThrowOutOfMemory
();
}
MC_DLLEXPORT_DEF
void
MCMemoryDeallocate
(
void
*p_block)
{
free
(p_block);
}
//
////////
MC_DLLEXPORT_DEF
bool
MCMemoryNew
(
size_t
p_size,
void
*& r_record)
{
if
(
MCMemoryAllocate
(p_size, r_record))
{
MCMemoryClear
(r_record, p_size);
return
true
;
}
return
false
;
}
MC_DLLEXPORT_DEF
void
MCMemoryDelete
(
void
*p_record)
{
MCMemoryDeallocate
(p_record);
}
//
////////
bool
MCMemoryNewArray
(
uindex_t
p_count,
size_t
p_size,
void
*& r_array)
{
if
(
MCMemoryAllocate
(p_count * p_size, r_array))
{
MCMemoryClear
(r_array, p_count * p_size);
return
true
;
}
return
false
;
}
bool
MCMemoryNewArray
(
uindex_t
p_count,
size_t
p_size,
void
*& r_array,
uindex_t
& r_count)
{
if
(
MCMemoryAllocate
(p_count * p_size, r_array))
{
MCMemoryClear
(r_array, p_count * p_size);
r_count = p_count;
return
true
;
}
return
false
;
}
bool
MCMemoryResizeArray
(
uindex_t
p_new_count,
size_t
p_size,
void
*& x_array,
uindex_t
& x_count)
{
if
(
MCMemoryReallocate
(x_array, p_new_count * p_size, x_array))
{
if
(p_new_count > x_count)
MCMemoryClear
(
static_cast
<
char
*>(x_array) + x_count * p_size, (p_new_count - x_count) * p_size);
x_count = p_new_count;
return
true
;
}
return
false
;
}
void
MCMemoryDeleteArray
(
void
*p_array)
{
MCMemoryDeallocate
(p_array);
}
//
//////////////////////////////////////////////////////////////////////////////
/*
Securely clear the memory located at dst, using volatile to try to
* ensure that the compiler doesn't optimise it out.
*/
MC_DLLEXPORT
void
MCMemoryClearSecure
(
byte_t
* dst,
size_t
size)
{
#
if
defined(__WINDOWS__)
SecureZeroMemory
(dst, size);
#
else
MCMemoryClear
(dst, size);
/*
Add a barrier to prevent the compiler from optimizing the above
* MCMemoryClear() call away. Without this, both clang and GCC
* will optimise out the memory clear.
*/
__asm__
__volatile__
(
"
"
: :
"
r
"
(dst) :
"
memory
"
);
#
endif
}
//
//////////////////////////////////////////////////////////////////////////////
MC_DLLEXPORT_DEF
hash_t
MCHashBool
(
bool
b)
{
return
hash_t
(b);
}
MC_DLLEXPORT_DEF
hash_t
MCHashInteger
(
integer_t
i)
{
return
MCHashInt
(i);
}
MC_DLLEXPORT_DEF
hash_t
MCHashUInteger
(
uinteger_t
i)
{
return
MCHashInt
(i);
}
MC_DLLEXPORT_DEF
hash_t
MCHashSize
(
ssize_t
i)
{
return
MCHashInt
(i);
}
MC_DLLEXPORT_DEF
hash_t
MCHashUSize
(
size_t
i)
{
return
MCHashInt
(i);
}
MC_DLLEXPORT_DEF
hash_t
MCHashInt64
(
int64_t
i)
{
return
MCHashInt
(i);
}
hash_t
MCHashUInt64
(
uint64_t
i)
{
return
MCHashInt
(i);
}
MC_DLLEXPORT_DEF
hash_t
MCHashPointer
(
const
void
*p)
{
return
MCHashInt
(
reinterpret_cast
<
uintptr_t
>(p));
}
MC_DLLEXPORT_DEF
hash_t
MCHashDouble
(
double
d)
{
return
MCHashFloatingPoint
(d);
}
MC_DLLEXPORT_DEF
hash_t
MCHashBytes
(
const
void
*p_bytes,
size_t
length)
{
MCHashBytesContext t_context;
t_context.
consume
(
reinterpret_cast
<
const
byte_t
*>(p_bytes), length);
return
t_context;
}
MC_DLLEXPORT_DEF
hash_t
MCHashBytes
(MCSpan<
const
byte_t
> p_bytes)
{
return
MCHashBytes
(p_bytes.
data
(), p_bytes.
size
());
}
MC_DLLEXPORT_DEF
hash_t
MCHashBytesStream
(
hash_t
p_start,
const
void
*p_bytes,
size_t
length)
{
MCHashBytesContext
t_context
(p_start);
t_context.
consume
(
reinterpret_cast
<
const
byte_t
*>(p_bytes), length);
return
t_context;
}
MC_DLLEXPORT_DEF
hash_t
MCHashBytesStream
(
hash_t
p_start, MCSpan<
const
byte_t
> p_bytes)
{
return
MCHashBytesStream
(p_start, p_bytes.
data
(), p_bytes.
size
());
}
template
<
typename
CodeUnit>
static
hash_t
hash_chars
(CodeUnit *p_chars,
size_t
char_count)
{
MCHashCharsContext t_context;
while
(char_count-- >
0
) t_context.
consume
(*p_chars++);
return
t_context;
}
MC_DLLEXPORT_DEF
hash_t
MCHashNativeChars
(
const
char_t
*chars,
size_t
char_count)
{
return
hash_chars
(chars, char_count);
}
MC_DLLEXPORT_DEF
hash_t
MCHashNativeChars
(MCSpan<
const
char_t
> p_chars)
{
return
hash_chars
(p_chars.
data
(), p_chars.
size
());
}
MC_DLLEXPORT
hash_t
MCHashChars
(
const
unichar_t
*chars,
size_t
char_count)
{
return
hash_chars
(chars, char_count);
}
MC_DLLEXPORT_DEF
hash_t
MCHashChars
(MCSpan<
const
unichar_t
> p_chars)
{
return
hash_chars
(p_chars.
data
(), p_chars.
size
());
}
//
//////////////////////////////////////////////////////////////////////////////
Back
|
FazBrowse Home
|
New Git URL