コード例 #1
0
ファイル: _yappi.c プロジェクト: sumerc/yappi
static void
_enum_threads(_ctx* (*f) (PyThreadState *))
{
    PyThreadState *ts;
    PyInterpreterState* is;

    for(is=PyInterpreterState_Head();is!=NULL;is = PyInterpreterState_Next(is))
    {
        for (ts=PyInterpreterState_ThreadHead(is) ; ts != NULL; ts = ts->next) {
            f(ts);
        }
    }
}
コード例 #2
0
ファイル: rootstate.c プロジェクト: 15580056814/hue
int
rootstate_traverse(NyHeapTraverse *ta)
{
    visitproc visit = ta->visit;
    NyHeapViewObject *hv = (void *)ta->hv;
    void *arg = ta->arg;
    PyThreadState *ts, *bts = PyThreadState_GET();
    PyInterpreterState *is;
    int err;

    for (is = PyInterpreterState_Head(); is; is = PyInterpreterState_Next(is)) {
	if (hv->is_hiding_calling_interpreter && is == bts->interp)
	  continue;
	VISIT(is->modules);
	VISIT(is->sysdict);
	VISIT(is->builtins);
	
#if PY_VERSION_HEX >= 0x020303f0
	VISIT(is->codec_search_path);
	VISIT(is->codec_search_cache);
	VISIT(is->codec_error_registry);
#endif	
	
	for (ts = is->tstate_head; ts; ts = ts->next) {
	    if (ts == bts && hv->limitframe) {
		VISIT(hv->limitframe);
	    } else if (!hv->limitframe) {
		VISIT(ts->frame);
	    }
	    VISIT(ts->c_profileobj);
	    VISIT(ts->c_traceobj);
	    VISIT(ts->curexc_type);
	    VISIT(ts->curexc_value);
	    VISIT(ts->curexc_traceback);
	    VISIT(ts->exc_type);
	    VISIT(ts->exc_value);
	    VISIT(ts->exc_traceback);
	    
	    VISIT(ts->dict);

#if PY_VERSION_HEX >= 0x020303f0
	    VISIT(ts->async_exc);
#endif	    

	      
	}
    }
    return 0;
}
コード例 #3
0
ファイル: pystate.c プロジェクト: tiran/cpython
static PyInterpreterState *
interp_look_up_id(PY_INT64_T requested_id)
{
    PyInterpreterState *interp = PyInterpreterState_Head();
    while (interp != NULL) {
        PY_INT64_T id = PyInterpreterState_GetID(interp);
        if (id < 0) {
            return NULL;
        }
        if (requested_id == id) {
            return interp;
        }
        interp = PyInterpreterState_Next(interp);
    }
    return NULL;
}
コード例 #4
0
ファイル: pystate.c プロジェクト: arizvisa/cpython
PyInterpreterState *
_PyInterpreterState_LookUpID(PY_INT64_T requested_id)
{
    if (requested_id < 0)
        goto error;

    PyInterpreterState *interp = PyInterpreterState_Head();
    while (interp != NULL) {
        PY_INT64_T id = PyInterpreterState_GetID(interp);
        if (id < 0)
            return NULL;
        if (requested_id == id)
            return interp;
        interp = PyInterpreterState_Next(interp);
    }

error:
    PyErr_Format(PyExc_RuntimeError,
                 "unrecognized interpreter ID %lld", requested_id);
    return NULL;
}
コード例 #5
0
ファイル: rootstate.c プロジェクト: 15580056814/hue
static PyObject *
rootstate_getattr(PyObject *obj, PyObject *name)
{
    char *s = PyString_AsString(name);
    PyInterpreterState *is;
    int ino;
    unsigned long tno;
    char buf[100];
    if (!s)
      return 0;
    if (sscanf(s, "i%d_%50s", &ino, buf) == 2) {
	int countis;
	int numis;
	for (is = PyInterpreterState_Head(), numis = 0;
	     is;
	     is = PyInterpreterState_Next(is), numis++)
	  ;
	for (is = PyInterpreterState_Head(), countis = 0;
	     is;
	     is = PyInterpreterState_Next(is), countis++) {
	    int isno = numis - countis - 1;
	    if (isno == ino) {
		PyObject *ret = PyMember_Get((char *)is, is_members, buf);
		if (!ret)
		  PyErr_Format(PyExc_AttributeError,
			       "interpreter state has no attribute '%s'",
			       buf);
		return ret;
	    }
	}
	PyErr_SetString(PyExc_AttributeError, "no such interpreter state number");
	return 0;
    }
    if (sscanf(s, "t%lu_%50s", &tno, buf) == 2) {
	for (is = PyInterpreterState_Head();
	     is;
	     is = PyInterpreterState_Next(is)) {
	    PyThreadState *ts;
	    for (ts = is->tstate_head; ts; ts = ts->next) {
		if (THREAD_ID(ts) == tno) {
		    int frameno = 0;
		    if (sscanf(buf, "f%d", &frameno) == 1) {
			PyFrameObject *frame;
			int numframes = 0;
			for (frame = ts->frame; frame; frame = frame->f_back) {
			    numframes ++;
			}
			for (frame = ts->frame; frame; frame = frame->f_back) {
			    numframes --;
			    if (numframes == frameno) {
				Py_INCREF(frame);
				return (PyObject *)frame;
			    }
			}
			PyErr_Format(PyExc_AttributeError,
				     "thread state has no frame numbered %d from bottom",
				     frameno);
			return 0;
		    } else {
			PyObject *ret = PyMember_Get((char *)ts, ts_members, buf);
			if (!ret)
			  PyErr_Format(PyExc_AttributeError,
				       "thread state has no attribute '%s'",
				       buf);
			return ret;
		    }
		}
	    }
	}
		
    }
    PyErr_Format(PyExc_AttributeError, "root state has no attribute '%.200s'", s);
    return 0;
}
コード例 #6
0
ファイル: rootstate.c プロジェクト: 15580056814/hue
static int
rootstate_relate(NyHeapRelate *r)
{
    NyHeapViewObject *hv = (void *)r->hv;
    PyThreadState *ts,  *bts = PyThreadState_GET();
    PyInterpreterState *is;
    int isframe = PyFrame_Check(r->tgt);
    int isno;
    for (is = PyInterpreterState_Head(), isno = 0;
	 is;
	 is = PyInterpreterState_Next(is), isno++)
      ;
    for (is = PyInterpreterState_Head(), isno--;
	 is;
	 is = PyInterpreterState_Next(is), isno--) {
	char buf[100];
	ISATTR(modules);
	ISATTR(sysdict);
	ISATTR(builtins);
#if PY_VERSION_HEX >= 0x020303f0
	ISATTR(codec_search_path);
	ISATTR(codec_search_cache);
	ISATTR(codec_error_registry);
#endif	

	for (ts = is->tstate_head; ts; ts = ts->next) {
	    if ((ts == bts && r->tgt == hv->limitframe) ||
		(!hv->limitframe && isframe)) {
		int frameno = -1;
		int numframes = 0;
		PyFrameObject *frame;
		for (frame = (PyFrameObject *)ts->frame; frame; frame = frame->f_back) {
		    numframes ++;
		    if (r->tgt == (PyObject *)frame)
		      frameno = numframes;
		}
		if (frameno != -1) {
		    frameno = numframes - frameno;
		    sprintf(buf,"t%lu_f%d", THREAD_ID(ts), frameno);
		    if (r->visit(NYHR_ATTRIBUTE, PyString_FromString(buf), r))
		      return 1;
		}
	    }
	    TSATTR(ts, c_profileobj);
	    TSATTR(ts, c_traceobj);
	    TSATTR(ts, curexc_type);
	    TSATTR(ts, curexc_value);
	    TSATTR(ts, curexc_traceback);
	    TSATTR(ts, exc_type);
	    TSATTR(ts, exc_value);
	    TSATTR(ts, exc_traceback);
	    
	    TSATTR(ts, dict);
#if PY_VERSION_HEX >= 0x020303f0
	    TSATTR(ts, async_exc);
#endif
	      
	}
    }
    return 0;
}