Skip to content

Commit

Permalink
Follow Python include advice (pyodide#1094)
Browse files Browse the repository at this point in the history
  • Loading branch information
Hood Chatham authored Jan 10, 2021
1 parent 83f8fa9 commit 4851be1
Show file tree
Hide file tree
Showing 20 changed files with 59 additions and 20 deletions.
5 changes: 4 additions & 1 deletion src/core/error_handling.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#include "error_handling.h"
// clang-format off
#define PY_SSIZE_T_CLEAN
#include "Python.h"
// clang-format on
#include "error_handling.h"
#include "jsproxy.h"
#include <emscripten.h>

Expand Down
4 changes: 4 additions & 0 deletions src/core/error_handling.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#ifndef ERROR_HANDLING_H
#define ERROR_HANDLING_H
// clang-format off
#define PY_SSIZE_T_CLEAN
#include "Python.h"
// clang-format on
#include <emscripten.h>

typedef int errcode;
Expand Down
3 changes: 3 additions & 0 deletions src/core/hiwire.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#define PY_SSIZE_T_CLEAN
#include "Python.h"

#include "error_handling.h"
#include <emscripten.h>

Expand Down
1 change: 1 addition & 0 deletions src/core/hiwire.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#ifndef HIWIRE_H
#define HIWIRE_H
#define PY_SSIZE_T_CLEAN
#include "Python.h"
#include "stdalign.h"
#include "types.h"
Expand Down
5 changes: 4 additions & 1 deletion src/core/js2python.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#include "js2python.h"
#define PY_SSIZE_T_CLEAN
#include "Python.h"

#include "error_handling.h"
#include "js2python.h"

#include <emscripten.h>

Expand Down
4 changes: 2 additions & 2 deletions src/core/js2python.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
/**
* Utilities to convert Javascript objects to Python objects.
*/

#define PY_SSIZE_T_CLEAN
#include "Python.h"
#include "hiwire.h"
#include <Python.h>

/** Convert a Javascript object to a Python object.
* \param x The Javascript object.
Expand Down
3 changes: 3 additions & 0 deletions src/core/jsimport.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#define PY_SSIZE_T_CLEAN
#include "Python.h"

#include "jsimport.h"

#include <emscripten.h>
Expand Down
4 changes: 2 additions & 2 deletions src/core/jsimport.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
#define JSIMPORT_H

/** Support "from js import …" from Python. */

#include <Python.h>
#define PY_SSIZE_T_CLEAN
#include "Python.h"

/** Install the import hook to support "from js import …". */
int
Expand Down
4 changes: 3 additions & 1 deletion src/core/jsproxy.c
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
#define PY_SSIZE_T_CLEAN
#include "Python.h"

#include "jsproxy.h"

#include "hiwire.h"
#include "js2python.h"
#include "python2js.h"

#include "Python.h"
#include "structmember.h"

static PyTypeObject* PyExc_BaseException_Type;
Expand Down
6 changes: 4 additions & 2 deletions src/core/jsproxy.h
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
#ifndef JSPROXY_H
#define JSPROXY_H
// clang-format off
#define PY_SSIZE_T_CLEAN
#include "Python.h"
// clang-format on
#include "hiwire.h"

/** A Python object that a Javascript object inside. Used for any non-standard
* data types that are passed from Javascript to Python.
*/

#include <Python.h>

/** Make a new JsProxy.
* \param v The Javascript object.
* \return The Python object wrapping the Javascript object.
Expand Down
3 changes: 2 additions & 1 deletion src/core/main.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <Python.h>
#define PY_SSIZE_T_CLEAN
#include "Python.h"
#include <assert.h>
#include <emscripten.h>
#include <stdalign.h>
Expand Down
3 changes: 2 additions & 1 deletion src/core/pyproxy.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#define PY_SSIZE_T_CLEAN
#include "Python.h"
#include "error_handling.h"
#include <Python.h>
#include <emscripten.h>

#include "hiwire.h"
Expand Down
1 change: 1 addition & 0 deletions src/core/pyproxy.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#ifndef PYPROXY_H
#define PYPROXY_H
#define PY_SSIZE_T_CLEAN
#include "Python.h"

/** Makes Python objects usable from Javascript.
Expand Down
7 changes: 4 additions & 3 deletions src/core/python2js.c
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
#include "python2js.h"

#include <emscripten.h>
#define PY_SSIZE_T_CLEAN
#include "Python.h"

#include "hiwire.h"
#include "jsproxy.h"
#include "pyproxy.h"
#include "python2js.h"
#include <emscripten.h>

#include "python2js_buffer.h"

Expand Down
6 changes: 4 additions & 2 deletions src/core/python2js.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@

/** Utilities to convert Python objects to Javascript.
*/

// clang-format off
#define PY_SSIZE_T_CLEAN
#include "Python.h"
// clang-format on
#include "hiwire.h"
#include <Python.h>

/** Convert the active Python exception into a Javascript Error object
* and print it to the console.
Expand Down
3 changes: 3 additions & 0 deletions src/core/python2js_buffer.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#define PY_SSIZE_T_CLEAN
#include "Python.h"

#include "python2js_buffer.h"
#include "types.h"

Expand Down
6 changes: 4 additions & 2 deletions src/core/python2js_buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@

/** Utilities to convert Python buffer objects to Javascript.
*/

// clang-format off
#define PY_SSIZE_T_CLEAN
#include "Python.h"
// clang-format on
#include "hiwire.h"
#include <Python.h>

/** Convert a Python buffer object to a Javascript object.
*
Expand Down
6 changes: 4 additions & 2 deletions src/core/runpython.c
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
#include "runpython.h"
#define PY_SSIZE_T_CLEAN
#include "Python.h"

#include "error_handling.h"
#include "hiwire.h"
#include "pyproxy.h"
#include "python2js.h"
#include "runpython.h"

#include <Python.h>
#include <emscripten.h>

static PyObject* pyodide_py;
Expand Down
2 changes: 2 additions & 0 deletions src/core/runpython.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#ifndef RUNPYTHON_H
#define RUNPYTHON_H
#define PY_SSIZE_T_CLEAN
#include "Python.h"

/** The primary entry point function that runs Python code.
*/
Expand Down
3 changes: 3 additions & 0 deletions src/core/types.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#ifndef MY_TYPES_H
#define MY_TYPES_H
// https://elixir.bootlin.com/linux/latest/source/arch/powerpc/boot/types.h#L9
#define PY_SSIZE_T_CLEAN
#include "Python.h"

#include "stdbool.h"
#include "stdint.h"

Expand Down

0 comments on commit 4851be1

Please sign in to comment.