xref: /libCEED/rust/libceed-sys/c-src/backends/weak/ceed-backend-weak.c (revision b1c579f084fff6512b7ecdc5f1776714eaea68ae)
1*d1503016SJeremy L Thompson // Copyright (c) 2017-2026, Lawrence Livermore National Security, LLC and other CEED contributors.
2*d1503016SJeremy L Thompson // All Rights Reserved. See the top-level LICENSE and NOTICE files for details.
3*d1503016SJeremy L Thompson //
4*d1503016SJeremy L Thompson // SPDX-License-Identifier: BSD-2-Clause
5*d1503016SJeremy L Thompson //
6*d1503016SJeremy L Thompson // This file is part of CEED:  http://github.com/ceed
7*d1503016SJeremy L Thompson 
8*d1503016SJeremy L Thompson #include "ceed-backend-weak.h"
9*d1503016SJeremy L Thompson #include <ceed.h>
10*d1503016SJeremy L Thompson #include <ceed/backend.h>
11*d1503016SJeremy L Thompson #include <stdarg.h>
12*d1503016SJeremy L Thompson 
13*d1503016SJeremy L Thompson // LCOV_EXCL_START
14*d1503016SJeremy L Thompson // This function provides improved error messages for uncompiled backends
CeedInit_Weak(const char * resource,Ceed ceed)15*d1503016SJeremy L Thompson static int CeedInit_Weak(const char *resource, Ceed ceed) {
16*d1503016SJeremy L Thompson   return CeedError(ceed, CEED_ERROR_UNSUPPORTED, "Backend not currently compiled: %s\nConsult the installation instructions to compile this backend",
17*d1503016SJeremy L Thompson                    resource);
18*d1503016SJeremy L Thompson }
19*d1503016SJeremy L Thompson 
20*d1503016SJeremy L Thompson // This function provides a debug target for weak symbols
CeedRegister_Weak(const char * name,int num_prefixes,...)21*d1503016SJeremy L Thompson int CeedRegister_Weak(const char *name, int num_prefixes, ...) {
22*d1503016SJeremy L Thompson   va_list prefixes;
23*d1503016SJeremy L Thompson   int     ierr;
24*d1503016SJeremy L Thompson 
25*d1503016SJeremy L Thompson   va_start(prefixes, num_prefixes);
26*d1503016SJeremy L Thompson   for (int i = 0; i < num_prefixes; i++) {
27*d1503016SJeremy L Thompson     const char *prefix = va_arg(prefixes, const char *);
28*d1503016SJeremy L Thompson 
29*d1503016SJeremy L Thompson     CeedDebugEnv("Weak Register   : %s", prefix);
30*d1503016SJeremy L Thompson     ierr = CeedRegisterImpl(prefix, CeedInit_Weak, CEED_MAX_BACKEND_PRIORITY);
31*d1503016SJeremy L Thompson     if (ierr) {
32*d1503016SJeremy L Thompson       va_end(prefixes);  // Prevent leak on error
33*d1503016SJeremy L Thompson       return ierr;
34*d1503016SJeremy L Thompson     }
35*d1503016SJeremy L Thompson   }
36*d1503016SJeremy L Thompson   va_end(prefixes);
37*d1503016SJeremy L Thompson   return CEED_ERROR_SUCCESS;
38*d1503016SJeremy L Thompson }
39*d1503016SJeremy L Thompson // LCOV_EXCL_STOP
40