Skip to content

Commit d962ea0

Browse files
committed
Bound lazy schema warnings per file
Materializing each instance repeated the same FILE_SCHEMA warning. Keep a thread-safe claim flag on the lazy file reader so concurrent loads and multiple DATA sections report the ambiguity once per input file.
1 parent 5a37441 commit d962ea0

5 files changed

Lines changed: 28 additions & 4 deletions

File tree

include/cllazyfile/lazyFileReader.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#ifndef LAZYFILEREADER_H
22
#define LAZYFILEREADER_H
33

4+
#include <atomic>
45
#include <vector>
56
#include <string>
67
#include <cstdlib>
@@ -32,6 +33,7 @@ class SC_LAZYFILE_EXPORT lazyFileReader {
3233
lazyInstMgr * _parent;
3334
headerSectionReader * _header;
3435
std::ifstream _file;
36+
std::atomic<bool> _schemaWarningClaimed;
3537
#ifdef _MSC_VER
3638
#pragma warning( pop )
3739
#endif
@@ -68,6 +70,14 @@ class SC_LAZYFILE_EXPORT lazyFileReader {
6870
return _parent;
6971
}
7072

73+
/** Return true only to the first caller reporting a FILE_SCHEMA
74+
* selection warning for this file. Instance materialization may
75+
* occur concurrently and span multiple DATA sections. */
76+
bool claimSchemaWarning() {
77+
return !_schemaWarningClaimed.exchange( true,
78+
std::memory_order_relaxed );
79+
}
80+
7181
bool needKW( const char * kw );
7282
};
7383

src/cllazyfile/lazyFileReader.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ instancesLoaded_t * lazyFileReader::getHeaderInstances() {
7878
}
7979

8080
lazyFileReader::lazyFileReader( std::string fname, lazyInstMgr * i, fileID fid ): _fileName( fname ), _parent( i ),
81-
_header( 0 ), _fileID( fid ), _fileSize( 0 ), _valid( false ) {
81+
_header( 0 ), _schemaWarningClaimed( false ), _fileID( fid ),
82+
_fileSize( 0 ), _valid( false ) {
8283
_file.open( _fileName.c_str(), std::ios::binary );
8384
_file.imbue( std::locale::classic() );
8485
_file.unsetf( std::ios_base::skipws );

src/cllazyfile/lazy_index_test.cc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include <cstdlib>
22
#include <iostream>
3+
#include <sstream>
34

45
#include "cllazyfile/lazyInstMgr.h"
56

@@ -69,10 +70,22 @@ int main( int argc, char ** argv ) {
6970

7071
Registry emptyRegistry( emptyRegistryInit );
7172
manager.setRegistry( &emptyRegistry );
73+
std::ostringstream schemaWarnings;
74+
std::streambuf * originalCerr = std::cerr.rdbuf( schemaWarnings.rdbuf() );
7275
LazyInstanceBatch missingBatch = manager.loadBatch( 5 );
76+
LazyInstanceBatch secondBatch = manager.loadBatch( 1 );
77+
std::cerr.rdbuf( originalCerr );
7378
require( missingBatch.instances().size() == 1 &&
7479
missingBatch.instances()[0] == 5,
7580
"missing reference leaked into materialization closure" );
81+
const std::string warningText =
82+
"Warning - multiple schema names found. Only searching with first one.";
83+
const size_t firstWarning = schemaWarnings.str().find( warningText );
84+
require( firstWarning != std::string::npos &&
85+
schemaWarnings.str().find( warningText, firstWarning + 1 ) ==
86+
std::string::npos,
87+
"multiple FILE_SCHEMA warning was not bounded per file" );
88+
secondBatch.release();
7689
missingBatch.release();
7790

7891
lazyInstMgr cancelled;

src/cllazyfile/sectionReader.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -446,11 +446,11 @@ SDAI_Application_instance * sectionReader::getRealInstance( const Registry * reg
446446
size_t qualifier = normalizedSchema.find_first_of( " {" );
447447
if( qualifier != std::string::npos ) normalizedSchema.erase( qualifier );
448448
sName = normalizedSchema.c_str();
449-
if( sn->NextNode() ) {
449+
if( sn->NextNode() && _lazyFile->claimSchemaWarning() ) {
450450
std::cerr << "Warning - multiple schema names found. Only searching with first one." << std::endl;
451451
}
452452
}
453-
} else {
453+
} else if( _lazyFile->claimSchemaWarning() ) {
454454
std::cerr << "Warning - no schema names found; the file is probably invalid. Looking for typeName in any loaded schema." << std::endl;
455455
}
456456
}

src/cllazyfile/test/lazy_index.stp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ ISO-10303-21;
22
HEADER;
33
FILE_DESCRIPTION(('lazy index test'),'2;1');
44
FILE_NAME('lazy_index.stp','2026-07-17T00:00:00',('STEPcode'),('STEPcode'),'','','');
5-
FILE_SCHEMA(('LAZY_TEST_SCHEMA { 1 0 10303 999 }'));
5+
FILE_SCHEMA(('LAZY_TEST_SCHEMA { 1 0 10303 999 }','UNUSED_TEST_SCHEMA'));
66
ENDSEC;
77
DATA('second',('LAZY_TEST_SCHEMA'));
88
#1=A($,'escaped quote '' and unicode \X2\03A9\X0\',#2);

0 commit comments

Comments
 (0)