22
22
23
23
void errorReportInit (ErrorReport * report , Storage * storage , const char * fileName , const char * fnName , int line , int pos , int code , const char * format , va_list args )
24
24
{
25
- report -> fileName = storageAdd (storage , strlen (fileName ) + 1 );
26
- strcpy (report -> fileName , fileName );
25
+ char * reportFileName = storageAdd (storage , strlen (fileName ) + 1 );
26
+ strcpy (reportFileName , fileName );
27
+ report -> fileName = reportFileName ;
27
28
28
- report -> fnName = storageAdd (storage , strlen (fnName ) + 1 );
29
- strcpy (report -> fnName , fnName );
29
+ char * reportFnName = storageAdd (storage , strlen (fnName ) + 1 );
30
+ strcpy (reportFnName , fnName );
31
+ report -> fnName = reportFnName ;
30
32
31
33
report -> line = line ;
32
34
report -> pos = pos ;
@@ -36,8 +38,9 @@ void errorReportInit(ErrorReport *report, Storage *storage, const char *fileName
36
38
va_copy (argsCopy , args );
37
39
38
40
const int msgLen = vsnprintf (NULL , 0 , format , args );
39
- report -> msg = storageAdd (storage , msgLen + 1 );
40
- vsnprintf (report -> msg , msgLen + 1 , format , argsCopy );
41
+ char * reportMsg = storageAdd (storage , msgLen + 1 );
42
+ vsnprintf (reportMsg , msgLen + 1 , format , argsCopy );
43
+ report -> msg = reportMsg ;
41
44
42
45
va_end (argsCopy );
43
46
}
@@ -96,7 +99,7 @@ char *storageAddStr(Storage *storage, int64_t len)
96
99
}
97
100
98
101
99
- DynArray * storageAddDynArray (Storage * storage , struct tagType * type , int64_t len )
102
+ DynArray * storageAddDynArray (Storage * storage , const struct tagType * type , int64_t len )
100
103
{
101
104
DynArray * array = storageAdd (storage , sizeof (DynArray ));
102
105
@@ -132,7 +135,7 @@ void storageRemove(Storage *storage, void *data)
132
135
133
136
void * storageRealloc (Storage * storage , void * data , int64_t size )
134
137
{
135
- StorageChunk * chunk = (StorageChunk * )((char * )data - sizeof (StorageChunk ));
138
+ const StorageChunk * chunk = (const StorageChunk * )((char * )data - sizeof (StorageChunk ));
136
139
137
140
void * newData = storageAdd (storage , size );
138
141
memcpy (newData , data , chunk -> size );
@@ -154,8 +157,9 @@ static const char *moduleImplLibSuffix()
154
157
#else
155
158
return "_linux" ;
156
159
#endif
157
- #endif
160
+ #else
158
161
return "" ;
162
+ #endif
159
163
}
160
164
161
165
@@ -167,8 +171,9 @@ static void *moduleLoadImplLib(const char *path)
167
171
#else
168
172
return dlopen (path , RTLD_LOCAL | RTLD_LAZY );
169
173
#endif
170
- #endif
174
+ #else
171
175
return NULL ;
176
+ #endif
172
177
}
173
178
174
179
@@ -192,8 +197,9 @@ static void *moduleLoadImplLibFunc(void *lib, const char *name)
192
197
#else
193
198
return dlsym (lib , name );
194
199
#endif
195
- #endif
200
+ #else
196
201
return NULL ;
202
+ #endif
197
203
}
198
204
199
205
@@ -223,7 +229,7 @@ void moduleFree(Modules *modules)
223
229
}
224
230
225
231
226
- void moduleNameFromPath (Modules * modules , const char * path , char * folder , char * name , int size )
232
+ void moduleNameFromPath (const Modules * modules , const char * path , char * folder , char * name , int size )
227
233
{
228
234
const char * slash = strrchr (path , '/' );
229
235
const char * backslash = strrchr (path , '\\' );
@@ -247,17 +253,17 @@ void moduleNameFromPath(Modules *modules, const char *path, char *folder, char *
247
253
}
248
254
249
255
250
- int moduleFind (Modules * modules , const char * path )
256
+ int moduleFind (const Modules * modules , const char * path )
251
257
{
252
- unsigned int pathHash = hash (path );
258
+ const unsigned int pathHash = hash (path );
253
259
for (int i = 0 ; i < modules -> numModules ; i ++ )
254
260
if (modules -> module [i ]-> pathHash == pathHash && strcmp (modules -> module [i ]-> path , path ) == 0 )
255
261
return i ;
256
262
return -1 ;
257
263
}
258
264
259
265
260
- int moduleFindImported (Modules * modules , Blocks * blocks , const char * alias )
266
+ int moduleFindImported (const Modules * modules , const Blocks * blocks , const char * alias )
261
267
{
262
268
for (int i = 0 ; i < modules -> numModules ; i ++ )
263
269
{
@@ -329,9 +335,9 @@ int moduleAdd(Modules *modules, const char *path)
329
335
}
330
336
331
337
332
- ModuleSource * moduleFindSource (Modules * modules , const char * path )
338
+ const ModuleSource * moduleFindSource (const Modules * modules , const char * path )
333
339
{
334
- unsigned int pathHash = hash (path );
340
+ const unsigned int pathHash = hash (path );
335
341
for (int i = 0 ; i < modules -> numModuleSources ; i ++ )
336
342
if (modules -> moduleSource [i ]-> pathHash == pathHash && strcmp (modules -> moduleSource [i ]-> path , path ) == 0 )
337
343
return modules -> moduleSource [i ];
@@ -371,7 +377,7 @@ void moduleAddSource(Modules *modules, const char *path, const char *source, boo
371
377
}
372
378
373
379
374
- void * moduleGetImplLibFunc (Module * module , const char * name )
380
+ void * moduleGetImplLibFunc (const Module * module , const char * name )
375
381
{
376
382
if (module -> implLib )
377
383
return moduleLoadImplLibFunc (module -> implLib , name );
@@ -419,15 +425,16 @@ bool modulePathIsAbsolute(const char *path)
419
425
}
420
426
421
427
422
- bool moduleRegularizePath (Modules * modules , const char * path , const char * curFolder , char * regularizedPath , int size )
428
+ bool moduleRegularizePath (const Modules * modules , const char * path , const char * curFolder , char * regularizedPath , int size )
423
429
{
424
430
char * absolutePath = storageAdd (modules -> storage , size );
425
431
snprintf (absolutePath , size , "%s%s" , modulePathIsAbsolute (path ) ? "" : curFolder , path );
426
432
427
433
char * * separators = storageAdd (modules -> storage , size * sizeof (char * ));
428
434
int numSeparators = 0 ;
429
435
430
- char * readCh = absolutePath , * writeCh = regularizedPath ;
436
+ const char * readCh = absolutePath ;
437
+ char * writeCh = regularizedPath ;
431
438
int numDots = 0 ;
432
439
433
440
while (* readCh )
@@ -499,7 +506,7 @@ bool moduleRegularizePath(Modules *modules, const char *path, const char *curFol
499
506
}
500
507
501
508
502
- void moduleAssertRegularizePath (Modules * modules , const char * path , const char * curFolder , char * regularizedPath , int size )
509
+ void moduleAssertRegularizePath (const Modules * modules , const char * path , const char * curFolder , char * regularizedPath , int size )
503
510
{
504
511
if (!moduleRegularizePath (modules , path , curFolder , regularizedPath , size ))
505
512
modules -> error -> handler (modules -> error -> context , "Invalid module path %s" , path );
@@ -519,7 +526,7 @@ void blocksInit(Blocks *blocks, Error *error)
519
526
}
520
527
521
528
522
- void blocksEnterFn (Blocks * blocks , struct tagIdent * fn , bool hasUpvalues )
529
+ void blocksEnterFn (Blocks * blocks , const struct tagIdent * fn , bool hasUpvalues )
523
530
{
524
531
if (blocks -> top >= MAX_BLOCK_NESTING )
525
532
blocks -> error -> handler (blocks -> error -> context , "Block nesting is too deep" );
@@ -553,7 +560,7 @@ void blocksReenter(Blocks *blocks)
553
560
}
554
561
555
562
556
- int blocksCurrent (Blocks * blocks )
563
+ int blocksCurrent (const Blocks * blocks )
557
564
{
558
565
return blocks -> item [blocks -> top ].block ;
559
566
}
@@ -568,9 +575,9 @@ void externalInit(Externals *externals, Storage *storage)
568
575
}
569
576
570
577
571
- External * externalFind (Externals * externals , const char * name )
578
+ External * externalFind (const Externals * externals , const char * name )
572
579
{
573
- unsigned int nameHash = hash (name );
580
+ const unsigned int nameHash = hash (name );
574
581
575
582
for (External * external = externals -> first ; external ; external = external -> next )
576
583
if (external -> hash == nameHash && strcmp (external -> name , name ) == 0 )
0 commit comments