Skip to content
This repository has been archived by the owner on May 14, 2024. It is now read-only.

Commit

Permalink
Reformat files with clang-format
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitry-kabanov committed Mar 14, 2024
1 parent 9cba966 commit a57922c
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 56 deletions.
48 changes: 21 additions & 27 deletions oif/dispatch.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,11 @@ static bool INITIALIZED_ = false;

static int IMPL_COUNTER_ = 1000;

size_t hash_fn(const ImplHandle *key) {
size_t
hash_fn(const ImplHandle *key)
{
if (*key < 0) {
fprintf(
stderr,
"[dispatch] Was expecting a non-negative number\n"
);
fprintf(stderr, "[dispatch] Was expecting a non-negative number\n");
exit(1);
}
return *key;
Expand Down Expand Up @@ -69,10 +68,10 @@ init_module_(void)
return 0;
}

ImplHandle load_interface_impl(const char *interface,
const char *impl,
size_t version_major,
size_t version_minor) {
ImplHandle
load_interface_impl(const char *interface, const char *impl, size_t version_major,
size_t version_minor)
{
if (!INITIALIZED_) {
int status = init_module_();
if (status) {
Expand Down Expand Up @@ -130,7 +129,8 @@ ImplHandle load_interface_impl(const char *interface,
if (buffer[len - 1] != '\n') {
fprintf(stderr, "Backend name is longer than allocated buffer\n");
goto cleanup;
} else {
}
else {
// Trim the new line character.
buffer[len - 1] = '\0';
}
Expand All @@ -148,7 +148,8 @@ ImplHandle load_interface_impl(const char *interface,
if (buffer[len - 1] != '\n') {
fprintf(stderr, "[dispatch] Backend name is longer than allocated array\n");
goto cleanup;
} else {
}
else {
// Trim new line character.
buffer[len - 1] = '\0';
}
Expand All @@ -163,10 +164,9 @@ ImplHandle load_interface_impl(const char *interface,
else if (strcmp(backend_name, "python") == 0) {
dh = OIF_LANG_PYTHON;
dispatch_lang_so = OIF_DISPATCH_PYTHON_SO;
} else {
fprintf(stderr,
"[dispatch] Implementation has unknown backend: '%s'\n",
backend_name);
}
else {
fprintf(stderr, "[dispatch] Implementation has unknown backend: '%s'\n", backend_name);
goto cleanup;
}

Expand All @@ -187,15 +187,11 @@ ImplHandle load_interface_impl(const char *interface,
load_impl_fn = dlsym(lib_handle, "load_impl");

if (load_impl_fn == NULL) {
fprintf(stderr,
"[dispatch] Could not load function %s: %s\n",
"load_impl",
dlerror());
fprintf(stderr, "[dispatch] Could not load function %s: %s\n", "load_impl", dlerror());
goto cleanup;
}

ImplInfo *impl_info =
load_impl_fn(impl_details, version_major, version_minor);
ImplInfo *impl_info = load_impl_fn(impl_details, version_major, version_minor);
if (impl_info == NULL) {
fprintf(stderr, "[dispatch] Could not load implementation\n");
goto cleanup;
Expand Down Expand Up @@ -246,10 +242,9 @@ unload_interface_impl(ImplHandle implh)
return 0;
}

int call_interface_impl(ImplHandle implh,
const char *method,
OIFArgs *in_args,
OIFArgs *out_args) {
int
call_interface_impl(ImplHandle implh, const char *method, OIFArgs *in_args, OIFArgs *out_args)
{
int status;

ImplInfo *impl_info = hashmap_get(&IMPL_MAP, &implh);
Expand All @@ -263,8 +258,7 @@ int call_interface_impl(ImplHandle implh,
}
void *lib_handle = OIF_DISPATCH_HANDLES[dh];

int (*call_impl_fn)(
ImplInfo *, const char *, OIFArgs *, OIFArgs *);
int (*call_impl_fn)(ImplInfo *, const char *, OIFArgs *, OIFArgs *);
call_impl_fn = dlsym(lib_handle, "call_impl");
if (call_impl_fn == NULL) {
fprintf(stderr,
Expand Down
6 changes: 2 additions & 4 deletions oif/include/oif/dispatch.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ unload_interface_impl(ImplHandle implh);
* @param out_args Array of output arguments
* @return status code that signals about an error if non-zero
*/
int call_interface_impl(ImplHandle implh,
const char *method,
OIFArgs *in_args,
OIFArgs *out_args);
int
call_interface_impl(ImplHandle implh, const char *method, OIFArgs *in_args, OIFArgs *out_args);
#endif
11 changes: 4 additions & 7 deletions oif/include/oif/dispatch_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,11 @@ typedef struct {
DispatchHandle dh;
} ImplInfo;

ImplInfo *load_impl(const char *impl_details,
size_t version_major,
size_t version_minor);
ImplInfo *
load_impl(const char *impl_details, size_t version_major, size_t version_minor);

int
unload_impl(ImplInfo *impl_info);

int call_impl(ImplInfo *impl_info,
const char *method,
OIFArgs *in_args,
OIFArgs *out_args);
int
call_impl(ImplInfo *impl_info, const char *method, OIFArgs *in_args, OIFArgs *out_args);
6 changes: 2 additions & 4 deletions oif/interfaces/c/src/ivp.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ oif_ivp_set_rhs_fn(ImplHandle implh, oif_ivp_rhs_fn_t rhs)
.arg_values = out_arg_values,
};

int status =
call_interface_impl(implh, "set_rhs_fn", &in_args, &out_args);
int status = call_interface_impl(implh, "set_rhs_fn", &in_args, &out_args);

return status;
}
Expand All @@ -51,8 +50,7 @@ oif_ivp_set_initial_value(ImplHandle implh, OIFArrayF64 *y0, double t0)
.arg_values = out_arg_values,
};

int status =
call_interface_impl(implh, "set_initial_value", &in_args, &out_args);
int status = call_interface_impl(implh, "set_initial_value", &in_args, &out_args);

return status;
}
Expand Down
13 changes: 6 additions & 7 deletions oif_impl/c/dispatch_c.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ typedef struct {

static int IMPL_COUNTER = 0;

ImplInfo *load_impl(const char *impl_details,
size_t version_major,
size_t version_minor) {
ImplInfo *
load_impl(const char *impl_details, size_t version_major, size_t version_minor)
{
// For C implementations, `impl_details` must contain the name
// of the shared library with the methods implemented as functions.
void *impl_lib = dlopen(impl_details, RTLD_LOCAL | RTLD_LAZY);
Expand Down Expand Up @@ -68,10 +68,9 @@ unload_impl(ImplInfo *impl_info_)
return 0;
}

int call_impl(ImplInfo *impl_info,
const char *method,
OIFArgs *in_args,
OIFArgs *out_args) {
int
call_impl(ImplInfo *impl_info, const char *method, OIFArgs *in_args, OIFArgs *out_args)
{
if (impl_info->dh != OIF_LANG_C) {
fprintf(stderr, "[dispatch_c] Provided implementation is not implemented in C\n");
return -1;
Expand Down
13 changes: 6 additions & 7 deletions oif_impl/python/dispatch_python.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ convert_oif_callback(OIFCallback *p)
return obj;
}

ImplInfo *load_impl(const char *impl_details,
size_t version_major,
size_t version_minor) {
ImplInfo *
load_impl(const char *impl_details, size_t version_major, size_t version_minor)
{
if (Py_IsInitialized()) {
fprintf(stderr, "[backend_python] Backend is already initialized\n");
}
Expand Down Expand Up @@ -178,10 +178,9 @@ ImplInfo *load_impl(const char *impl_details,
return (ImplInfo *)impl_info;
}

int call_impl(ImplInfo *impl_info,
const char *method,
OIFArgs *in_args,
OIFArgs *out_args) {
int
call_impl(ImplInfo *impl_info, const char *method, OIFArgs *in_args, OIFArgs *out_args)
{
if (impl_info->dh != OIF_LANG_PYTHON) {
fprintf(stderr, "[dispatch_python] Provided implementation is not in Python\n");
return -1;
Expand Down

0 comments on commit a57922c

Please sign in to comment.