// Parses the value of the active python exception
// NOTE SHOULD NOT BE CALLED IF NO EXCEPTION
std::string parse_python_exception(){
    PyObject *type_ptr = NULL, *value_ptr = NULL, *traceback_ptr = NULL;
    // Fetch the exception info from the Python C API
    PyErr_Fetch(&type_ptr, &value_ptr, &traceback_ptr);

    // Fallback error
    std::string ret("Unfetchable Python error");
    // If the fetch got a type pointer, parse the type into the exception string
    if(type_ptr != NULL){
        py::handle<> h_type(type_ptr);
        py::str type_pstr(h_type);
        // Extract the string from the boost::python object
        py::extract<std::string> e_type_pstr(type_pstr);
        // If a valid string extraction is available, use it 
        //  otherwise use fallback
        if(e_type_pstr.check())
            ret = e_type_pstr();
        else
            ret = "Unknown exception type";
    }
    // Do the same for the exception value (the stringification of the exception)
    if(value_ptr != NULL){
        py::handle<> h_val(value_ptr);
        py::str a(h_val);
        py::extract<std::string> returned(a);
        if(returned.check())
            ret +=  ": " + returned();
        else
            ret += std::string(": Unparseable Python error: ");
    }
    // Parse lines from the traceback using the Python traceback module
    if(traceback_ptr != NULL){
        py::handle<> h_tb(traceback_ptr);
        // Load the traceback module and the format_tb function
        py::object tb(py::import("traceback"));
        py::object fmt_tb(tb.attr("format_tb"));
        // Call format_tb to get a list of traceback strings
        py::object tb_list(fmt_tb(h_tb));
        // Join the traceback strings into a single string
        py::object tb_str(py::str("\n").join(tb_list));
        // Extract the string, check the extraction, and fallback in necessary
        py::extract<std::string> returned(tb_str);
        if(returned.check())
            ret += ": " + returned();
        else
            ret += std::string(": Unparseable Python traceback");
    }
    return ret;
}
Beispiel #2
0
std::wstring PyError::get_python_error_description()
{
	std::wstring ret = L"Unfetchable Python error";

	PyObject *type_ptr = NULL, *value_ptr = NULL, *traceback_ptr = NULL;
    PyErr_Fetch(&type_ptr, &value_ptr, &traceback_ptr);
    
	if(type_ptr != NULL)
	{
		py::handle<> h_type(type_ptr);
		py::str type_pstr(h_type);
		py::extract<std::wstring> e_type_pstr(type_pstr);
		if(e_type_pstr.check())
			ret = e_type_pstr();
		else
			ret = L"Unknown exception type";
	}

	if(value_ptr != NULL)
	{
		py::handle<> h_val(value_ptr);
		py::str a(h_val);
		py::extract<std::wstring> returned(a);
		if(returned.check())
			ret +=  L": " + returned();
		else
			ret += L": Unparseable Python error: ";
	}

	if(traceback_ptr != NULL)
	{
		py::handle<> h_tb(traceback_ptr);
		py::object tb(py::import("traceback"));
		py::object fmt_tb(tb.attr("format_tb"));
		py::object tb_list(fmt_tb(h_tb));
		py::object tb_str(py::str("\n").join(tb_list));
		py::extract<std::wstring> returned(tb_str);
		if(returned.check())
			ret += L": " + returned();
		else
			ret += L": Unparseable Python traceback";
	}

	return ret;
}
Beispiel #3
0
// -------------------------------------------------------------------
// ToFloatArray
// -------------------------------------------------------------------
boost::shared_ptr<vector<float> > Vec3D::ToFloatArray()
{
	boost::shared_ptr<vector<float> > returned (new vector<float>());
	returned->push_back(fx);
	returned->push_back(fy);
	returned->push_back(fz);

	return returned;
}
Beispiel #4
0
// -------------------------------------------------------------------
// ToIntArray
// -------------------------------------------------------------------
boost::shared_ptr<vector<long int> > Vec3D::ToIntArray()
{
	boost::shared_ptr<vector<long int> > returned (new vector<long int>());
	returned->push_back(ix);
	returned->push_back(iy);
	returned->push_back(iz);

	return returned;
}
Beispiel #5
0
SearchBar::SearchBar(QWidget* parent)
    : QLineEdit(parent)
    , m_suggestionBox(new SuggestionBox(this))
{
    connect(this, SIGNAL(textChanged(const QString&)),
        m_suggestionBox, SLOT(searchBarChanged(const QString&)));
    connect(this, SIGNAL(returnPressed()),
        m_suggestionBox, SLOT(returned()));
    QLineEdit::resize(600, sizeHint().height());
}
Beispiel #6
0
profiling_sample_count profiling_sample_count::record_counts() volatile {
  atomic::fence();
  profiling_sample_count returned(sample_count, gc_sample_count,
                                  jit_sample_count, foreign_sample_count,
                                  foreign_thread_sample_count);
  atomic::fetch_subtract(&sample_count, returned.sample_count);
  atomic::fetch_subtract(&gc_sample_count, returned.gc_sample_count);
  atomic::fetch_subtract(&jit_sample_count, returned.jit_sample_count);
  atomic::fetch_subtract(&foreign_sample_count, returned.foreign_sample_count);
  atomic::fetch_subtract(&foreign_thread_sample_count,
                         returned.foreign_thread_sample_count);
  return returned;
}
Beispiel #7
0
// -------------------------------------------------------------------
// ToString
// -------------------------------------------------------------------
boost::shared_ptr<string> SFSUserVariable::ToString()
{
	char buffer[512];

	switch (type)
	{
	case VARIABLETYPE_UNKNOWN:
		sprintf (buffer, "[UVar: %s, type: %d, value: Unknown]", name->c_str(), type);
		break;

	case VARIABLETYPE_NULL:
		sprintf (buffer, "[UVar: %s, type: %d, value: NULL]", name->c_str(), type);
		break;

	case VARIABLETYPE_BOOL:
		sprintf (buffer, "[UVar: %s, type: %d, value: %d]", name->c_str(), type, *(boost::static_pointer_cast<bool>(val)));
		break;

	case VARIABLETYPE_INT:
		sprintf (buffer, "[UVar: %s, type: %d, value: %d]", name->c_str(), type, *(boost::static_pointer_cast<long int>(val)));
		break;

	case VARIABLETYPE_DOUBLE:
		sprintf (buffer, "[UVar: %s, type: %d, value: %d]", name->c_str(), type, *(boost::static_pointer_cast<double>(val)));
		break;

	case VARIABLETYPE_STRING:
		sprintf (buffer, "[UVar: %s, type: %d, value: %s]", name->c_str(), type, (boost::static_pointer_cast<string>(val))->c_str());
		break;

	case VARIABLETYPE_OBJECT:
		sprintf (buffer, "[UVar: %s, type: %d, value: object]", name->c_str(), type);
		break;

	case VARIABLETYPE_ARRAY:
		sprintf (buffer, "[UVar: %s, type: %d, value: array]", name->c_str(), type);
		break;
	}

	boost::shared_ptr<string>returned (new string(buffer));

	return returned;
}