Skip to content
Snippets Groups Projects
Commit b392c57a authored by Jonathan Lambrechts's avatar Jonathan Lambrechts
Browse files

error code as last argument in c api

parent ac219c32
No related branches found
No related tags found
No related merge requests found
...@@ -420,10 +420,10 @@ class API: ...@@ -420,10 +420,10 @@ class API:
f.write("\n") f.write("\n")
f.write("/* gmsh"+module.name+" */\n") f.write("/* gmsh"+module.name+" */\n")
for rtype, name, args in module.fs: for rtype, name, args in module.fs:
f.write("GMSH_API int gmshc" + module.name+name+"("+", ".join( f.write("GMSH_API "+(rtype.rtype_c if rtype else "void"))
list((a.c for a in args))) + f.write(" gmshc" + module.name+name+"("
((", "+rtype.rtype_c + " *result") if rtype else "") + +", ".join(list((a.c for a in args+(oint("ierr"),))))
");\n") + ");\n")
f.write(c_footer) f.write(c_footer)
with open(filename+".cc","w") as f: with open(filename+".cc","w") as f:
...@@ -432,22 +432,21 @@ class API: ...@@ -432,22 +432,21 @@ class API:
f.write("\n") f.write("\n")
f.write("/* gmsh"+module.name+" */\n") f.write("/* gmsh"+module.name+" */\n")
for rtype, name, args in module.fs: for rtype, name, args in module.fs:
#rt = rtype.rtype_c if rtype else "void" f.write(rtype.rtype_c if rtype else "void")
f.write("int gmshc" + module.name+name+"("+", ".join( f.write(" gmshc" + module.name+name+"("
list((a.c for a in args)))+ +", ".join(list((a.c for a in args+(oint("ierr"),))))+"){\n")
((", "+rtype.rtype_c + " *result") if rtype else "") + if rtype:
"){\n" f.write(" "+ rtype.rtype_c + " result_api_;\n")
) f.write("if(ierr) *ierr = 0;\n");
f.write(" try {\n"); f.write(" try {\n");
f.write("".join((a.c_cpp_pre for a in args))) f.write("".join((a.c_cpp_pre for a in args)))
if rtype: if rtype:
f.write(rtype.rtype_c + " result_api_ = ") f.write(" result_api_ = ")
f.write(" gmsh" + module.name+name+"("+", ".join( f.write(" gmsh" + module.name+name+"("+", ".join(
list((a.c_cpp_arg for a in args)))+ list((a.c_cpp_arg for a in args)))+
");\n") ");\n")
if rtype:
f.write("if(result) *result = result_api_;\n")
f.write("".join((a.c_cpp_post for a in args))) f.write("".join((a.c_cpp_post for a in args)))
f.write(" } catch(int api_ierr_) {return api_ierr_;}\n"); f.write(" } catch(int api_ierr_) {if (ierr) *ierr = api_ierr_;}\n");
f.write(" return 0;\n"); if rtype :
f.write(" return result_api_;\n");
f.write("}\n\n") f.write("}\n\n")
#include <stdio.h> #include <stdio.h>
#include "gmshc.h" #include "gmshc.h"
#define chk(ierr) if (ierr != 0) {fprintf(stderr, "ERROR on line %i in function '%s': gmsh function return non-zero error code: %i\n",__LINE__, __FUNCTION__,ierr); gmshcFinalize(); exit(ierr);} #define chk(ierr) if (ierr != 0) {fprintf(stderr, "ERROR on line %i in function '%s': gmsh function return non-zero error code: %i\n",__LINE__, __FUNCTION__,ierr); gmshcFinalize(NULL); exit(ierr);}
void genGeometry() { void genGeometry() {
int ierr; int ierr;
ierr = gmshcModelCreate("square"); gmshcModelCreate("square",&ierr);chk(ierr);
ierr = gmshcModelGeoAddPoint(0,0,0,0.1,1,NULL);chk(ierr); gmshcModelGeoAddPoint(0,0,0,0.1,1,&ierr);chk(ierr);
ierr = gmshcModelGeoAddPoint(1,0,0,0.1,2,NULL);chk(ierr); gmshcModelGeoAddPoint(1,0,0,0.1,2,&ierr);chk(ierr);
ierr = gmshcModelGeoAddPoint(1,1,0,0.1,3,NULL);chk(ierr); gmshcModelGeoAddPoint(1,1,0,0.1,3,&ierr);chk(ierr);
ierr = gmshcModelGeoAddPoint(0,1,0,0.1,4,NULL);chk(ierr); gmshcModelGeoAddPoint(0,1,0,0.1,4,&ierr);chk(ierr);
ierr = gmshcModelGeoAddLine(1,2,1,NULL); chk(ierr); gmshcModelGeoAddLine(1,2,1,&ierr); chk(ierr);
ierr = gmshcModelGeoAddLine(2,3,2,NULL); chk(ierr); gmshcModelGeoAddLine(2,3,2,&ierr); chk(ierr);
ierr = gmshcModelGeoAddLine(3,4,3,NULL); chk(ierr); gmshcModelGeoAddLine(3,4,3,&ierr); chk(ierr);
// try automatic assignement of tag // try automatic assignement of tag
int line4; int line4 = gmshcModelGeoAddLine(4,1,-1,&ierr); chk(ierr);
ierr = gmshcModelGeoAddLine(4,1,-1,&line4); chk(ierr);
printf("line4 received tag %i\n\n", line4); printf("line4 received tag %i\n\n", line4);
int ll[] = {1,2,3,line4}; int ll[] = {1,2,3,line4};
ierr = gmshcModelGeoAddLineLoop(ll,4,1,NULL); chk(ierr); gmshcModelGeoAddLineLoop(ll,4,1,&ierr); chk(ierr);
int s[] = {1}; int s[] = {1};
ierr = gmshcModelGeoAddPlaneSurface(ll,1,6,NULL); chk(ierr); gmshcModelGeoAddPlaneSurface(ll,1,6,&ierr); chk(ierr);
ierr = gmshcModelGeoSynchronize(); chk(ierr); gmshcModelGeoSynchronize(&ierr); chk(ierr);
} }
void printMesh() { void printMesh() {
...@@ -29,13 +28,13 @@ void printMesh() { ...@@ -29,13 +28,13 @@ void printMesh() {
int *dimTags; int *dimTags;
size_t ndimTags; size_t ndimTags;
ierr = gmshcModelGetEntities(&dimTags, &ndimTags, -1); chk(ierr); gmshcModelGetEntities(&dimTags, &ndimTags, -1,&ierr); chk(ierr);
for (size_t ie = 0; ie < ndimTags/2; ++ie) { for (size_t ie = 0; ie < ndimTags/2; ++ie) {
int *types, **elementTags, **vertexTags; int *types, **elementTags, **vertexTags;
size_t ntypes, *nelementTags, nnelementTags, *nvertexTags, nnvertexTags; size_t ntypes, *nelementTags, nnelementTags, *nvertexTags, nnvertexTags;
ierr = gmshcModelGetMeshElements(dimTags[ie*2+0], dimTags[ie*2+1], &types, &ntypes, &elementTags, &nelementTags, &nnelementTags, &vertexTags, &nvertexTags, &nnvertexTags); chk(ierr); gmshcModelGetMeshElements(dimTags[ie*2+0], dimTags[ie*2+1], &types, &ntypes, &elementTags, &nelementTags, &nnelementTags, &vertexTags, &nvertexTags, &nnvertexTags,&ierr); chk(ierr);
printf("entity %i of dim %i\n", dimTags[ie*2+1], dimTags[ie*2+0]); printf("entity %i of dim %i\n", dimTags[ie*2+1], dimTags[ie*2+0]);
for (size_t i = 0; i < nnelementTags; ++i) { for (size_t i = 0; i < nnelementTags; ++i) {
...@@ -66,16 +65,16 @@ void printMesh() { ...@@ -66,16 +65,16 @@ void printMesh() {
void genError() { void genError() {
int ierr; int ierr;
printf("\n** generate an error **\n"); printf("\n** generate an error **\n");
ierr = gmshcModelGetMeshElements(999, 999, NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL); chk(ierr); gmshcModelGetMeshElements(999, 999, NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,&ierr); chk(ierr);
} }
int main(int argc, char **argv) { int main(int argc, char **argv) {
int ierr; int ierr;
gmshcInitialize(argc, argv); gmshcInitialize(argc, argv);
genGeometry(); genGeometry();
ierr = gmshcModelMesh(2); chk(ierr); gmshcModelMesh(2,&ierr); chk(ierr);
ierr = gmshcExport("square.msh"); chk(ierr); gmshcExport("square.msh",&ierr); chk(ierr);
printMesh(); printMesh();
genError(); genError();
ierr = gmshcFinalize(); chk(ierr); gmshcFinalize(&ierr); chk(ierr);
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment