Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the SystemError when no type specific clipboard content exists #920

Merged
merged 2 commits into from Mar 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
42 changes: 37 additions & 5 deletions src_c/scrap.c
Expand Up @@ -203,7 +203,6 @@ _scrap_get_scrap(PyObject *self, PyObject *args)
char *scrap = NULL;
PyObject *retval;
char *scrap_type;
PyObject *val;
unsigned long count;

PYGAME_SCRAP_INIT_CHECK();
Expand All @@ -212,17 +211,50 @@ _scrap_get_scrap(PyObject *self, PyObject *args)
return NULL;

if (!pygame_scrap_lost()) {
/* We are still the active one. */
/* Still own the clipboard. */
PyObject *scrap_dict = NULL;
PyObject *key = NULL;
PyObject *val = NULL;

switch (_currentmode) {
case SCRAP_SELECTION:
val = PyDict_GetItemString(_selectiondata, scrap_type);
scrap_dict = _selectiondata;
break;

case SCRAP_CLIPBOARD:
default:
val = PyDict_GetItemString(_clipdata, scrap_type);
scrap_dict = _clipdata;
break;
}
Py_XINCREF(val);

#if PY3
key = PyUnicode_FromString(scrap_type);
if (NULL == key) {
return PyErr_Format(PyExc_ValueError,
"invalid scrap data type identifier (%s)",
scrap_type);
}

val = PyDict_GetItemWithError(scrap_dict, key);
Py_DECREF(key);

if (NULL == val) {
if (PyErr_Occurred()) {
return PyErr_Format(PyExc_SystemError,
"pygame.scrap internal error (key=%s)",
scrap_type);
}

Py_RETURN_NONE;
}
#else /* !PY3 */
val = PyDict_GetItemString(scrap_dict, scrap_type);
if (NULL == val) {
Py_RETURN_NONE;
}
#endif /* !PY3 */

Py_INCREF(val);
return val;
}

Expand Down
3 changes: 0 additions & 3 deletions test/scrap_test.py
Expand Up @@ -41,9 +41,6 @@ def todo_test_get(self):
"""Ensures get works as expected."""
self.fail()

# The @unittest.expectedFailure decorator can be removed when issue #915
# is resolved.
@unittest.expectedFailure
def test_get__owned_empty_type(self):
"""Ensures get works when there is no data of the requested type
in the clipboard and the clipboard is owned by the pygame application.
Expand Down