Skip to content

Commit

Permalink
fix #2325: fix compilation on PyPy
Browse files Browse the repository at this point in the history
  • Loading branch information
giampaolo committed Nov 9, 2023
1 parent 902fada commit ccdb775
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
5 changes: 5 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ XXXX-XX-XX
- 2324_: enforce Ruff rule `raw-string-in-exception`, which helps providing
clearer tracebacks when exceptions are raised by psutil.

**Bug fixes**

- 2325_, [PyPy]: psutil did not compile on PyPy due to missing
`PyErr_SetExcFromWindowsErrWithFilenameObject` cPython API.

5.9.6
=====

Expand Down
12 changes: 12 additions & 0 deletions psutil/_psutil_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,18 @@ PyErr_SetFromWindowsErrWithFilename(int winerr, const char *filename) {
#endif // !defined(PyErr_SetFromWindowsErrWithFilename)


#if !defined(PyErr_SetExcFromWindowsErrWithFilenameObject)
PyObject *
PyErr_SetExcFromWindowsErrWithFilenameObject(PyObject *type,
int ierr,
PyObject *filename) {
// Original function is too complex. Just raise OSError without
// filename.
return PyErr_SetFromWindowsErrWithFilename(ierr, NULL);
}
#endif // !defined(PyErr_SetExcFromWindowsErrWithFilenameObject)


// PyPy 2.7
#if !defined(PyErr_SetFromWindowsErr)
PyObject *
Expand Down
14 changes: 9 additions & 5 deletions psutil/_psutil_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,15 @@ static const int PSUTIL_CONN_NONE = 128;
#define PyUnicode_DecodeFSDefaultAndSize PyString_FromStringAndSize
#endif

#if defined(PSUTIL_WINDOWS) && \
defined(PYPY_VERSION) && \
!defined(PyErr_SetFromWindowsErrWithFilename)
PyObject *PyErr_SetFromWindowsErrWithFilename(int ierr,
const char *filename);
#if defined(PSUTIL_WINDOWS) && defined(PYPY_VERSION)
#if !defined(PyErr_SetFromWindowsErrWithFilename)
PyObject *PyErr_SetFromWindowsErrWithFilename(int ierr,
const char *filename);
#endif
#if !defined(PyErr_SetExcFromWindowsErrWithFilenameObject)
PyObject *PyErr_SetExcFromWindowsErrWithFilenameObject(
PyObject *type, int ierr, PyObject *filename);
#endif
#endif

// --- _Py_PARSE_PID
Expand Down

0 comments on commit ccdb775

Please sign in to comment.