Skip to content

Commit

Permalink
Bump C standard to C11 for using _Generic
Browse files Browse the repository at this point in the history
  • Loading branch information
awvwgk committed May 15, 2022
1 parent 5d2c914 commit edb9d84
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 17 deletions.
8 changes: 8 additions & 0 deletions include/xtb.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@
#define XTB_VERBOSITY_MINIMAL 1
#define XTB_VERBOSITY_MUTED 0

/// Convencience macro for deleting a handle
#define xtb_delete(ptr) _Generic((ptr), \
xtb_TEnvironment: xtb_delEnvironment, \
xtb_TMolecule: xtb_delMolecule, \
xtb_TCalculator: xtb_delCalculator, \
xtb_TResults: xtb_delResults \
)(&ptr)

#ifdef __cplusplus
extern "C" {
#else
Expand Down
2 changes: 1 addition & 1 deletion meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ project(
license: 'LGPL3',
meson_version: '>=0.55',
default_options: [
'includedir=include/xtb',
'buildtype=debugoptimized',
'default_library=both',
'optimization=2',
'c_std=c11',
],
)

Expand Down
32 changes: 16 additions & 16 deletions test/api/c_api_example.c
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,10 @@ int testFirst() {
if (!check(wbo[9], +2.89453979224265, 1.0e-8, "Bond order does not match"))
goto error;

xtb_delResults(&res);
xtb_delCalculator(&calc);
xtb_delMolecule(&mol);
xtb_delEnvironment(&env);
xtb_delete(res);
xtb_delete(calc);
xtb_delete(mol);
xtb_delete(env);

if (!check(!res, 1, "Results not deleted"))
goto error;
Expand All @@ -144,10 +144,10 @@ int testFirst() {

error:
xtb_showEnvironment(env, NULL);
xtb_delResults(&res);
xtb_delCalculator(&calc);
xtb_delMolecule(&mol);
xtb_delEnvironment(&env);
xtb_delete(res);
xtb_delete(calc);
xtb_delete(mol);
xtb_delete(env);
return 1;
}

Expand Down Expand Up @@ -260,10 +260,10 @@ int testSecond() {
if (xtb_checkEnvironment(env))
goto error;

xtb_delResults(&res);
xtb_delCalculator(&calc);
xtb_delMolecule(&mol);
xtb_delEnvironment(&env);
xtb_delete(res);
xtb_delete(calc);
xtb_delete(mol);
xtb_delete(env);

if (!check(pcgrad[0], 0.00000755, 1.0e-6, "pcgrad[0] does not match"))
goto error;
Expand All @@ -274,10 +274,10 @@ int testSecond() {

error:
xtb_showEnvironment(env, NULL);
xtb_delResults(&res);
xtb_delCalculator(&calc);
xtb_delMolecule(&mol);
xtb_delEnvironment(&env);
xtb_delete(res);
xtb_delete(calc);
xtb_delete(mol);
xtb_delete(env);
return 1;
}

Expand Down

0 comments on commit edb9d84

Please sign in to comment.