@@ -60,72 +60,6 @@ static void list_constraint_destructor (void **item)
6060 }
6161}
6262
63- static bool match_and (struct list_constraint * c , const struct job * job )
64- {
65- struct list_constraint * cp = zlistx_first (c -> values );
66- while (cp ) {
67- if (!cp -> match (cp , job ))
68- return false;
69- cp = zlistx_next (c -> values );
70- }
71- return true;
72- }
73-
74- static bool match_or (struct list_constraint * c , const struct job * job )
75- {
76- struct list_constraint * cp = zlistx_first (c -> values );
77- /* no values in "or" defined as true per RFC31 */
78- if (!cp )
79- return true;
80- while (cp ) {
81- if (cp -> match (cp , job ))
82- return true;
83- cp = zlistx_next (c -> values );
84- }
85- return false;
86- }
87-
88- static bool match_not (struct list_constraint * c , const struct job * job )
89- {
90- return !match_and (c , job );
91- }
92-
93- static struct list_constraint * conditional_constraint (const char * type ,
94- json_t * values ,
95- flux_error_t * errp )
96- {
97- json_t * entry ;
98- size_t index ;
99- struct list_constraint * c ;
100- match_f match_cb ;
101-
102- if (streq (type , "and" ))
103- match_cb = match_and ;
104- else if (streq (type , "or" ))
105- match_cb = match_or ;
106- else /* streq (type, "not") */
107- match_cb = match_not ;
108-
109- if (!(c = list_constraint_new (match_cb , list_constraint_destructor , errp )))
110- return NULL ;
111-
112- json_array_foreach (values , index , entry ) {
113- struct list_constraint * cp = list_constraint_create (entry , errp );
114- if (!cp )
115- goto error ;
116- if (!zlistx_add_end (c -> values , cp )) {
117- errprintf (errp , "Out of memory" );
118- list_constraint_destroy (cp );
119- goto error ;
120- }
121- }
122- return c ;
123-
124- error :
125- list_constraint_destroy (c );
126- return NULL ;
127- }
128-
12963/* zlistx_set_destructor */
13064static void wrap_free (void * * item )
13165{
@@ -382,6 +316,72 @@ static struct list_constraint *create_since_constraint (json_t *values,
382316 return c ;
383317}
384318
319+ static bool match_and (struct list_constraint * c , const struct job * job )
320+ {
321+ struct list_constraint * cp = zlistx_first (c -> values );
322+ while (cp ) {
323+ if (!cp -> match (cp , job ))
324+ return false;
325+ cp = zlistx_next (c -> values );
326+ }
327+ return true;
328+ }
329+
330+ static bool match_or (struct list_constraint * c , const struct job * job )
331+ {
332+ struct list_constraint * cp = zlistx_first (c -> values );
333+ /* no values in "or" defined as true per RFC31 */
334+ if (!cp )
335+ return true;
336+ while (cp ) {
337+ if (cp -> match (cp , job ))
338+ return true;
339+ cp = zlistx_next (c -> values );
340+ }
341+ return false;
342+ }
343+
344+ static bool match_not (struct list_constraint * c , const struct job * job )
345+ {
346+ return !match_and (c , job );
347+ }
348+
349+ static struct list_constraint * conditional_constraint (const char * type ,
350+ json_t * values ,
351+ flux_error_t * errp )
352+ {
353+ json_t * entry ;
354+ size_t index ;
355+ struct list_constraint * c ;
356+ match_f match_cb ;
357+
358+ if (streq (type , "and" ))
359+ match_cb = match_and ;
360+ else if (streq (type , "or" ))
361+ match_cb = match_or ;
362+ else /* streq (type, "not") */
363+ match_cb = match_not ;
364+
365+ if (!(c = list_constraint_new (match_cb , list_constraint_destructor , errp )))
366+ return NULL ;
367+
368+ json_array_foreach (values , index , entry ) {
369+ struct list_constraint * cp = list_constraint_create (entry , errp );
370+ if (!cp )
371+ goto error ;
372+ if (!zlistx_add_end (c -> values , cp )) {
373+ errprintf (errp , "Out of memory" );
374+ list_constraint_destroy (cp );
375+ goto error ;
376+ }
377+ }
378+ return c ;
379+
380+ error :
381+ list_constraint_destroy (c );
382+ return NULL ;
383+ }
384+
385385void list_constraint_destroy (struct list_constraint * constraint )
386386{
387387 if (constraint ) {
0 commit comments