{
if (check_PackageStatus(self))
return -1;
- if (!PyString_Check(value)) {
- PyErr_SetString(PyExc_ValueError, "String expected!");
+ if (!PyString_Check(value) && value != Py_None) {
+ PyErr_SetString(PyExc_ValueError, "String or None expected!");
return -1;
}
cr_Package *pkg = self->package;
+ if (value == Py_None) {
+ // If value is None exist right now (avoid possibly
+ // creation of a string chunk)
+ *((char **) ((size_t) pkg + (size_t) member_offset)) = NULL;
+ return 0;
+ }
+
// Check if chunk exits
// If it doesn't - this is package from loaded metadata and all its
// strings are in a metadata common chunk (cr_Metadata->chunk).
{
if (check_RepomdRecordStatus(self))
return -1;
- if (!PyString_Check(value)) {
- PyErr_SetString(PyExc_ValueError, "String expected!");
+ if (!PyString_Check(value) && value != Py_None) {
+ PyErr_SetString(PyExc_ValueError, "String or None expected!");
return -1;
}
cr_RepomdRecord *rec = self->record;
- char *str = g_string_chunk_insert(rec->chunk, PyString_AsString(value));
+ char *str = cr_safe_string_chunk_insert(rec->chunk,
+ PyObject_ToStrOrNull(value));
*((char **) ((size_t) rec + (size_t) member_offset)) = str;
return 0;
}