Exemplo n.º 1
0
void friend_cleanup(Tox *tox)
{
    uint32_t friend_count = tox_self_get_friend_list_size(tox);

    if (friend_count == 0) {
        return;
    }

    uint32_t friends[friend_count];
    tox_self_get_friend_list(tox, friends);

    uint64_t curr_time = time(NULL);
    for (uint32_t i = 0; i < friend_count; i++) {
        TOX_ERR_FRIEND_GET_LAST_ONLINE err;
        uint32_t friend = friends[i];
        uint64_t last_online = tox_friend_get_last_online(tox, friend, &err);

        if (err != TOX_ERR_FRIEND_GET_LAST_ONLINE_OK) {
            yerr("couldn't obtain 'last online', this should never happen\n");
            continue;
        }

        if (curr_time - last_online > 2629743) {
            yinfo("removing friend %d\n", friend);
            tox_friend_delete(tox, friend, NULL);
        }
    }
Exemplo n.º 2
0
static uintptr_t
_current_context_id(PyThreadState *ts)
{
    uintptr_t rc;
    PyObject *callback_rc;
    if (context_id_callback) {
        callback_rc = PyObject_CallFunctionObjArgs(context_id_callback, NULL);
        if (!callback_rc) {
            PyErr_Print();
            goto error;
        }
        rc = (uintptr_t)PyLong_AsLong(callback_rc);
        Py_DECREF(callback_rc);
        if (PyErr_Occurred()) {
            yerr("context id callback returned non-integer");
            goto error;
        }
        return rc;
    } else {
        // Use thread_id instead of ts pointer, because when we create/delete many threads, some
        // of them do not show up in the thread_stats, because ts pointers are recycled in the VM.
        // Also, OS tids are recycled, too. The only valid way is to give ctx's custom tids which
        // are hold in a per-thread structure. Again: we use an integer instead of directly mapping the ctx
        // pointer to some per-thread structure because other threading libraries do not necessarily
        // have direct ThreadState->Thread mapping. Greenlets, for example, will only have a single
        // thread. Therefore, we need to identify the "context" concept independent from ThreadState 
        // objects.

        // TODO: Any more optimization? This has increased the runtime factor from 7x to 11x.
        // and also we may have a memory leak below. We maybe can optimize the common case.
        PyObject *d = PyThreadState_GetDict();
        PyObject *ytid = PyDict_GetItemString(d, "_yappi_tid");
        if (!ytid) {
            ytid = PyLong_FromLong(ycurthreadindex++);
            PyDict_SetItemString(d, "_yappi_tid", ytid);
        }
        rc = PyLong_AsLong(ytid);
        return rc;
    }

error:
    PyErr_Clear();
    Py_CLEAR(context_id_callback); // don't use callback again
    return 0;
}
Exemplo n.º 3
0
static PyObject *
_current_context_name(void)
{
    PyObject *name;

    if (!context_name_callback) {
        return NULL;
    }

    name = PyObject_CallFunctionObjArgs(context_name_callback, NULL);
    if (!name) {
        PyErr_Print();
        goto err;
    }

    if (name == Py_None) {
        // Name not available yet - will try again on the next call
        goto later;
    }

    if (!PyStr_Check(name)) {
        yerr("context name callback returned non-string");
        goto err;
    }

    return name;

err:
    PyErr_Clear();
    Py_CLEAR(context_name_callback);  /* Don't use the callback again. */
    Py_XDECREF(name);
    return NULL;
later:
    Py_XDECREF(name);
    return NULL;
}
Exemplo n.º 4
0
void MainWindow::setupLogErrorsTest(QCustomPlot *customPlot)
{
	customPlot->yAxis->setScaleType(QCPAxis::stLogarithmic);
	customPlot->yAxis->setSubTickCount(8);
	customPlot->yAxis->grid()->setSubGridVisible(true);
	int n = 11;
	QVector<double> x(n), y(n), yerr(n), xerr(n);
	for (int i=0; i<n; ++i)
	{
		x[i] = i;
		y[i] = i*0.1;
		yerr[i] = 0.5;
		xerr[i] = qAbs(qCos(i/2.0)*0.5);
	}
	customPlot->addGraph();
	customPlot->graph()->setScatterStyle(QCPScatterStyle::ssCross);
	customPlot->graph()->setDataBothError(x, y, xerr, yerr);
	customPlot->graph()->setErrorType(QCPGraph::etBoth);
	customPlot->graph()->setErrorBarSkipSymbol(true);

	//customPlot->rescaleAxes();
	customPlot->xAxis->setRange(0, 10);
	customPlot->yAxis->setRange(1, 10);
}
Exemplo n.º 5
0
static void
_log_err(unsigned int code)
{
    yerr("Internal Error. [%u]", code);
}