// Ref: http://sidvind.com/wiki/Opengl/windowless Glcontext_headless create_Glcontext_headless( void ) { /* open display */ Display *dpy = XOpenDisplay(NULL); if ( !dpy ) { error0( "Cannot connect to X server"); return NULL; } /* get root window */ Window root = DefaultRootWindow(dpy); /* get visual matching attr */ GLint attr[] = { GLX_RGBA, GLX_DEPTH_SIZE, 24, GLX_DOUBLEBUFFER, None }; XVisualInfo *vi = glXChooseVisual(dpy, 0, attr); if( !vi ) { error0("No appropriate visual found"); return NULL; } /* create a context using the root window */ GLXContext glc = glXCreateContext(dpy, vi, NULL, GL_TRUE); if ( !glc ) { error0("Failed to create context"); return NULL; } glXMakeCurrent(dpy, root, glc); return glc; }
int ac_lvc(int lc,int lv1,int lv2) { /* Assertion Check : Loop Variant check. */ if (lc == 0) { if (lv2 < 0) { #ifdef SE_EXCEPTIONS internal_exception_handler(Loop_variant); #else { char msg [64]; sprintf(msg,"Bad First Variant Value = %d\n",lv2); error0(msg,NULL); } #endif } else { return lv2; } } else if ((lv2 < 0) || (lv2 >= lv1)) { #ifdef SE_EXCEPTIONS internal_exception_handler(Loop_variant); #else { char msg [512]; sprintf(msg, "Bad loop variant.\nLoop body counter = %d (done)\n" "Previous Variant = %d\nNew Variant = %d\n", lc,lv1,lv2); error0(msg,NULL); } #endif } return lv2; }
scm_obj *port_close_output_port(const scm_obj *obj) { if (obj == scm_null || cdr(obj) != scm_null) { error0("procedure: close-output-port\nexpected: 1 argument\nbad argument(s)", obj); } else if (type(car(obj)) != OUTPORT) { error0("procedure: close-output-port\nexpected: output-port\nbad argument(s)", car(obj)); } else { FILE *fp = port(car(obj)); fclose(fp); return scm_unspecified; } }
int check_nargs(char *fname, SCM args, int min, int max) { if (!(IS_PAIR(args) || IS_NULL(args))) error0("wrong arguments"); int i; for (i = 0; IS_PAIR(args); i++) args = CDR(args); if (!IS_NULL(args)) error0("wrong arguments"); if (!((min <= i) && (i <= max))) wna_error(fname, i); return i; }
static int gui_x_io_error (Display *display) { /* * The X I/O error handling routine. * * Arguments: * "display" is the X display the error orignated from. * * Results: * An X I/O error basically means we lost our connection * to the X server. There is not much we can do to * continue, so simply print an error message and exit. * */ /* This is basically modelled after the code in XLib. We need * an explicit error handler here, so we can disable our atexit() * which would otherwise cause a nice segfault. */ if (errno == EPIPE) { fprintf(SE_ERR, "GUI-ERROR **: X connection to %s broken (explicit kill or server shutdown).\n", gdk_display ? DisplayString(gdk_display) : gdk_display_name); } else { fprintf(SE_ERR, "Gdk-ERROR **: Fatal IO error %d (%s) on X server %s.\n", errno, basic_gui_strerror(errno), gdk_display ? DisplayString(gdk_display) : gdk_display_name); } #ifdef SE_NO_CHECK error0("gui_x_io_error.", NULL); #endif exit(1); }
static int gui_x_error (Display *display, XErrorEvent *error) { /* * The X error handling routine. * * Arguments: * "display" is the X display the error orignated from. * "error" is the XErrorEvent that we are handling. * * Results: * Either we were expecting some sort of error to occur, * in which case we set the "gdk_error_code" flag, or this * error was unexpected, in which case we will print an * error message and exit. (Since trying to continue will * most likely simply lead to more errors). */ if (error->error_code) { { char buf[64]; XGetErrorText(display, error->error_code, buf, 63); fprintf(SE_ERR, "%s\n serial %ld error_code %d request_code %d minor_code %d\n", buf, error->serial, error->error_code, error->request_code, error->minor_code); } #ifdef SE_NO_CHECK error0("gui_x_error.", NULL); #endif return 0; } }
inline scm_obj *port_current_output_port(const scm_obj *obj) { if (obj != scm_null) { error0("procedure: current-output-port\nexpected: 0 argument\nbad argument(s)", obj); } else { return scm_cur_output_port; } }
inline scm_obj *port_pred_output_port(const scm_obj *obj) { if (obj == scm_null || cdr(obj) != scm_null) { error0("procedure: output-port?\nexpected: 1 argument\nbad argument(s)", obj); } else { return type(car(obj)) == OUTPORT ? scm_true : scm_false; } }
void ac_civ(int v,char*vv) { if (!v) { #ifdef SE_EXCEPTIONS internal_exception_handler(Check_instruction); #else error0("Check Assertion Violated.",vv); #endif } }
void ac_inv(int v,char*vv) { if (!v) { #ifdef SE_EXCEPTIONS internal_exception_handler(Class_invariant); #else error0("Class Invariant Violation.",vv); #endif } }
void ac_ens(int v,char*vv) { if (!v) { #ifdef SE_EXCEPTIONS internal_exception_handler(Postcondition); #else error0("Ensure Assertion Violated.",vv); #endif } }
void ac_req(int v,char*vv) { if (!v) { #ifdef SE_EXCEPTIONS internal_exception_handler(Precondition); #else error0("Require Assertion Violated.",vv); #endif } }
void ac_liv(int v,char*vv) { /* Assertion Check : Loop Invariant check. */ if (!v) { #ifdef SE_EXCEPTIONS internal_exception_handler(Loop_invariant); #else error0("Loop Invariant Violation.",vv); #endif } }
void destroy_Glcontext_headless( Glcontext_headless glc ) { /* open display */ Display *dpy = XOpenDisplay(NULL); if ( !dpy ) { error0( "Cannot connect to X server"); return; } glXDestroyContext( dpy, glc ); }
static void check_write(int expected, int actual) { if (actual != expected) { handle(SE_HANDLE_RUNTIME_ERROR, NULL); #ifdef SE_EXCEPTIONS internal_exception_handler(Routine_failure); #elif !defined(SE_BOOST) error0("Routine failure: could not write.", NULL); #else fprintf(SE_ERR,"Routine failure (write returned %d but expected %d).\n", actual, expected); exit(EXIT_FAILURE); #endif } }
scm_obj *port_open_output_file(const scm_obj *obj) { if (obj == scm_null || cdr(obj) != scm_null) { error0("procedure: open-output-file\nexpected: 1 argument\nbad argument(s)", obj); } else if (type(car(obj)) != STRING) { error0("procedure: open-output-file\nexpected: string\nbad argument(s)", car(obj)); } else { scm_obj *port_obj; char *name = str(car(obj)); FILE *fp = fopen(name, "w"); if (fp == NULL) { error0("procedure: open-output-file\ncan't open output file\nbad argument(s)", car(obj)); } else { port_obj = scm_alloc_obj(); type(port_obj) = OUTPORT; port(port_obj) = fp; return port_obj; } } }
// vector storage for PRECISION precision void vector_PRECISION_define( vector_PRECISION phi, complex_PRECISION value, int start, int end, level_struct *l ) { int thread = omp_get_thread_num(); if(thread == 0 && start != end) PROF_PRECISION_START( _SET ); if ( phi != NULL ) { int i; for ( i=start; i<end; i++ ) phi[i] = value; } else { error0("Error in \"vector_PRECISION_define\": pointer is null\n"); } if(thread == 0 && start != end) PROF_PRECISION_STOP( _SET, 1 ); }
void vector_PRECISION_define_random( vector_PRECISION phi, int start, int end, level_struct *l ) { int thread = omp_get_thread_num(); if(thread == 0 && start != end) PROF_PRECISION_START( _SET ); if ( phi != NULL ) { int i; for ( i=start; i<end; i++ ) phi[i] = (PRECISION)(((double)rand()/(double)RAND_MAX))-0.5 + ( (PRECISION)((double)rand()/(double)RAND_MAX)-0.5)*_Complex_I; } else { error0("Error in \"vector_PRECISION_define_random\": pointer is null\n"); } if(thread == 0 && start != end) PROF_PRECISION_STOP( _SET, 1 ); }