Skip to content

Commit e08233f

Browse files
committed
demo.c: Update for python3
Test-case demo.c does not compile with python3, because it uses a PyInt_* function. Fix compilation by replacing it with its PyLong_* equivalent, as suggested by this ( https://docs.python.org/3/howto/cporting.html#long-int-unification ).
1 parent af4fdc6 commit e08233f

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

demo.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@
2222

2323
extern uint16_t htons(uint16_t hostshort);
2424

25+
#if PY_MAJOR_VERSION >= 3
26+
#define PYINT_FROMLONG(l) (PyLong_FromLong(l))
27+
#else
28+
#define PYINT_FROMLONG(l) (PyInt_FromLong(l))
29+
#endif
30+
2531
PyObject *
2632
socket_htons(PyObject *self, PyObject *args)
2733
{
@@ -31,7 +37,7 @@ socket_htons(PyObject *self, PyObject *args)
3137
return NULL;
3238
}
3339
x2 = (int)htons((short)x1);
34-
return PyInt_FromLong(x2);
40+
return PYINT_FROMLONG(x2);
3541
}
3642

3743
PyObject *

0 commit comments

Comments
 (0)