Beispiel #1
0
static StructRNA *pointer_type_from_py(PyObject *value, const char *error_prefix)
{
	StructRNA *srna;

	srna= srna_from_self(value, "");
	if(!srna) {
		if(PyErr_Occurred()) {
			PyObject *msg= PyC_ExceptionBuffer();
			char *msg_char= _PyUnicode_AsString(msg);
			PyErr_Format(PyExc_TypeError,
			             "%.200s expected an RNA type derived from PropertyGroup, failed with: %s",
			             error_prefix, msg_char);
			Py_DECREF(msg);
		}
		else {
			PyErr_Format(PyExc_TypeError,
			             "%.200s expected an RNA type derived from PropertyGroup, failed with type '%s'",
			             error_prefix, Py_TYPE(value)->tp_name);
		}
		return NULL;
	}

	if(!RNA_struct_is_a(srna, &RNA_PropertyGroup)) {
		PyErr_Format(PyExc_TypeError,
		             "%.200s expected an RNA type derived from PropertyGroup",
		             error_prefix);
		return NULL;
	}

	return srna;
}
Beispiel #2
0
short BPy_errors_to_report(ReportList *reports)
{
	PyObject *pystring;
	PyObject *pystring_format = NULL;  /* workaround, see below */
	char *cstring;

	const char *filename;
	int lineno;

	if (!PyErr_Occurred())
		return 1;
	
	/* less hassle if we allow NULL */
	if (reports == NULL) {
		PyErr_Print();
		PyErr_Clear();
		return 1;
	}
	
	pystring = PyC_ExceptionBuffer();
	
	if (pystring == NULL) {
		BKE_report(reports, RPT_ERROR, "Unknown py-exception, could not convert");
		return 0;
	}
	
	PyC_FileAndNum(&filename, &lineno);
	if (filename == NULL)
		filename = "<unknown location>";
	
	cstring = _PyUnicode_AsString(pystring);

#if 0 /* ARG!. workaround for a bug in blenders use of vsnprintf */
	BKE_reportf(reports, RPT_ERROR, "%s\nlocation: %s:%d\n", cstring, filename, lineno);
#else
	pystring_format = PyUnicode_FromFormat(TIP_("%s\nlocation: %s:%d\n"), cstring, filename, lineno);
	cstring = _PyUnicode_AsString(pystring_format);
	BKE_report(reports, RPT_ERROR, cstring);
#endif

	/* not exactly needed. just for testing */
	fprintf(stderr, TIP_("%s\nlocation: %s:%d\n"), cstring, filename, lineno);

	Py_DECREF(pystring);
	Py_DECREF(pystring_format);  /* workaround */
	return 1;
}