• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

polserver / polserver / 21541532363

31 Jan 2026 08:14AM UTC coverage: 60.532% (+0.03%) from 60.507%
21541532363

push

github

web-flow
Tidy modernize for loops (#862)

* trigger loop convert

* Automated clang-tidy change: modernize-loop-convert

* fixed refactor

* Automated clang-tidy change: modernize-loop-convert

* compile

* first look through

* fixes and start to use a few ranges

* revert autogenerated file

* compilation fix

* second pass

* renamed loop variable

---------

Co-authored-by: Clang Tidy <clang-tidy@users.noreply.github.com>

164 of 447 new or added lines in 61 files covered. (36.69%)

6 existing lines in 5 files now uncovered.

44377 of 73312 relevant lines covered (60.53%)

499857.83 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

31.4
/pol-core/pol/syshookscript.cpp
1
/** @file
2
 *
3
 * @par History
4
 * - 2009/12/10 Turley:   Method/Syshook definitions now supports :pkg: format
5
 */
6

7

8
#include "syshookscript.h"
9

10
#include <exception>
11
#include <stddef.h>
12
#include <string>
13

14
#include "../bscript/berror.h"
15
#include "../bscript/eprog.h"
16
#include "../bscript/executor.h"
17
#include "../clib/clib.h"
18
#include "../clib/logfacility.h"
19
#include "scrsched.h"
20

21

22
namespace Pol::Core
23
{
24
using namespace Bscript;
25
ExportScript::ExportScript( const Plib::Package* pkg, std::string scriptname )
9✔
26
{
27
  if ( scriptname.find( ".ecl" ) == std::string::npos )
9✔
28
    scriptname += ".ecl";
9✔
29
  sd.config( scriptname, pkg, "", true );
9✔
30
}
9✔
31

32
ExportScript::ExportScript( const ScriptDef& isd ) : sd( isd ) {}
3✔
33

34
bool ExportScript::Initialize()
12✔
35
{
36
  BObject ob( run_executor_to_completion( uoexec, sd ) );
12✔
37
  return ob.isTrue();
24✔
38
}
12✔
39

40
const std::string& ExportScript::scriptname() const
15✔
41
{
42
  return sd.name();
15✔
43
}
44

45
bool ExportScript::FindExportedFunction( const std::string& name, unsigned args,
18✔
46
                                         unsigned& PC ) const
47
{
48
  const EScriptProgram* prog = uoexec.prog();
18✔
49
  for ( const auto& exportedfunc : prog->exported_functions )
63✔
50
  {
51
    if ( stricmp( exportedfunc.name.c_str(), name.c_str() ) == 0 )
63✔
52
    {
53
      if ( args != exportedfunc.nargs )
18✔
54
      {
55
        INFO_PRINTLN( "Exported function {} in script {} takes {} parameters, expected {}", name,
×
NEW
56
                      scriptname(), exportedfunc.nargs, args );
×
57
        return false;
18✔
58
      }
59
      PC = exportedfunc.PC;
18✔
60
      return true;
18✔
61
    }
62
  }
63
  return false;
×
64
}
65

66
bool ExportScript::FindExportedFunction( const char* name, unsigned args, unsigned& PC ) const
7✔
67
{
68
  const EScriptProgram* prog = uoexec.prog();
7✔
69
  for ( const auto& exportedfunc : prog->exported_functions )
11✔
70
  {
71
    if ( stricmp( exportedfunc.name.c_str(), name ) == 0 )
11✔
72
    {
73
      if ( args != exportedfunc.nargs )
7✔
74
      {
75
        INFO_PRINTLN( "Exported function {} in script {} takes {} parameters, expected {}", name,
×
NEW
76
                      scriptname(), exportedfunc.nargs, args );
×
77
        return false;
7✔
78
      }
79
      PC = exportedfunc.PC;
7✔
80
      return true;
7✔
81
    }
82
  }
83
  return false;
×
84
}
85

86
bool ExportScript::call( unsigned PC, BObjectImp* p0, BObjectImp* p1, BObjectImp* p2,
×
87
                         BObjectImp* p3 )
88
{
89
  try
90
  {
91
    // build backup if function is called inside the same script
92
    BackupStruct backup;
×
93
    SaveStack( backup );
×
94

95
    uoexec.initForFnCall( PC );
×
96

97
    uoexec.pushArg( p0 );
×
98
    uoexec.pushArg( p1 );
×
99
    uoexec.pushArg( p2 );
×
100
    uoexec.pushArg( p3 );
×
101

102
    uoexec.exec();
×
103

104
    bool istrue = expect_bool();
×
105

106
    // delete current state and reenable backup
107
    LoadStack( backup );
×
108

109
    return istrue;
×
110
  }
×
111
  catch ( std::exception& )  //...
×
112
  {
113
    return false;
×
114
  }
×
115
}
116

117
bool ExportScript::call( unsigned PC, BObjectImp* p0, BObjectImp* p1, BObjectImp* p2 )
×
118
{
119
  try
120
  {
121
    // build backup if function is called inside the same script
122
    BackupStruct backup;
×
123
    SaveStack( backup );
×
124

125
    uoexec.initForFnCall( PC );
×
126

127
    uoexec.pushArg( p0 );
×
128
    uoexec.pushArg( p1 );
×
129
    uoexec.pushArg( p2 );
×
130

131
    uoexec.exec();
×
132

133
    bool istrue = expect_bool();
×
134

135
    // delete current state and reenable backup
136
    LoadStack( backup );
×
137

138
    return istrue;
×
139
  }
×
140
  catch ( std::exception& )  //...
×
141
  {
142
    return false;
×
143
  }
×
144
}
145

146
bool ExportScript::call( unsigned PC, BObjectImp* p0, BObjectImp* p1 )
×
147
{
148
  try
149
  {
150
    // build backup if function is called inside the same script
151
    BackupStruct backup;
×
152
    SaveStack( backup );
×
153

154
    uoexec.initForFnCall( PC );
×
155

156
    uoexec.pushArg( p0 );
×
157
    uoexec.pushArg( p1 );
×
158

159
    uoexec.exec();
×
160

161
    bool istrue = expect_bool();
×
162

163
    // delete current state and reenable backup
164
    LoadStack( backup );
×
165

166
    return istrue;
×
167
  }
×
168
  catch ( std::exception& )  //...
×
169
  {
170
    return false;
×
171
  }
×
172
}
173

174
bool ExportScript::call( unsigned PC, BObjectImp* p0 )
×
175
{
176
  try
177
  {
178
    // build backup if function is called inside the same script
179
    BackupStruct backup;
×
180
    SaveStack( backup );
×
181

182
    uoexec.initForFnCall( PC );
×
183

184
    uoexec.pushArg( p0 );
×
185

186
    uoexec.exec();
×
187

188
    bool istrue = expect_bool();
×
189

190
    // delete current state and reenable backup
191
    LoadStack( backup );
×
192

193
    return istrue;
×
194
  }
×
195
  catch ( std::exception& )  //...
×
196
  {
197
    return false;
×
198
  }
×
199
}
200

201
std::string ExportScript::call_string( unsigned PC, BObjectImp* p0, BObjectImp* p1 )
×
202
{
203
  try
204
  {
205
    // build backup if function is called inside the same script
206
    BackupStruct backup;
×
207
    SaveStack( backup );
×
208

209
    uoexec.initForFnCall( PC );
×
210

211
    uoexec.pushArg( p0 );
×
212
    uoexec.pushArg( p1 );
×
213

214
    uoexec.exec();
×
215

216
    std::string ret = expect_string();
×
217

218
    // delete current state and reenable backup
219
    LoadStack( backup );
×
220

221
    return ret;
×
222
  }
×
223
  catch ( std::exception& )  //...
×
224
  {
225
    return "exception";
×
226
  }
×
227
}
228

229
std::string ExportScript::call_string( unsigned PC, BObjectImp* p0, BObjectImp* p1, BObjectImp* p2 )
×
230
{
231
  try
232
  {
233
    // build backup if function is called inside the same script
234
    BackupStruct backup;
×
235
    SaveStack( backup );
×
236

237
    uoexec.initForFnCall( PC );
×
238

239
    uoexec.pushArg( p0 );
×
240
    uoexec.pushArg( p1 );
×
241
    uoexec.pushArg( p2 );
×
242

243
    uoexec.exec();
×
244

245
    std::string ret = expect_string();
×
246

247
    // delete current state and reenable backup
248
    LoadStack( backup );
×
249

250
    return ret;
×
251
  }
×
252
  catch ( std::exception& )  //...
×
253
  {
254
    return "exception";
×
255
  }
×
256
}
257

258
int ExportScript::call_long( unsigned PC, BObjectImp* p0 )
522✔
259
{
260
  try
261
  {
262
    // build backup if function is called inside the same script
263
    BackupStruct backup;
522✔
264
    SaveStack( backup );
522✔
265

266
    uoexec.initForFnCall( PC );
522✔
267

268
    uoexec.pushArg( p0 );
522✔
269

270
    uoexec.exec();
522✔
271

272
    int ret = expect_int();
522✔
273

274
    // delete current state and reenable backup
275
    LoadStack( backup );
522✔
276

277
    return ret;
522✔
278
  }
522✔
279
  catch ( std::exception& )  //...
×
280
  {
281
    return 0;
×
282
  }
×
283
}
284

285
int ExportScript::call_long( unsigned PC, BObjectImp* p0, BObjectImp* p1 )
×
286
{
287
  try
288
  {
289
    // build backup if function is called inside the same script
290
    BackupStruct backup;
×
291
    SaveStack( backup );
×
292

293
    uoexec.initForFnCall( PC );
×
294

295
    uoexec.pushArg( p0 );
×
296
    uoexec.pushArg( p1 );
×
297

298
    uoexec.exec();
×
299

300
    int ret = expect_int();
×
301

302
    // delete current state and reenable backup
303
    LoadStack( backup );
×
304

305
    return ret;
×
306
  }
×
307
  catch ( std::exception& )  //...
×
308
  {
309
    return 0;
×
310
  }
×
311
}
312

313
BObjectImp* ExportScript::call( unsigned PC, BObjectImp* p0, std::vector<BObjectRef>& pmore )
7✔
314
{
315
  try
316
  {
317
    // build backup if function is called inside the same script
318
    BackupStruct backup;
7✔
319
    SaveStack( backup );
7✔
320

321
    uoexec.initForFnCall( PC );
7✔
322

323
    uoexec.pushArg( p0 );
7✔
324
    for ( const auto& ref : pmore )
7✔
325
    {  // push BObjectRef so params can be pass-by-ref
NEW
326
      uoexec.pushArg( ref );
×
327
    }
328

329
    uoexec.exec();
7✔
330

331
    BObjectImp* ret = expect_imp();
7✔
332

333
    // delete current state and reenable backup
334
    LoadStack( backup );
7✔
335

336
    return ret;
7✔
337
  }
7✔
338
  catch ( std::exception& )  //...
×
339
  {
340
    return new BError( "Exception during execution" );
×
341
  }
×
342
}
343

344
BObject ExportScript::call( unsigned PC, BObjectImp* p0, BObjectImpRefVec& pmore )
×
345
{
346
  try
347
  {
348
    // build backup if function is called inside the same script
349
    BackupStruct backup;
×
350
    SaveStack( backup );
×
351

352
    uoexec.initForFnCall( PC );
×
353

354
    uoexec.pushArg( p0 );
×
NEW
355
    for ( const auto& ref : pmore )
×
NEW
356
      uoexec.pushArg( ref.get() );
×
357

358
    uoexec.exec();
×
359
    BObjectImp* ret = expect_imp();
×
360

361
    // delete current state and reenable backup
362
    LoadStack( backup );
×
363

364
    return BObject( ret );
×
365
  }
×
366
  catch ( std::exception& )  //...
×
367
  {
368
    return BObject( new BError( "Exception during execution" ) );
×
369
  }
×
370
}
371

372
BObject ExportScript::call_object( unsigned PC, BObjectImp* p0, BObjectImp* p1 )
×
373
{
374
  try
375
  {
376
    // build backup if function is called inside the same script
377
    BackupStruct backup;
×
378
    SaveStack( backup );
×
379

380
    uoexec.initForFnCall( PC );
×
381

382
    uoexec.pushArg( p0 );
×
383
    uoexec.pushArg( p1 );
×
384

385
    uoexec.exec();
×
386

387
    BObjectImp* ret = expect_imp();
×
388

389
    // delete current state and reenable backup
390
    LoadStack( backup );
×
391

392
    return BObject( ret );
×
393
  }
×
394
  catch ( std::exception& )  //...
×
395
  {
396
    return BObject( new BError( "Exception during execution" ) );
×
397
  }
×
398
}
399

400
BObject ExportScript::call_object( unsigned PC, BObjectImp* p0, BObjectImp* p1, BObjectImp* p2 )
×
401
{
402
  try
403
  {
404
    // build backup if function is called inside the same script
405
    BackupStruct backup;
×
406
    SaveStack( backup );
×
407

408
    uoexec.initForFnCall( PC );
×
409

410
    uoexec.pushArg( p0 );
×
411
    uoexec.pushArg( p1 );
×
412
    uoexec.pushArg( p2 );
×
413

414
    uoexec.exec();
×
415
    BObjectImp* ret = expect_imp();
×
416

417
    // delete current state and reenable backup
418
    LoadStack( backup );
×
419

420
    return BObject( ret );
×
421
  }
×
422
  catch ( std::exception& )  //...
×
423
  {
424
    return BObject( new BError( "Exception during execution" ) );
×
425
  }
×
426
}
427

428
void ExportScript::SaveStack( BackupStruct& backup )
529✔
429
{
430
  if ( uoexec.PC != 0 )
529✔
431
  {
432
    backup.PC = uoexec.PC;
2✔
433
    backup.ValueStack = std::move( uoexec.ValueStack );
2✔
434
    if ( ( uoexec.Locals2 != nullptr ) && ( !uoexec.Locals2->empty() ) )
2✔
435
    {
436
      backup.Locals.reset( uoexec.Locals2 );
2✔
437
      uoexec.Locals2 = new BObjectRefVec;
2✔
438
    }
439
  }
440
  else
441
    backup.PC = 0;
527✔
442
}
529✔
443

444
void ExportScript::LoadStack( BackupStruct& backup )
529✔
445
{
446
  if ( backup.PC != 0 )
529✔
447
  {
448
    uoexec.initForFnCall( backup.PC );
2✔
449
    uoexec.ValueStack = std::move( backup.ValueStack );
2✔
450
    if ( backup.Locals.get() != nullptr )
2✔
451
    {
452
      delete uoexec.Locals2;
2✔
453
      uoexec.Locals2 = backup.Locals.release();
2✔
454
    }
455
  }
456
}
529✔
457

458
size_t ExportScript::estimateSize() const
1✔
459
{
460
  return sd.estimatedSize() + uoexec.sizeEstimate();
1✔
461
}
462

463
bool ExportScript::expect_bool()
×
464
{
465
  if ( uoexec.error() || uoexec.ValueStack.empty() )
×
466
    return false;
×
467
  bool istrue = uoexec.ValueStack.back().get()->isTrue();
×
468
  uoexec.ValueStack.pop_back();
×
469
  return istrue;
×
470
}
471

472
int ExportScript::expect_int()
522✔
473
{
474
  if ( uoexec.error() || uoexec.ValueStack.empty() )
522✔
475
    return 0;
×
476
  int ret;
477
  BObjectImp* imp = uoexec.ValueStack.back().get()->impptr();
522✔
478
  if ( auto* l = impptrIf<BLong>( imp ) )
522✔
479
    ret = l->value();
522✔
480
  else if ( auto* b = impptrIf<BBoolean>( imp ) )
×
481
    ret = b->isTrue() ? 1 : 0;
×
482
  else
483
    ret = 0;
×
484
  uoexec.ValueStack.pop_back();
522✔
485
  return ret;
522✔
486
}
487

488
std::string ExportScript::expect_string()
×
489
{
490
  if ( uoexec.error() || uoexec.ValueStack.empty() )
×
491
    return "error";
×
492
  auto ret = uoexec.ValueStack.back().get()->impptr()->getStringRep();
×
493
  uoexec.ValueStack.pop_back();
×
494
  return ret;
×
495
}
×
496

497
BObjectImp* ExportScript::expect_imp()
7✔
498
{
499
  if ( uoexec.error() )
7✔
500
    return new BError( "Error during execution" );
×
501
  if ( uoexec.ValueStack.empty() )
7✔
502
    return new BError( "There was no return value??" );
×
503

504
  auto ret = uoexec.ValueStack.back()->impptr()->copy();
7✔
505
  uoexec.ValueStack.pop_back();
7✔
506
  return ret;
7✔
507
}
508
}  // namespace Pol::Core
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc