@@ -595,12 +595,12 @@ int CeedSetData(Ceed ceed, void *data) {
595595/// @{
596596
597597/**
598- @brief Get the list of avaliable resource names for Ceed contexts
598+ @brief Get the list of available resource names for Ceed contexts
599599 Note: The caller is responsible for `free()`ing the resources and priorities arrays,
600600 but should not `free()` the contents of the resources array.
601601
602- @param[out] n Number of avaliable resources
603- @param[out] resources List of avaliable resource names
602+ @param[out] n Number of available resources
603+ @param[out] resources List of available resource names
604604 @param[out] priorities Resource name prioritization values, lower is better
605605
606606 @return An error code: 0 - success, otherwise - failure
@@ -610,7 +610,7 @@ int CeedSetData(Ceed ceed, void *data) {
610610// LCOV_EXCL_START
611611int CeedRegistryGetList (size_t * n , char * * * const resources ,
612612 CeedInt * * priorities ) {
613- * n = num_backends ;
613+ * n = 0 ;
614614 * resources = malloc (num_backends * sizeof (* * resources ));
615615 if (!resources )
616616 return CeedError (NULL , CEED_ERROR_MAJOR , "malloc() failure" );
@@ -620,8 +620,20 @@ int CeedRegistryGetList(size_t *n, char ***const resources,
620620 return CeedError (NULL , CEED_ERROR_MAJOR , "malloc() failure" );
621621 }
622622 for (size_t i = 0 ; i < num_backends ; i ++ ) {
623- * resources [i ] = backends [i ].prefix ;
624- if (priorities ) * priorities [i ] = backends [i ].priority ;
623+ // Only report compiled backends
624+ if (backends [i ].priority < CEED_MAX_BACKEND_PRIORITY ) {
625+ * resources [i ] = backends [i ].prefix ;
626+ if (priorities ) * priorities [i ] = backends [i ].priority ;
627+ * n += 1 ;
628+ }
629+ }
630+ * resources = realloc (* resources , * n * sizeof (* * resources ));
631+ if (!resources )
632+ return CeedError (NULL , CEED_ERROR_MAJOR , "realloc() failure" );
633+ if (priorities ) {
634+ * priorities = realloc (* priorities , * n * sizeof (* * priorities ));
635+ if (!priorities )
636+ return CeedError (NULL , CEED_ERROR_MAJOR , "realloc() failure" );
625637 }
626638 return CEED_ERROR_SUCCESS ;
627639};
@@ -631,7 +643,7 @@ int CeedRegistryGetList(size_t *n, char ***const resources,
631643 @brief Initialize a \ref Ceed context to use the specified resource.
632644 Note: Prefixing the resource with "help:" (e.g. "help:/cpu/self")
633645 will result in CeedInt printing the current libCEED version number
634- and a list of current avaliable backend resources to stderr.
646+ and a list of current available backend resources to stderr.
635647
636648 @param resource Resource to use, e.g., "/cpu/self"
637649 @param ceed The library context
@@ -643,7 +655,8 @@ int CeedRegistryGetList(size_t *n, char ***const resources,
643655**/
644656int CeedInit (const char * resource , Ceed * ceed ) {
645657 int ierr ;
646- size_t match_len = 0 , match_idx = UINT_MAX , match_priority = UINT_MAX , priority ;
658+ size_t match_len = 0 , match_idx = UINT_MAX ,
659+ match_priority = CEED_MAX_BACKEND_PRIORITY , priority ;
647660
648661 // Find matching backend
649662 if (!resource )
@@ -661,9 +674,11 @@ int CeedInit(const char *resource, Ceed *ceed) {
661674 fprintf (stderr , "libCEED version: %d.%d%d%s\n" , CEED_VERSION_MAJOR ,
662675 CEED_VERSION_MINOR , CEED_VERSION_PATCH ,
663676 CEED_VERSION_RELEASE ? "" : "+development" );
664- fprintf (stderr , "Avaliable backend resources:\n" );
677+ fprintf (stderr , "Available backend resources:\n" );
665678 for (size_t i = 0 ; i < num_backends ; i ++ ) {
666- fprintf (stderr , " %s\n" , backends [i ].prefix );
679+ // Only report compiled backends
680+ if (backends [i ].priority < CEED_MAX_BACKEND_PRIORITY )
681+ fprintf (stderr , " %s\n" , backends [i ].prefix );
667682 }
668683 fflush (stderr );
669684 match_help = 5 ; // Delineating character expected
@@ -694,7 +709,7 @@ int CeedInit(const char *resource, Ceed *ceed) {
694709 // LCOV_EXCL_STOP
695710 } else if (match_len != stem_length ) {
696711 // LCOV_EXCL_START
697- return CeedError (NULL , CEED_ERROR_MAJOR , "No suitable backend: %s "
712+ return CeedError (NULL , CEED_ERROR_MAJOR , "No suitable backend: %s\n "
698713 "Closest match: %s" , resource , backends [match_idx ].prefix );
699714 // LCOV_EXCL_STOP
700715 }
0 commit comments