Exemple #1
0
inline void JyErr_InsertCurExc()
{
	PyThreadState *tstate = PyThreadState_GET();
	env();
	(*env)->CallStaticVoidMethod(env, JyNIClass, JyNIJyErr_InsertCurExc,
			TS_GET_JY(tstate),
			JyNI_JythonPyObject_FromPyObject(tstate->curexc_type),
			JyNI_JythonPyObject_FromPyObject(tstate->curexc_value),
			JyNI_JythonPyObject_FromPyObject(tstate->curexc_traceback));
}
Exemple #2
0
PyFrameObject *
PyFrame_New(PyThreadState *tstate, PyCodeObject *code, PyObject *globals,
			PyObject *locals)
{
	jobject builtins = NULL, back = NULL, f;
//	puts(__FUNCTION__);
	env(NULL);

	if (tstate)
	{
		jobject jts = TS_GET_JY(tstate);
		back = (*env)->GetObjectField(env, jts, pyThreadState_frameField);
		builtins = (*env)->GetObjectField(env, back, pyFrame_f_builtinsField);
	}
	f = (*env)->NewObject(env, pyFrameClass, pyFrame_Constructor,
			JyNI_JythonPyObject_FromPyObject(code),
			JyNI_JythonPyObject_FromPyObject(locals),
			JyNI_JythonPyObject_FromPyObject(globals),
			builtins);
	if (back)
		(*env)->SetObjectField(env, f, pyFrame_f_backField, back);
	return (PyFrameObject*) JyNI_PyObject_FromJythonPyObject(f);

//	PyFrameObject *back = tstate->frame;PyTraceBack_Here
//	PyFrameObject *f;
//	PyObject *builtins;
//	Py_ssize_t i;
//
//#ifdef Py_DEBUG
//	if (code == NULL || globals == NULL || !PyDict_Check(globals) ||
//		(locals != NULL && !PyMapping_Check(locals))) {
//		PyErr_BadInternalCall();
//		return NULL;
//	}
//#endif
//	if (back == NULL || back->f_globals != globals) {
//		builtins = PyDict_GetItem(globals, builtin_object);
//		if (builtins) {
//			if (PyModule_Check(builtins)) {
//				builtins = PyModule_GetDict(builtins);
//				assert(!builtins || PyDict_Check(builtins));
//			}
//			else if (!PyDict_Check(builtins))
//				builtins = NULL;
//		}
//		if (builtins == NULL) {
//			/* No builtins!              Make up a minimal one
//			   Give them 'None', at least. */
//			builtins = PyDict_New();
//			if (builtins == NULL ||
//				PyDict_SetItemString(
//					builtins, "None", Py_None) < 0)
//				return NULL;
//		}
//		else
//			Py_INCREF(builtins);
//
//	}
//	else {
//		/* If we share the globals, we share the builtins.
//		   Save a lookup and a call. */
//		builtins = back->f_builtins;
//		assert(builtins != NULL && PyDict_Check(builtins));
//		Py_INCREF(builtins);
//	}
//	if (code->co_zombieframe != NULL) {
//		f = code->co_zombieframe;
//		code->co_zombieframe = NULL;
//		_Py_NewReference((PyObject *)f);
//		assert(f->f_code == code);
//	}
//	else {
//		Py_ssize_t extras, ncells, nfrees;
//		ncells = PyTuple_GET_SIZE(code->co_cellvars);
//		nfrees = PyTuple_GET_SIZE(code->co_freevars);
//		extras = code->co_stacksize + code->co_nlocals + ncells +
//			nfrees;
//		if (free_list == NULL) {
//			f = PyObject_GC_NewVar(PyFrameObject, &PyFrame_Type,
//			extras);
//			if (f == NULL) {
//				Py_DECREF(builtins);
//				return NULL;
//			}
//		}
//		else {
//			assert(numfree > 0);
//			--numfree;
//			f = free_list;
//			free_list = free_list->f_back;
//			if (Py_SIZE(f) < extras) {
//				f = PyObject_GC_Resize(PyFrameObject, f, extras);
//				if (f == NULL) {
//					Py_DECREF(builtins);
//					return NULL;
//				}
//			}
//			_Py_NewReference((PyObject *)f);
//		}
//
//		f->f_code = code;
//		extras = code->co_nlocals + ncells + nfrees;
//		f->f_valuestack = f->f_localsplus + extras;
//		for (i=0; i<extras; i++)
//			f->f_localsplus[i] = NULL;
//		f->f_locals = NULL;
//		f->f_trace = NULL;
//		f->f_exc_type = f->f_exc_value = f->f_exc_traceback = NULL;
//	}
//	f->f_stacktop = f->f_valuestack;
//	f->f_builtins = builtins;
//	Py_XINCREF(back);
//	f->f_back = back;
//	Py_INCREF(code);
//	Py_INCREF(globals);
//	f->f_globals = globals;
//	/* Most functions have CO_NEWLOCALS and CO_OPTIMIZED set. */
//	if ((code->co_flags & (CO_NEWLOCALS | CO_OPTIMIZED)) ==
//		(CO_NEWLOCALS | CO_OPTIMIZED))
//		; /* f_locals = NULL; will be set by PyFrame_FastToLocals() */
//	else if (code->co_flags & CO_NEWLOCALS) {
//		locals = PyDict_New();
//		if (locals == NULL) {
//			Py_DECREF(f);
//			return NULL;
//		}
//		f->f_locals = locals;
//	}
//	else {
//		if (locals == NULL)
//			locals = globals;
//		Py_INCREF(locals);
//		f->f_locals = locals;
//	}
//	f->f_tstate = tstate;
//
//	f->f_lasti = -1;
//	f->f_lineno = code->co_firstlineno;
//	f->f_iblock = 0;
//
//	_PyObject_GC_TRACK(f);
//	return f;
}