c-jo / cpython

RISC OS port of the Python programming language
https://www.python.org/
Other
7 stars 3 forks source link

DeprecationWarning: PY_SSIZE_T_CLEAN #28

Open riscman opened 7 months ago

riscman commented 7 months ago

The following code generates a Deprecation warning.

"""create a swi block and print contents"""

import swi
bufsize = 4               
buf = swi.block(4)                    # 4 words
print (f'buf {buf}')
buf.padstring('hello world', b'.')    # deprecated warning
print (f'block.tostring {buf.tostring()}')

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

The problem appears to be in the c code of the swimodule.c A search of the topic revealed two main types of answer. Fix it in my code by suppressing the message, or fix it in the swi module. Here is what it suggests:

to fix this issue define PY_SSIZE_T_CLEAN before including python.h:

#define NOT_MAIN 1
#define PY_SSIZE_T_CLEAN

#include "xdelta3.h"
#include "xdelta3.c"
#include <Python.h>

You will also need to change the type passed to '#' formats from int to Py_ssize_t,