Skip to content

Commit 7c1a9cd

Browse files
committed
Update to non-deprecated types for length arguments
1 parent 1bbc501 commit 7c1a9cd

File tree

2 files changed

+40
-36
lines changed

2 files changed

+40
-36
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ jobs:
1717
- version: "3.6"
1818
- version: "3.8"
1919
- version: "3.9"
20-
# TODO(robinlinden): Fix PY_SSIZE_T_CLEAN errors.
21-
# - version: "3.10"
20+
- version: "3.10"
2221

2322
steps:
2423
- uses: actions/checkout@v2

pytox/core.c

Lines changed: 39 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
2222
*/
2323

24+
#define PY_SSIZE_T_CLEAN
2425
#include "core.h"
2526
#include "util.h"
2627

@@ -52,33 +53,35 @@ static void callback_friend_request(Tox *tox, const uint8_t *public_key,
5253

5354
bytes_to_hex_string(public_key, TOX_PUBLIC_KEY_SIZE, buf);
5455

55-
PyObject_CallMethod((PyObject *)self, "on_friend_request", "ss#", buf, data,
56-
length - (length > 0 && data[length - 1] == 0));
56+
PyObject_CallMethod(
57+
(PyObject *)self, "on_friend_request", "ss#", buf, data,
58+
(Py_ssize_t)(length - (length > 0 && data[length - 1] == 0)));
5759
}
5860

5961
static void callback_friend_message(Tox *tox, uint32_t friendnumber,
6062
Tox_Message_Type type,
6163
const uint8_t *message, size_t length,
6264
void *self) {
63-
PyObject_CallMethod((PyObject *)self, "on_friend_message", "iis#",
64-
friendnumber, type, message,
65-
length - (length > 0 && message[length - 1] == 0));
65+
PyObject_CallMethod(
66+
(PyObject *)self, "on_friend_message", "iis#", friendnumber, type,
67+
message, (Py_ssize_t)(length - (length > 0 && message[length - 1] == 0)));
6668
}
6769

6870
static void callback_friend_name(Tox *tox, uint32_t friendnumber,
6971
const uint8_t *newname, size_t length,
7072
void *self) {
71-
PyObject_CallMethod((PyObject *)self, "on_friend_name", "is#", friendnumber,
72-
newname,
73-
length - (length > 0 && newname[length - 1] == 0));
73+
PyObject_CallMethod(
74+
(PyObject *)self, "on_friend_name", "is#", friendnumber, newname,
75+
(Py_ssize_t)(length - (length > 0 && newname[length - 1] == 0)));
7476
}
7577

7678
static void callback_friend_status_message(Tox *tox, uint32_t friendnumber,
7779
const uint8_t *newstatus,
7880
size_t length, void *self) {
79-
PyObject_CallMethod((PyObject *)self, "on_friend_status_message", "is#",
80-
friendnumber, newstatus,
81-
length - (length > 0 && newstatus[length - 1] == 0));
81+
PyObject_CallMethod(
82+
(PyObject *)self, "on_friend_status_message", "is#", friendnumber,
83+
newstatus,
84+
(Py_ssize_t)(length - (length > 0 && newstatus[length - 1] == 0)));
8285
}
8386

8487
static void callback_friend_status(Tox *tox, uint32_t friendnumber,
@@ -111,17 +114,18 @@ static void callback_conference_invite(Tox *tox, uint32_t friendnumber,
111114
const uint8_t *data, size_t length,
112115
void *self) {
113116
PyObject_CallMethod((PyObject *)self, "on_conference_invite", "ii" BUF_TC "#",
114-
friendnumber, type, data, length);
117+
friendnumber, type, data, (Py_ssize_t)length);
115118
}
116119

117120
static void callback_conference_message(Tox *tox, uint32_t conference_number,
118121
uint32_t peer_number,
119122
Tox_Message_Type type,
120123
const uint8_t *message, size_t length,
121124
void *self) {
122-
PyObject_CallMethod((PyObject *)self, "on_conference_message", "iiis#",
123-
conference_number, peer_number, type, message,
124-
length - (length > 0 && message[length - 1] == 0));
125+
PyObject_CallMethod(
126+
(PyObject *)self, "on_conference_message", "iiis#", conference_number,
127+
peer_number, type, message,
128+
(Py_ssize_t)(length - (length > 0 && message[length - 1] == 0)));
125129
}
126130

127131
static void callback_conference_peer_name(Tox *tox, uint32_t conference_number,
@@ -130,7 +134,7 @@ static void callback_conference_peer_name(Tox *tox, uint32_t conference_number,
130134
void *self) {
131135
PyObject_CallMethod((PyObject *)self, "on_conference_peer_name",
132136
"ii" BUF_TC "#", conference_number, peer_number, name,
133-
length);
137+
(Py_ssize_t)length);
134138
}
135139

136140
static void callback_conference_peer_list_changed(Tox *tox,
@@ -163,7 +167,7 @@ static void callback_file_recv(Tox *tox, uint32_t friend_number,
163167
} else {
164168
PyObject_CallMethod((PyObject *)self, "on_file_recv", "iiiKs#",
165169
friend_number, file_number, kind, file_size, filename,
166-
filename_length);
170+
(Py_ssize_t)filename_length);
167171
}
168172
}
169173

@@ -179,7 +183,8 @@ static void callback_file_recv_chunk(Tox *tox, uint32_t friend_number,
179183
const uint8_t *data, size_t length,
180184
void *self) {
181185
PyObject_CallMethod((PyObject *)self, "on_file_recv_chunk", "iiK" BUF_TC "#",
182-
friend_number, file_number, position, data, length);
186+
friend_number, file_number, position, data,
187+
(Py_ssize_t)length);
183188
}
184189

185190
static void init_options(ToxCore *self, PyObject *pyopts,
@@ -351,9 +356,9 @@ static PyObject *ToxCore_friend_add(ToxCore *self, PyObject *args) {
351356
CHECK_TOX(self);
352357

353358
uint8_t *address = NULL;
354-
int addr_length = 0;
359+
Py_ssize_t addr_length = 0;
355360
uint8_t *data = NULL;
356-
int data_length = 0;
361+
Py_ssize_t data_length = 0;
357362

358363
if (!PyArg_ParseTuple(args, "s#s#", &address, &addr_length, &data,
359364
&data_length)) {
@@ -413,7 +418,7 @@ static PyObject *ToxCore_friend_add_norequest(ToxCore *self, PyObject *args) {
413418
CHECK_TOX(self);
414419

415420
uint8_t *address = NULL;
416-
int addr_length = 0;
421+
Py_ssize_t addr_length = 0;
417422

418423
if (!PyArg_ParseTuple(args, "s#", &address, &addr_length)) {
419424
return NULL;
@@ -436,7 +441,7 @@ static PyObject *ToxCore_friend_by_public_key(ToxCore *self, PyObject *args) {
436441
CHECK_TOX(self);
437442

438443
uint8_t *id = NULL;
439-
int addr_length = 0;
444+
Py_ssize_t addr_length = 0;
440445

441446
if (!PyArg_ParseTuple(args, "s#", &id, &addr_length)) {
442447
return NULL;
@@ -530,7 +535,7 @@ static PyObject *ToxCore_friend_send_message(ToxCore *self, PyObject *args) {
530535

531536
int friend_num = 0;
532537
int msg_type = 0;
533-
int length = 0;
538+
Py_ssize_t length = 0;
534539
uint8_t *message = NULL;
535540

536541
if (!PyArg_ParseTuple(args, "iis#", &friend_num, &msg_type, &message,
@@ -554,7 +559,7 @@ static PyObject *ToxCore_self_set_name(ToxCore *self, PyObject *args) {
554559
CHECK_TOX(self);
555560

556561
uint8_t *name = 0;
557-
int length = 0;
562+
Py_ssize_t length = 0;
558563

559564
if (!PyArg_ParseTuple(args, "s#", &name, &length)) {
560565
return NULL;
@@ -633,7 +638,7 @@ static PyObject *ToxCore_self_set_status_message(ToxCore *self,
633638
CHECK_TOX(self);
634639

635640
uint8_t *message;
636-
int length;
641+
Py_ssize_t length;
637642
if (!PyArg_ParseTuple(args, "s#", &message, &length)) {
638643
return NULL;
639644
}
@@ -912,7 +917,7 @@ static PyObject *ToxCore_conference_set_title(ToxCore *self, PyObject *args) {
912917

913918
int conference_number = 0;
914919
uint8_t *title = NULL;
915-
uint32_t length = 0;
920+
Py_ssize_t length = 0;
916921

917922
if (!PyArg_ParseTuple(args, "is#", &conference_number, &title, &length)) {
918923
return NULL;
@@ -991,7 +996,7 @@ static PyObject *ToxCore_conference_join(ToxCore *self, PyObject *args) {
991996

992997
int friend_number = 0;
993998
uint8_t *cookie = NULL;
994-
int length = 0;
999+
Py_ssize_t length = 0;
9951000

9961001
if (!PyArg_ParseTuple(args, "is#", &friend_number, &cookie, &length)) {
9971002
return NULL;
@@ -1014,7 +1019,7 @@ static PyObject *ToxCore_conference_send_message(ToxCore *self,
10141019
int conference_number = 0;
10151020
int type = 0;
10161021
uint8_t *message = NULL;
1017-
uint32_t length = 0;
1022+
Py_ssize_t length = 0;
10181023

10191024
if (!PyArg_ParseTuple(args, "iis#", &conference_number, &type, &message,
10201025
&length)) {
@@ -1113,7 +1118,7 @@ static PyObject *ToxCore_file_send(ToxCore *self, PyObject *args) {
11131118
uint64_t file_size = 0;
11141119
uint8_t *file_id = NULL;
11151120
uint8_t *filename = 0;
1116-
int filename_length = 0;
1121+
Py_ssize_t filename_length = 0;
11171122

11181123
if (!PyArg_ParseTuple(args, "iiKss#", &friend_number, &kind, &file_size,
11191124
&file_id, &filename, &filename_length)) {
@@ -1158,7 +1163,7 @@ static PyObject *ToxCore_file_send_chunk(ToxCore *self, PyObject *args) {
11581163
uint32_t file_number = 0;
11591164
uint64_t position = 0;
11601165
uint8_t *data = 0;
1161-
size_t length = 0;
1166+
Py_ssize_t length = 0;
11621167

11631168
if (!PyArg_ParseTuple(args, "iiKs#", &friend_number, &file_number, &position,
11641169
&data, &length)) {
@@ -1300,8 +1305,8 @@ static PyObject *ToxCore_bootstrap(ToxCore *self, PyObject *args) {
13001305
uint16_t port = 0;
13011306
uint8_t *public_key = NULL;
13021307
char *address = NULL;
1303-
int addr_length = 0;
1304-
int pk_length = 0;
1308+
Py_ssize_t addr_length = 0;
1309+
Py_ssize_t pk_length = 0;
13051310
uint8_t pk[TOX_PUBLIC_KEY_SIZE];
13061311

13071312
if (!PyArg_ParseTuple(args, "s#Hs#", &address, &addr_length, &port,
@@ -1326,8 +1331,8 @@ static PyObject *ToxCore_add_tcp_relay(ToxCore *self, PyObject *args) {
13261331
uint16_t port = 0;
13271332
uint8_t *public_key = NULL;
13281333
char *address = NULL;
1329-
int addr_length = 0;
1330-
int pk_length = 0;
1334+
Py_ssize_t addr_length = 0;
1335+
Py_ssize_t pk_length = 0;
13311336
uint8_t pk[TOX_PUBLIC_KEY_SIZE];
13321337

13331338
if (!PyArg_ParseTuple(args, "s#Hs#", &address, &addr_length, &port,

0 commit comments

Comments
 (0)