Exemple #1
0
static PyObject *
pygst_debug_log (PyObject * pyobject, PyObject * string, GstDebugLevel level,
    gboolean isgstobject)
{
#ifndef GST_DISABLE_GST_DEBUG
  gchar *str;
  gchar *function;
  gchar *filename;
  int lineno;
  PyFrameObject *frame;
  GObject *object = NULL;

  if (!PyArg_ParseTuple (string, "s:gst.debug_log", &str)) {
    PyErr_SetString (PyExc_TypeError, "Need a string!");
    return NULL;
  }

  frame = PyEval_GetFrame ();
  function = PyString_AsString (frame->f_code->co_name);
  filename =
      g_path_get_basename (PyString_AsString (frame->f_code->co_filename));
  lineno = PyCode_Addr2Line (frame->f_code, frame->f_lasti);
  /* gst_debug_log : category, level, file, function, line, object, format, va_list */
  if (isgstobject)
    object = G_OBJECT (pygobject_get (pyobject));
  gst_debug_log (python_debug, level, filename, function, lineno, object,
      "%s", str);
  if (filename)
    g_free (filename);
#endif
  Py_INCREF (Py_None);
  return Py_None;
}
Exemple #2
0
/* Declared in pyerrors.h */
int
PyErr_CheckSignals(void)
{
	int i;
	PyObject *f;

	if (!is_tripped)
		return 0;
#ifdef WITH_THREAD
	if (PyThread_get_thread_ident() != main_thread)
		return 0;
#endif
	if (!(f = (PyObject *)PyEval_GetFrame()))
		f = Py_None;
	
	for (i = 1; i < NSIG; i++) {
		if (Handlers[i].tripped) {
			PyObject *result = NULL;
			PyObject *arglist = Py_BuildValue("(iO)", i, f);
			Handlers[i].tripped = 0;

			if (arglist) {
				result = PyEval_CallObject(Handlers[i].func,
							   arglist);
				Py_DECREF(arglist);
			}
			if (!result)
				return -1;

			Py_DECREF(result);
		}
	}
	is_tripped = 0;
	return 0;
}
// Return the current class info list.
QList<ClassInfo> qpycore_get_class_info_list()
{
    PyFrameObject *frame = PyEval_GetFrame();
    QList<ClassInfo> class_info_list = class_info_hash.values(frame);

    class_info_hash.remove(frame);

    return class_info_list;
}
Exemple #4
0
PyObject *
PyEval_GetBuiltins(void)
{
	PyFrameObject *current_frame = PyEval_GetFrame();
	if (current_frame == NULL) {
		return PyThreadState_Get()->interp->builtins;
	}
	else {
		return current_frame->f_builtins;
	}
}
Exemple #5
0
PyObject* local(PyObject* self, PyObject* name) {
    PyFrameObject* frame = PyEval_GetFrame();
    PyObject* result = find_local_in_frame(frame, name);

    if(!result) {
        PyErr_SetString(PyExc_AttributeError, PyString_AsString(name));
        return NULL;
    }

    return result;
}
Exemple #6
0
/* Declared in pyerrors.h */
int
PyErr_CheckSignals(void)
{
	int i;
	PyObject *f;

	if (!is_tripped)
		return 0;

#ifdef WITH_THREAD
	if (PyThread_get_thread_ident() != main_thread)
		return 0;
#endif

	/*
	 * The is_stripped variable is meant to speed up the calls to
	 * PyErr_CheckSignals (both directly or via pending calls) when no
	 * signal has arrived. This variable is set to 1 when a signal arrives
	 * and it is set to 0 here, when we know some signals arrived. This way
	 * we can run the registered handlers with no signals blocked.
	 *
	 * NOTE: with this approach we can have a situation where is_tripped is
	 *       1 but we have no more signals to handle (Handlers[i].tripped
	 *       is 0 for every signal i). This won't do us any harm (except
	 *       we're gonna spent some cycles for nothing). This happens when
	 *       we receive a signal i after we zero is_tripped and before we
	 *       check Handlers[i].tripped.
	 */
	is_tripped = 0;

	if (!(f = (PyObject *)PyEval_GetFrame()))
		f = Py_None;

	for (i = 1; i < NSIG; i++) {
		if (Handlers[i].tripped) {
			PyObject *result = NULL;
			PyObject *arglist = Py_BuildValue("(iO)", i, f);
			Handlers[i].tripped = 0;

			if (arglist) {
				result = PyEval_CallObject(Handlers[i].func,
							   arglist);
				Py_DECREF(arglist);
			}
			if (!result)
				return -1;

			Py_DECREF(result);
		}
	}

	return 0;
}
PyObject *
is_frame_utf8(PyObject* self, PyObject* args)
{
    PyFrameObject *frame = PyEval_GetFrame();
    while (frame != NULL) {
        if (!(PyFrame_Check(frame)
                && is_utf8(frame->f_code->co_filename)
                && is_utf8(frame->f_code->co_name))) {
            Py_RETURN_FALSE;
        }
        frame = frame->f_back;
    }
    Py_RETURN_TRUE;
}
Exemple #8
0
// are we currently within a 'try' block (even transitively for ANY
// function on stack?)
int transitively_within_try_block() {
  PyFrameObject* f = PyEval_GetFrame();
  while (f) {
    int i;
    for (i = 0; i < f->f_iblock; i++) {
      PyTryBlock* b = &f->f_blockstack[i];
      if (b->b_type == SETUP_FINALLY || b->b_type == SETUP_EXCEPT) {
        return 1;
      }
    }

    f = f->f_back;
  }

  return 0;
}
Exemple #9
0
PyObject *PythonContext::outstream_write(PyObject *self, PyObject *args)
{
  const char *text = NULL;

  if(!PyArg_ParseTuple(args, "z:write", &text))
    return NULL;

  if(PyErr_Occurred())
    return NULL;

  OutputRedirector *redirector = (OutputRedirector *)self;

  if(redirector)
  {
    PythonContext *context = redirector->context;
    // most likely this is NULL because the sys.stdout override is static and shared amongst
    // contexts. So look up the global variable that stores the context
    if(context == NULL)
    {
      _frame *frame = PyEval_GetFrame();

      while(frame)
      {
        PyObject *globals = frame->f_globals;
        if(globals)
        {
          OutputRedirector *global =
              (OutputRedirector *)PyDict_GetItemString(globals, "_renderdoc_internal");
          if(global)
            context = global->context;
        }

        if(context)
          break;

        frame = frame->f_back;
      }
    }

    if(context)
    {
      context->addText(redirector->isStdError ? true : false, QString::fromUtf8(text));
    }
  }

  Py_RETURN_NONE;
}
Exemple #10
0
void log_NA_event(const char* event_name) {
  PyFrameObject* f = PyEval_GetFrame();

  // stolen from frame_getlineno in Objects/frameobject.c
  int lineno;
  if (f->f_trace)
    lineno = f->f_lineno;
  else
    lineno = PyCode_Addr2Line(f->f_code, f->f_lasti);


  PG_LOG_PRINTF("{%s | %s %s:%d}\n",
                event_name,
                PyString_AsString(f->f_code->co_filename),
                PyString_AsString(f->f_code->co_name),
                lineno);
}
// Add the given name/value pair to the current class info hash.
PyObject *qpycore_ClassInfo(const char *name, const char *value)
{
    PyFrameObject *frame = PyEval_GetFrame();

    // We need the frame we were called from, not the current one.
    if (frame)
        frame = frame->f_back;

    if (!frame)
    {
        PyErr_SetString(PyExc_RuntimeError, "no current frame");
        return 0;
    }

    class_info_hash.insert(frame,
            ClassInfo(QByteArray(name), QByteArray(value)));

    Py_INCREF(Py_None);
    return Py_None;
}
Exemple #12
0
 /**
  * Is the given function name in the call stack
  * @param name :: The name of the function call to search for
  * @param startFrame :: An optional frame to start from, if NULL then the current frame is
  * retrieved from the interpreter
  * @return True if the function name is found in the stack, false otherwise
  */
 bool isInCallStack(const char * name, PyFrameObject* startFrame)
 {
   PyFrameObject *frame = startFrame;
   if( !frame ) frame = PyEval_GetFrame(); // current frame
   if( !frame ) return false;
   bool inStack(false);
   if( strcmp(PyString_AsString(frame->f_code->co_name), name) == 0)
   {
     inStack = true;
   }
   else
   {
     while(frame->f_back)
     {
       frame = frame->f_back;
       if( strcmp(PyString_AsString(frame->f_code->co_name), name) == 0 )
       {
         inStack = true;
         break;
       }
     }
   }
   return inStack;
 }
Exemple #13
0
/* Traverse stack backwards to find the nearest valid _script object in globals */
PyObject *pyloader_find_script_obj(void)
{
    PyFrameObject *frame;

    for (frame = PyEval_GetFrame(); frame != NULL; frame = frame->f_back)
    {
        PyObject *script;

        g_return_val_if_fail(frame->f_globals != NULL, NULL);
        script = PyDict_GetItemString(frame->f_globals, "_script");

        if (script && pyscript_check(script))
        {
            /*
            PySys_WriteStdout("Found script at %s in %s, script -> 0x%x\n",
                    PyString_AS_STRING(frame->f_code->co_name), 
                    PyString_AS_STRING(frame->f_code->co_filename), script);
            */
            return script;
        }
    }

    return NULL;
}