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

polserver / polserver / 25918451630

15 May 2026 12:43PM UTC coverage: 60.929% (+2.1%) from 58.859%
25918451630

push

github

turleypol
added dynamic property which returns a pointer of the object instead of
a copy like the current imp.
needed to be able to eg store a vector

43 of 61 new or added lines in 2 files covered. (70.49%)

14455 existing lines in 345 files now uncovered.

44695 of 73356 relevant lines covered (60.93%)

449621.59 hits per line

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

21.9
/pol-core/bscript/symcont.cpp
1
/** @file
2
 *
3
 * @par History
4
 * - 2006/10/06 Shinigami: malloc.h -> stdlib.h
5
 */
6

7

8
#include "symcont.h"
9

10
#include <cstdio>
11
#include <cstdlib>
12
#include <cstring>
13
#include <string>
14

15
#include "../clib/logfacility.h"
16
#include "../clib/strutil.h"
17

18

19
namespace Pol::Bscript
20
{
21
SymbolContainer::SymbolContainer( int PgrowBy )
4,286✔
22
{
23
  s = nullptr;
4,286✔
24
  usedLen = allocLen = 0u;
4,286✔
25
  growBy = PgrowBy;
4,286✔
26
}
4,286✔
27
SymbolContainer::~SymbolContainer()
3,974✔
28
{
29
  if ( s )
3,974✔
30
    free( s );
3,972✔
31
  s = nullptr;
3,974✔
32
}
3,974✔
33

UNCOV
34
void SymbolContainer::erase()
×
35
{
UNCOV
36
  if ( s )
×
37
    free( s );
×
38
  s = nullptr;
×
39
  usedLen = allocLen = 0;
×
40
}
×
41

UNCOV
42
void SymbolContainer::resize( unsigned lengthToAdd )
×
43
{
UNCOV
44
  while ( usedLen + lengthToAdd > allocLen )
×
45
  {
UNCOV
46
    allocLen += growBy;
×
47
    if ( s == nullptr )
×
48
    {
UNCOV
49
      s = (char*)calloc( 1, (unsigned)allocLen );
×
50
      usedLen = 0;
×
51
    }
52
    else
53
    {
UNCOV
54
      char* t = (char*)realloc( s, allocLen );
×
55
      if ( t )
×
56
        s = t;
×
57
      else
UNCOV
58
        throw std::runtime_error( "allocation failure in SymbolContainer::resize(" +
×
59
                                  Clib::tostring( allocLen ) + ")" );
×
60
    }
61
  }
UNCOV
62
}
×
63

UNCOV
64
bool SymbolContainer::findexisting( const void* data, int datalen, unsigned& position )
×
65
{
UNCOV
66
  int nstarting = usedLen - datalen + 1;
×
67
  // don't use the first byte, because that's the "fake null"
UNCOV
68
  for ( int i = 1; i < nstarting; i++ )
×
69
  {
UNCOV
70
    if ( memcmp( s + i, data, datalen ) == 0 )
×
71
    {
UNCOV
72
      position = i;
×
73
      return true;
×
74
    }
75
  }
UNCOV
76
  return false;
×
77
}
78

UNCOV
79
void SymbolContainer::append( const char* string, unsigned& position )
×
80
{
UNCOV
81
  int nChars = static_cast<unsigned int>( strlen( string ) + 1 );
×
82
  if ( findexisting( string, nChars, position ) )
×
83
    return;
×
84
  resize( nChars );
×
85
  strcpy( s + usedLen, string );
×
86
  position = usedLen;
×
87
  usedLen += nChars;
×
88
}
89

UNCOV
90
void SymbolContainer::append( int lvalue, unsigned& position )
×
91
{
UNCOV
92
  resize( sizeof lvalue );
×
93
  std::memcpy( s + usedLen, &lvalue, sizeof( int ) );
×
94
  position = usedLen;
×
95
  usedLen += sizeof lvalue;
×
96
}
×
97

UNCOV
98
void SymbolContainer::append( double dvalue, unsigned& position )
×
99
{
UNCOV
100
  resize( sizeof dvalue );
×
101
  std::memcpy( s + usedLen, &dvalue, sizeof( double ) );
×
102
  position = usedLen;
×
103
  usedLen += sizeof dvalue;
×
104
}
×
105

UNCOV
106
void SymbolContainer::append( void* data, unsigned datalen, unsigned& position )
×
107
{
UNCOV
108
  resize( datalen );
×
109
  if ( findexisting( data, datalen, position ) )
×
110
    return;
×
111
  memcpy( s + usedLen, data, datalen );
×
112
  position = usedLen;
×
113
  usedLen += datalen;
×
114
}
115

UNCOV
116
void SymbolContainer::write( FILE* fp )
×
117
{
UNCOV
118
  if ( fwrite( &usedLen, sizeof usedLen, 1, fp ) != 1 )
×
119
    throw std::runtime_error( "SymbolContainer::write failed" );
×
120
  if ( fwrite( s, usedLen, 1, fp ) != 1 )
×
121
    throw std::runtime_error( "SymbolContainer::write failed" );
×
122
}
×
123

UNCOV
124
unsigned int SymbolContainer::get_write_length() const
×
125
{
126
  // we write the length, followed by the actual data.
UNCOV
127
  return sizeof usedLen + usedLen;
×
128
}
129

UNCOV
130
void SymbolContainer::write( char* fname )
×
131
{
UNCOV
132
  FILE* fp = fopen( fname, "wb" );
×
133
  if ( !fp )
×
134
    throw std::runtime_error( std::string( "Unable to open " ) + fname + " for writing." );
×
135
  write( fp );
×
136
  fclose( fp );
×
137
}
×
138

139
void SymbolContainer::read( FILE* fp )
4,284✔
140
{
141
  size_t fread_res = fread( &usedLen, sizeof usedLen, 1, fp );
4,284✔
142
  if ( fread_res != 1 )
4,284✔
UNCOV
143
    throw std::runtime_error( "failed to read in SymbolContainer::read()." );
×
144
  char* new_s = (char*)realloc( s, usedLen );
4,284✔
145
  if ( !new_s )
4,284✔
UNCOV
146
    throw std::runtime_error( "allocation failure in SymbolContainer::read()." );
×
147
  s = new_s;
4,284✔
148
  fread_res = fread( s, usedLen, 1, fp );
4,284✔
149
  if ( fread_res != 1 )
4,284✔
UNCOV
150
    throw std::runtime_error( "failed to read in SymbolContainer::read()." );
×
151
  allocLen = usedLen;
4,284✔
152
}
4,284✔
153

154
void StoredTokenContainer::read( FILE* fp )
2,142✔
155
{
156
  SymbolContainer::read( fp );
2,142✔
157
  ST = (StoredToken*)s;
2,142✔
158
}
2,142✔
159

UNCOV
160
void SymbolContainer::read( char* fname )
×
161
{
UNCOV
162
  FILE* fp = fopen( fname, "rb" );
×
163
  if ( !fp )
×
164
    throw std::runtime_error( std::string( "Unable to open " ) + fname + " for reading." );
×
165
  read( fp );
×
166
  fclose( fp );
×
167
}
×
168

UNCOV
169
void StoredTokenContainer::append_tok( const StoredToken& sToken, unsigned* pposition )
×
170
{
UNCOV
171
  resize( sizeof sToken );
×
172
  unsigned position = usedLen / sizeof( StoredToken );
×
173
  usedLen += sizeof sToken;
×
174
  atPut1( sToken, position );
×
175
  if ( pposition )
×
176
    *pposition = position;
×
177
}
×
178

UNCOV
179
void StoredTokenContainer::atPut1( const StoredToken& sToken, unsigned position )
×
180
{
UNCOV
181
  if ( position >= count() )
×
182
    throw std::runtime_error( "Assigning token at invalid position " + Clib::tostring( position ) +
×
183
                              ", range is 0.." + Clib::tostring( count() - 1 ) );
×
184

UNCOV
185
  char* dst = s + position * sizeof( StoredToken );
×
186
  StoredToken* st = (StoredToken*)dst;
×
187
  *st = sToken;
×
188
}
×
189

190
void StoredTokenContainer::atGet1( unsigned position, StoredToken& sToken ) const
162,166✔
191
{
192
  if ( position >= count() )
162,166✔
UNCOV
193
    throw std::runtime_error( "Retrieving token at invalid position " + Clib::tostring( position ) +
×
194
                              ", range is 0.." + Clib::tostring( count() - 1 ) );
×
195

196
  char* src = s + position * sizeof( StoredToken );
162,166✔
197
  StoredToken* st = (StoredToken*)src;
162,166✔
198

199
  sToken = *st;
162,166✔
200
}
162,166✔
201

UNCOV
202
void StoredTokenContainer::pack()
×
203
{
UNCOV
204
  SymbolContainer::pack();
×
205
  ST = (StoredToken*)s;
×
206
}
×
207

UNCOV
208
void* StoredTokenContainer::detach()
×
209
{
UNCOV
210
  void* d = SymbolContainer::detach();
×
211
  ST = nullptr;
×
212
  return d;
×
213
}
214

UNCOV
215
void StoredTokenContainer::resize( unsigned lengthToAdd )
×
216
{
UNCOV
217
  SymbolContainer::resize( lengthToAdd );
×
218
  ST = (StoredToken*)s;
×
219
}
×
220

221
}  // namespace Pol::Bscript
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