HIDE void* errJNI(const char *err, ...) { char msg[512]; va_list ap; #ifndef RJ_DEBUG /* non-debug version goes straight to ckx - it should never return */ ckx(NULL); #endif va_start(ap, err); msg[511]=0; vsnprintf(msg, 511, err, ap); #ifdef RJ_DEBUG Rf_warning(msg); #else Rf_error(msg); /* this never returns and is just a fallback in case ckx doesn't return */ #endif va_end(ap); checkExceptionsX(getJNIEnv(), 0); return 0; }
void Wind::localon() { int evt=0; int mask=0; XSetWindowAttributes attributes; XGCValues gcv; XGetGCValues(dsp,gtbknd(),GCForeground,&gcv); attributes.background_pixel=gcv.foreground; mask|=CWBackPixel; if(pixmap) { attributes.background_pixmap=pixmap; mask|=CWBackPixmap; } if(cursor) { attributes.cursor=cursor; mask|=CWCursor; } // FIXME! /* if(x->funcs->expose || x->target && x->target->funcs->expose) evt|=ExposureMask; if(x->funcs->enternotify || x->target && x->target->funcs->enternotify) evt|=EnterWindowMask; if(x->funcs->leavenotify || x->target && x->target->funcs->leavenotify) evt|=LeaveWindowMask; if(x->funcs->buttonpress || x->target && x->target->funcs->buttonpress) evt|=ButtonPressMask; if(x->funcs->buttonrelease || x->target && x->target->funcs->buttonrelease) evt|=ButtonReleaseMask; if(x->funcs->motionnotify || x->target && x->target->funcs->motionnotify) evt|=ButtonMotionMask; if(x->funcs->keypress || x->target && x->target->funcs->keypress) evt|=KeyPressMask|KeyReleaseMask; if(x->funcs->configurenotify && gtmom(x)==gtmain(root)) evt|=StructureNotifyMask; if(x->funcs->focusin || x->funcs->focusout) evt|=FocusChangeMask; */ evt|=ExposureMask; evt|=EnterWindowMask; evt|=LeaveWindowMask; evt|=ButtonReleaseMask; evt|=ButtonMotionMask; evt|=KeyPressMask; evt|=KeyReleaseMask; evt|=StructureNotifyMask; evt|=FocusChangeMask; evt|=ButtonPressMask; attributes.event_mask=evt; mask|=CWEventMask; if(override_flag) { attributes.override_redirect=1; } else attributes.override_redirect=0; mask|=CWOverrideRedirect; /* Create window */ win=XCreateWindow(dsp,gtmom()->gtwin(),gtx(),gty(),gtwidth(),gtheight(),0, CopyFromParent,InputOutput,CopyFromParent, mask,&attributes); /* Duh, this should be the default */ if(in==root->gtmain()) hintinput(target,True); if(in==root->gtmain() && ckx() && cky()) { hintposition(target,gtx(),gty()); } if(target && target->hints) sendhints(win,target->hints); if(transient_flag) XSetTransientForHint(dsp,win,gtmom()->gtwin()); /* Map and raise window */ XMapRaised(dsp,win); if(XSaveContext(dsp,win,wins,(XPointer)this)) { printf("Error\n"); exit(1); } }
/* check for exceptions and throw them to R level */ HIDE void ckx(JNIEnv *env) { SEXP xr, xobj, msg = 0, xclass = 0; /* note: we don't bother counting protections becasue we never return */ jthrowable x = 0; if (env && !(x = (*env)->ExceptionOccurred(env))) return; if (!env) { env = getJNIEnv(); if (!env) error("Unable to retrieve JVM environment."); ckx(env); return; } /* env is valid and an exception occurred */ /* we create the jobj first, because the exception may in theory disappear after being cleared, yet this can be (also in theory) risky as it uses further JNI calls ... */ xobj = j2SEXP(env, x, 0); (*env)->ExceptionClear(env); /* grab the list of class names (without package path) */ SEXP clazzes = PROTECT( getSimpleClassNames_asSEXP( (jobject)x, (jboolean)1 ) ) ; /* ok, now this is a critical part that we do manually to avoid recursion */ { jclass cls = (*env)->GetObjectClass(env, x); if (cls) { jstring cname; jmethodID mid = (*env)->GetMethodID(env, cls, "toString", "()Ljava/lang/String;"); if (mid) { jstring s = (jstring)(*env)->CallObjectMethod(env, x, mid); if (s) { const char *c = (*env)->GetStringUTFChars(env, s, 0); if (c) { msg = PROTECT(mkString(c)); (*env)->ReleaseStringUTFChars(env, s, c); } } } /* beside toString() we also need to call getName() on cls to get the subclass */ cname = (jstring) (*env)->CallObjectMethod(env, cls, mid_getName); if (cname) { const char *c = (*env)->GetStringUTFChars(env, cname, 0); if (c) { /* convert full class name to JNI notation */ char *cn = strdup(c), *d = cn; while (*d) { if (*d == '.') *d = '/'; d++; } xclass = mkString(cn); free(cn); (*env)->ReleaseStringUTFChars(env, cname, c); } (*env)->DeleteLocalRef(env, cname); } if ((*env)->ExceptionOccurred(env)) (*env)->ExceptionClear(env); (*env)->DeleteLocalRef(env, cls); } else (*env)->ExceptionClear(env); if (!msg) msg = PROTECT(mkString("Java Exception <no description because toString() failed>")); } /* delete the local reference to the exception (jobjRef has a global copy) */ (*env)->DeleteLocalRef(env, x); /* construct the jobjRef */ xr = PROTECT(NEW_OBJECT(MAKE_CLASS("jobjRef"))); if (inherits(xr, "jobjRef")) { SET_SLOT(xr, install("jclass"), xclass ? xclass : mkString("java/lang/Throwable")); SET_SLOT(xr, install("jobj"), xobj); } /* and off to R .. (we're keeping xr and clazzes protected) */ throwR(msg, xr, clazzes); /* throwR never returns so don't even bother ... */ }