Exemple #1
0
void
PyErr_Display(PyObject *exception, PyObject *value, PyObject *tb)
{
    PyObject *seen;
    PyObject *f = _PySys_GetObjectId(&PyId_stderr);
    if (PyExceptionInstance_Check(value)
        && tb != NULL && PyTraceBack_Check(tb)) {
        /* Put the traceback on the exception, otherwise it won't get
           displayed.  See issue #18776. */
        PyObject *cur_tb = PyException_GetTraceback(value);
        if (cur_tb == NULL)
            PyException_SetTraceback(value, tb);
        else
            Py_DECREF(cur_tb);
    }
    if (f == Py_None) {
        /* pass */
    }
    else if (f == NULL) {
        _PyObject_Dump(value);
        fprintf(stderr, "lost sys.stderr\n");
    }
    else {
        /* We choose to ignore seen being possibly NULL, and report
           at least the main exception (it could be a MemoryError).
        */
        seen = PySet_New(NULL);
        if (seen == NULL)
            PyErr_Clear();
        print_exception_recursive(f, value, seen);
        Py_XDECREF(seen);
    }
}
Exemple #2
0
DEFINEFN void po_inlined_in(PsycoObject* po)
{
  if (po->pr.is_inlining)
    {
      fprintf(stderr, "inlined from position %d in\n",
              (int) (CompileTime_Get(po->vlocals.items[0]->
                                     array->items[1]->source)->value));
      _PyObject_Dump((PyObject*)
                     (CompileTime_Get(po->vlocals.items[0]->
                                      array->items[0]->source)->value));
    }
  else
    fprintf(stderr, "not inlined\n");
  if (&po_inlined_in) ;  /* force the compiler to consider it as used */
}
Exemple #3
0
ssize_t skull_module_unpack (void* md, skull_txn_t* txn,
                         const void* data, size_t data_len)
{
    PyGILState_STATE state = PyGILState_Ensure();
    module_data_t* mdata = (module_data_t*)md;

    // Prepare args
    PyObject* pyArgs = PyTuple_New(4);
    PyObject* pyModuleName = PyString_FromString(mdata->name);
    PyObject* pyEntryName  = PyString_FromString(MODULE_UNPACK_FUNCNAME);
    PyObject* pyTxn        = PyCapsule_New(txn, "skull_txn", NULL);
    PyObject* pyData       = PyString_FromStringAndSize((const char*)data,
                                                        (Py_ssize_t)data_len);

    PyTuple_SetItem(pyArgs, 0, pyModuleName);
    PyTuple_SetItem(pyArgs, 1, pyEntryName);
    PyTuple_SetItem(pyArgs, 2, pyTxn);
    PyTuple_SetItem(pyArgs, 3, pyData);

    // Call user module_unpack
    PyObject* pyConsumed = PyObject_CallObject(mdata->pyExecutorFunc, pyArgs);

    // Set to -1 by default, so if error occurred, like un-handled excpetions,
    //  then the entity will be destroyed soon
    ssize_t consumed = -1;

    if (!pyConsumed) {
        if (PyErr_Occurred()) PyErr_Print();
    } else {
        if (PyInt_Check(pyConsumed)) {
            consumed = PyInt_AsSsize_t(pyConsumed);
        } else if (PyLong_Check(pyConsumed)) {
            consumed = PyLong_AsSsize_t(pyConsumed);
        } else {
            fprintf(stderr, "Error: Cannot parse the pyConsumed object");
            _PyObject_Dump(pyConsumed);
        }
    }

    Py_XDECREF(pyConsumed);
    Py_DECREF(pyArgs);
    PyGILState_Release(state);
    return consumed;
}
Exemple #4
0
/* for debugging */
void
_PyGC_Dump(PyGC_Head *g)
{
	_PyObject_Dump(FROM_GC(g));
}