Skip to content

Commit 69112dd

Browse files
authored
[mypyc] Fix compilation of byteswriter_extra_ops (#20403)
Compiling byteswriter_extra_ops.c on its own fails because it uses types from Python.h without including it so add the include directive. It also references `BytesWriterObject` which is defined only when `MYPYC_EXPERIMENTAL` is defined so wrap the functions with the same `ifdef`. Also add the explicit include of Python.h in other header files that currently rely on the file being included above them when compiling. Remove unused variables.
1 parent fd86abd commit 69112dd

File tree

7 files changed

+18
-2
lines changed

7 files changed

+18
-2
lines changed

mypyc/lib-rt/byteswriter_extra_ops.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
#include "byteswriter_extra_ops.h"
55

6+
#ifdef MYPYC_EXPERIMENTAL
7+
68
char CPyBytesWriter_Write(PyObject *obj, PyObject *value) {
79
BytesWriterObject *self = (BytesWriterObject *)obj;
810
const char *data;
@@ -29,3 +31,5 @@ char CPyBytesWriter_Write(PyObject *obj, PyObject *value) {
2931
self->len += size;
3032
return CPY_NONE;
3133
}
34+
35+
#endif // MYPYC_EXPERIMENTAL

mypyc/lib-rt/byteswriter_extra_ops.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
#ifndef BYTESWRITER_EXTRA_OPS_H
22
#define BYTESWRITER_EXTRA_OPS_H
33

4+
#ifdef MYPYC_EXPERIMENTAL
5+
6+
#include <stdint.h>
7+
#include <Python.h>
8+
49
#include "librt_strings.h"
510

611
static inline CPyTagged
@@ -31,4 +36,6 @@ CPyBytesWriter_Append(PyObject *obj, uint8_t value) {
3136

3237
char CPyBytesWriter_Write(PyObject *obj, PyObject *value);
3338

39+
#endif // MYPYC_EXPERIMENTAL
40+
3441
#endif

mypyc/lib-rt/function_wrapper.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ static PyObject* CPyFunction_repr(CPyFunction *op) {
3333
}
3434

3535
static PyObject* CPyFunction_call(PyObject *func, PyObject *args, PyObject *kw) {
36-
PyObject *result;
3736
CPyFunction *f = (CPyFunction *)func;
3837
vectorcallfunc vc = CPyFunction_func_vectorcall(f);
3938
assert(vc);

mypyc/lib-rt/getargs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ static void
437437
skipitem(const char **p_format, va_list *p_va)
438438
{
439439
const char *format = *p_format;
440-
char c = *format++;
440+
format++;
441441

442442
if (p_va != NULL) {
443443
(void) va_arg(*p_va, PyObject **);

mypyc/lib-rt/librt_base64.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import_librt_base64(void)
1212

1313
#else // MYPYC_EXPERIMENTAL
1414

15+
#include <Python.h>
16+
1517
#define LIBRT_BASE64_ABI_VERSION 1
1618
#define LIBRT_BASE64_API_VERSION 2
1719
#define LIBRT_BASE64_API_LEN 4

mypyc/lib-rt/librt_internal.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#ifndef LIBRT_INTERNAL_H
22
#define LIBRT_INTERNAL_H
33

4+
#include <Python.h>
5+
46
// ABI version -- only an exact match is compatible. This will only be changed in
57
// very exceptional cases (likely never) due to strict backward compatibility
68
// requirements.

mypyc/lib-rt/librt_strings.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import_librt_strings(void)
1212

1313
#else // MYPYC_EXPERIMENTAL
1414

15+
#include <Python.h>
16+
1517
// ABI version -- only an exact match is compatible. This will only be changed in
1618
// very exceptional cases (likely never) due to strict backward compatibility
1719
// requirements.

0 commit comments

Comments
 (0)