Skip to content

File tree

5 files changed

+50
-11
lines changed

5 files changed

+50
-11
lines changed

core/src/FieldmlDOM.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -671,8 +671,9 @@ class ReferenceEvaluatorParser :
671671
{
672672
const char *name = getStringAttribute( objectNode, NAME_ATTRIB );
673673
FmlObjectHandle sourceEvaluator = getObjectAttribute( objectNode, EVALUATOR_ATTRIB, state );
674+
FmlObjectHandle valueType = getObjectAttribute( objectNode, VALUE_TYPE_ATTRIB, state );
674675

675-
FmlObjectHandle evaluator = Fieldml_CreateReferenceEvaluator( state.session, name, sourceEvaluator );
676+
FmlObjectHandle evaluator = Fieldml_CreateReferenceEvaluator( state.session, name, sourceEvaluator, valueType );
676677
if( evaluator == FML_INVALID_HANDLE )
677678
{
678679
state.errorHandler->logError( "ReferenceEvaluator creation failed", name );

core/src/fieldml_api.cpp

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2158,6 +2158,11 @@ FmlEnsembleValue Fieldml_GetEvaluatorElement( FmlSessionHandle handle, FmlObject
21582158
return -1;
21592159
}
21602160

2161+
if ( ( evaluatorIndex < 0 ) || ( evaluatorIndex > map->size() ) )
2162+
{
2163+
return -1;
2164+
}
2165+
21612166
return map->getKey( evaluatorIndex - 1 );
21622167
}
21632168

@@ -2179,6 +2184,11 @@ FmlObjectHandle Fieldml_GetEvaluator( FmlSessionHandle handle, FmlObjectHandle o
21792184
return FML_INVALID_HANDLE;
21802185
}
21812186

2187+
if ( ( evaluatorIndex < 0 ) || ( evaluatorIndex > map->size() ) )
2188+
{
2189+
return FML_INVALID_HANDLE;
2190+
}
2191+
21822192
return map->getValue( evaluatorIndex - 1 );
21832193
}
21842194

@@ -2204,7 +2214,7 @@ FmlObjectHandle Fieldml_GetElementEvaluator( FmlSessionHandle handle, FmlObjectH
22042214
}
22052215

22062216

2207-
FmlObjectHandle Fieldml_CreateReferenceEvaluator( FmlSessionHandle handle, const char * name, FmlObjectHandle sourceEvaluator )
2217+
FmlObjectHandle Fieldml_CreateReferenceEvaluator( FmlSessionHandle handle, const char * name, FmlObjectHandle sourceEvaluator, FmlObjectHandle valueType )
22082218
{
22092219
FieldmlSession *session = FieldmlSession::handleToSession( handle );
22102220
ERROR_AUTOSTACK( session );
@@ -2224,7 +2234,22 @@ FmlObjectHandle Fieldml_CreateReferenceEvaluator( FmlSessionHandle handle, const
22242234
return session->getLastError();
22252235
}
22262236

2227-
FmlObjectHandle valueType = Fieldml_GetValueType( handle, sourceEvaluator );
2237+
if( !checkLocal( session, valueType ) )
2238+
{
2239+
return session->getLastError();
2240+
}
2241+
2242+
if( !checkIsValueType( session, valueType, true, false, false, false ) )
2243+
{
2244+
session->setError( FML_ERR_INVALID_PARAMETER_4, valueType, "Cannot create reference evaluator of this type." );
2245+
return FML_INVALID_HANDLE;
2246+
}
2247+
2248+
if ( Fieldml_GetTypeComponentCount( handle, valueType ) > 1 )
2249+
{
2250+
session->setError( FML_ERR_INVALID_PARAMETER_4, valueType, "Cannot create reference evaluator, value type is not a scalar type." );
2251+
return FML_INVALID_HANDLE;
2252+
}
22282253

22292254
ReferenceEvaluator *referenceEvaluator = new ReferenceEvaluator( name, sourceEvaluator, valueType, false );
22302255

@@ -2377,6 +2402,11 @@ FmlObjectHandle Fieldml_GetBindArgument( FmlSessionHandle handle, FmlObjectHandl
23772402
return FML_INVALID_HANDLE;
23782403
}
23792404

2405+
if ( ( bindIndex < 0 ) || ( bindIndex > map->size() ) )
2406+
{
2407+
return FML_INVALID_HANDLE;
2408+
}
2409+
23802410
return map->getKey( bindIndex - 1 );
23812411
}
23822412

@@ -2397,6 +2427,11 @@ FmlObjectHandle Fieldml_GetBindEvaluator( FmlSessionHandle handle, FmlObjectHand
23972427
return FML_INVALID_HANDLE;
23982428
}
23992429

2430+
if ( ( bindIndex < 0 ) || ( bindIndex > map->size() ) )
2431+
{
2432+
return FML_INVALID_HANDLE;
2433+
}
2434+
24002435
return map->getValue( bindIndex - 1 );
24012436
}
24022437

core/src/fieldml_api.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -991,11 +991,11 @@ FmlObjectHandle Fieldml_GetIndexEvaluator( FmlSessionHandle handle, FmlObjectHan
991991
* Creates a reference evaluator. Reference evaluators delegate their evaluation directly to another evaluator, but can bind
992992
* argument evaluators before doing so.
993993
*
994-
* \note A reference evaluator's value type is the same as the value type of its source evaluator.
994+
* \note Currently, the value type must be a scalar continuous type.
995995
*
996996
* \see Fieldml_GetReferenceSourceEvaluator
997997
*/
998-
FmlObjectHandle Fieldml_CreateReferenceEvaluator( FmlSessionHandle handle, const char * name, FmlObjectHandle sourceEvaluator );
998+
FmlObjectHandle Fieldml_CreateReferenceEvaluator( FmlSessionHandle handle, const char * name, FmlObjectHandle sourceEvaluator, FmlObjectHandle valueType );
999999

10001000

10011001
/**
@@ -1057,7 +1057,8 @@ int Fieldml_GetBindCount( FmlSessionHandle handle, FmlObjectHandle objectHandle
10571057

10581058

10591059
/**
1060-
* \return The argument evaulator used by the nth bind in the given evaluator.
1060+
* \return The argument evaulator used by the nth bind in the given evaluator. FML_INVALID_HANDLE will be returned
1061+
* if object at bind index cannot be found.
10611062
*
10621063
* \see Fieldml_GetBindCount
10631064
* \see Fieldml_SetBind

core/src/fieldml_write.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ static int writeBinds( xmlTextWriterPtr writer, FmlSessionHandle handle, FmlObje
167167

168168
static int writeArguments( xmlTextWriterPtr writer, FmlSessionHandle handle, FmlObjectHandle object )
169169
{
170-
int count = Fieldml_GetArgumentCount( handle, object, 1, 1 );
170+
int count = Fieldml_GetArgumentCount( handle, object, 0, 0 );
171171
if( count <= 0 )
172172
{
173173
return 0;
@@ -177,7 +177,7 @@ static int writeArguments( xmlTextWriterPtr writer, FmlSessionHandle handle, Fml
177177

178178
for( int i = 1; i <= count; i++ )
179179
{
180-
FmlObjectHandle argument = Fieldml_GetArgument( handle, object, i, 1, 1 );
180+
FmlObjectHandle argument = Fieldml_GetArgument( handle, object, i, 0, 0 );
181181
if( argument == FML_INVALID_HANDLE )
182182
{
183183
continue;

test/src/fieldml_test.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -512,15 +512,17 @@ int testCycles()
512512

513513
FmlObjectHandle type = Fieldml_CreateContinuousType( session, "test.type" );
514514

515+
FmlObjectHandle type2 = Fieldml_CreateContinuousType( session, "test.type.2" );
516+
515517
FmlObjectHandle ensemble = Fieldml_CreateEnsembleType( session, "test.ensemble" );
516518
Fieldml_SetEnsembleMembersRange( session, ensemble, 1, 20, 1 );
517519

518520
FmlObjectHandle arg1 = Fieldml_CreateArgumentEvaluator( session, "test.arg1", type );
519521

520522
FmlObjectHandle external = Fieldml_CreateExternalEvaluator( session, "test.external", type );
521523

522-
FmlObjectHandle ref1 = Fieldml_CreateReferenceEvaluator( session, "test.reference1", external );
523-
FmlObjectHandle ref2 = Fieldml_CreateReferenceEvaluator( session, "test.reference2", ref1 );
524+
FmlObjectHandle ref1 = Fieldml_CreateReferenceEvaluator( session, "test.reference1", external , type);
525+
FmlObjectHandle ref2 = Fieldml_CreateReferenceEvaluator( session, "test.reference2", ref1 , type2);
524526

525527
if( Fieldml_SetBind( session, ref1, arg1, ref2 ) != FML_ERR_CYCLIC_DEPENDENCY )
526528
{
@@ -531,7 +533,7 @@ int testCycles()
531533
FmlObjectHandle param = Fieldml_CreateParameterEvaluator( session, "test.parameter", ensemble );
532534
Fieldml_SetParameterDataDescription( session, param, FML_DATA_DESCRIPTION_DOK_ARRAY );
533535

534-
FmlObjectHandle ref3 = Fieldml_CreateReferenceEvaluator( session, "test.reference3", param );
536+
FmlObjectHandle ref3 = Fieldml_CreateReferenceEvaluator( session, "test.reference3", param , type);
535537

536538
if( Fieldml_AddDenseIndexEvaluator( session, param, ref3, FML_INVALID_HANDLE ) != FML_ERR_CYCLIC_DEPENDENCY )
537539
{

0 commit comments

Comments
 (0)