mongodb / winkerberos

A native Kerberos client implementation for Python on Windows
Apache License 2.0
54 stars 15 forks source link

DeprecationWarning: PY_SSIZE_T_CLEAN will be required for '#' formats #37

Closed interifter closed 3 years ago

interifter commented 4 years ago

This was actually found while using requests-kerberos, but it depends on winkerberos in Windows environments.

Full warning message:

requests_kerberos\kerberos_.py:385: DeprecationWarning: PY_SSIZE_T_CLEAN will be required for '#' formats
    self.cbt_struct = kerberos.channelBindings(application_data=cbt_application_data)

I am not 100% familiar with the python c-api, so can only make some recommendations at a high level.

First, the documentation says:

**Note** For all # variants of formats (s#, y#, etc.), the type of the length argument (int or Py_ssize_t) is controlled by defining the macro PY_SSIZE_T_CLEAN before including Python.h. If the macro was defined, length is a Py_ssize_t rather than an int. This behavior will change in a future Python version to only support Py_ssize_t and drop int support. It is best to always define PY_SSIZE_T_CLEAN.

Per documentation, this at least means you may need to add this above here: https://github.com/mongodb-labs/winkerberos/blob/master/src/kerberos_sspi.h#L19

Looking at a similar issue in tox, I could guess where other changes could be made: https://github.com/python-pillow/Pillow/pull/3749/files

Running with

python 3.8.1 Windows 10 RS5 Similar issue found in other libraries python-pillow/Pillow#3750 https://github.com/zopefoundation/ZODB/issues/261

behackett commented 4 years ago

Thanks for reporting this. It looks like this is only a problem in sspi_channel_bindings which uses "s#" with PyArg_ParseTupleAndKeywords. # formats don't seem to be used anywhere else. This shouldn't be too hard to fix, I hope.

interifter commented 4 years ago

You'r right. I was able to reproduce the issue with a bare install of a local copy. All I did was add the definition above the python import in kerberos_sspi.h and the warning disappears in my project.

#define SECURITY_WIN32 1 /* Required for SSPI */
#define PY_SSIZE_T_CLEAN

#include "Python.h"

Also, out of curiosity, do you plan on supporting pip wheel? I used easy_install in my test project to install the generated egg, but easy_install is deprecated.

interifter commented 4 years ago

38

Created a Pull Request - hope it is okay.

behackett commented 4 years ago

We already provide wheels for WinKerberos:

https://pypi.org/project/winkerberos/#files

And the docs say to use pip to install it:

https://pypi.org/project/winkerberos/#description