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:
f.write("\n")
f.write("/* gmsh"+module.name+" */\n")
for rtype, name, args in module.fs:
f.write("GMSH_API int gmshc" + module.name+name+"("+", ".join(
list((a.c for a in args))) +
((", "+rtype.rtype_c + " *result") if rtype else "") +
");\n")
f.write("GMSH_API "+(rtype.rtype_c if rtype else "void"))
f.write(" gmshc" + module.name+name+"("
+", ".join(list((a.c for a in args+(oint("ierr"),))))
+ ");\n")
f.write(c_footer)
with open(filename+".cc","w") as f:
......@@ -432,22 +432,21 @@ class API:
f.write("\n")
f.write("/* gmsh"+module.name+" */\n")
for rtype, name, args in module.fs:
#rt = rtype.rtype_c if rtype else "void"
f.write("int gmshc" + module.name+name+"("+", ".join(
list((a.c for a in args)))+
((", "+rtype.rtype_c + " *result") if rtype else "") +
"){\n"
)
f.write(rtype.rtype_c if rtype else "void")
f.write(" gmshc" + module.name+name+"("
+", ".join(list((a.c for a in args+(oint("ierr"),))))+"){\n")
if rtype:
f.write(" "+ rtype.rtype_c + " result_api_;\n")
f.write("if(ierr) *ierr = 0;\n");
f.write(" try {\n");
f.write("".join((a.c_cpp_pre for a in args)))
if rtype:
f.write(rtype.rtype_c + " result_api_ = ")
f.write(" result_api_ = ")
f.write(" gmsh" + module.name+name+"("+", ".join(
list((a.c_cpp_arg for a in args)))+
");\n")
if rtype:
f.write("if(result) *result = result_api_;\n")
f.write("".join((a.c_cpp_post for a in args)))
f.write(" } catch(int api_ierr_) {return api_ierr_;}\n");
f.write(" return 0;\n");
f.write(" } catch(int api_ierr_) {if (ierr) *ierr = api_ierr_;}\n");
if rtype :
f.write(" return result_api_;\n");
f.write("}\n\n")
#include <stdio.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() {
int ierr;
ierr = gmshcModelCreate("square");
ierr = gmshcModelGeoAddPoint(0,0,0,0.1,1,NULL);chk(ierr);
ierr = gmshcModelGeoAddPoint(1,0,0,0.1,2,NULL);chk(ierr);
ierr = gmshcModelGeoAddPoint(1,1,0,0.1,3,NULL);chk(ierr);
ierr = gmshcModelGeoAddPoint(0,1,0,0.1,4,NULL);chk(ierr);
ierr = gmshcModelGeoAddLine(1,2,1,NULL); chk(ierr);
ierr = gmshcModelGeoAddLine(2,3,2,NULL); chk(ierr);
ierr = gmshcModelGeoAddLine(3,4,3,NULL); chk(ierr);
gmshcModelCreate("square",&ierr);chk(ierr);
gmshcModelGeoAddPoint(0,0,0,0.1,1,&ierr);chk(ierr);
gmshcModelGeoAddPoint(1,0,0,0.1,2,&ierr);chk(ierr);
gmshcModelGeoAddPoint(1,1,0,0.1,3,&ierr);chk(ierr);
gmshcModelGeoAddPoint(0,1,0,0.1,4,&ierr);chk(ierr);
gmshcModelGeoAddLine(1,2,1,&ierr); chk(ierr);
gmshcModelGeoAddLine(2,3,2,&ierr); chk(ierr);
gmshcModelGeoAddLine(3,4,3,&ierr); chk(ierr);
// try automatic assignement of tag
int line4;
ierr = gmshcModelGeoAddLine(4,1,-1,&line4); chk(ierr);
int line4 = gmshcModelGeoAddLine(4,1,-1,&ierr); chk(ierr);
printf("line4 received tag %i\n\n", 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};
ierr = gmshcModelGeoAddPlaneSurface(ll,1,6,NULL); chk(ierr);
ierr = gmshcModelGeoSynchronize(); chk(ierr);
gmshcModelGeoAddPlaneSurface(ll,1,6,&ierr); chk(ierr);
gmshcModelGeoSynchronize(&ierr); chk(ierr);
}
void printMesh() {
......@@ -29,13 +28,13 @@ void printMesh() {
int *dimTags;
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) {
int *types, **elementTags, **vertexTags;
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]);
for (size_t i = 0; i < nnelementTags; ++i) {
......@@ -66,16 +65,16 @@ void printMesh() {
void genError() {
int ierr;
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 ierr;
gmshcInitialize(argc, argv);
genGeometry();
ierr = gmshcModelMesh(2); chk(ierr);
ierr = gmshcExport("square.msh"); chk(ierr);
gmshcModelMesh(2,&ierr); chk(ierr);
gmshcExport("square.msh",&ierr); chk(ierr);
printMesh();
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.
Please register or to comment