Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ jobs:
python-version: ${{ matrix.python_version }}
- name: Setup cmake
run: |
sudo apt-get install -y cmake doxygen graphviz gcovr llvm
sudo apt-get install -y cmake doxygen graphviz gcovr llvm python3-dev python3-pytest
pip install pytest
- name: Cache spidermonkey build
id: cache-spidermonkey
uses: actions/cache@v3
Expand All @@ -38,7 +39,10 @@ jobs:
curl --proto '=https' --tlsv1.3 https://sh.rustup.rs -sSf | sh -s -- -y
wget -q https://ftp.mozilla.org/pub/firefox/releases/102.2.0esr/source/firefox-102.2.0esr.source.tar.xz
tar xf firefox-102.2.0esr.source.tar.xz
cd firefox-102.2.0/js/src
cd firefox-102.2.0/js
sed -i 's/bool Unbox/JS_PUBLIC_API bool Unbox/g' ./public/Class.h # need to manually add JS_PUBLIC_API to js::Unbox until it gets fixed in Spidermonkey
Comment thread
zollqir marked this conversation as resolved.
Resolved
sed -i 's/bool js::Unbox/JS_PUBLIC_API bool js::Unbox/g' ./src/vm/JSObject.cpp # same here
cd src
cp ./configure.in ./configure
chmod +x ./configure
mkdir _build
Expand All @@ -61,6 +65,8 @@ jobs:
make && make tests
gcovr --xml-pretty --exclude-unreachable-branches --print-summary -o coverage.xml
cd tests && ctest
cd ../src
python -m pytest ../../tests/python
- name: google-tests-artifacts
uses: actions/upload-artifact@v3
with:
Expand Down
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ bin/
lib/*
.pytest_cache
.DS_Store
firefox-102.2.0*
firefox-102.2.0/*
firefox-*/*
firefox-*/
firefox-*/
tests/__pycache__/*
tests/python/__pycache__/*

91 changes: 0 additions & 91 deletions .gitlab-ci.yml

This file was deleted.

32 changes: 32 additions & 0 deletions include/NoneType.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
* @file NoneType.hh
* @author Caleb Aikens (caleb@distributive.network)
* @brief Struct for representing None
* @version 0.1
* @date 2023-02-22
*
* @copyright Copyright (c) 2023
*
*/

#ifndef PythonMonkey_NoneType_
#define PythonMonkey_NoneType_

#include "PyType.hh"
#include "TypeEnum.hh"

#include <iostream>

/**
* @brief This struct represents the 'None' type in Python. It inherits from the PyType struct
*/
struct NoneType : public PyType {
public:
NoneType();
const TYPE returnType = TYPE::NONE;

protected:
virtual void print(std::ostream &os) const override;
};

#endif
32 changes: 32 additions & 0 deletions include/NullType.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
* @file NullType.hh
* @author Caleb Aikens (caleb@distributive.network)
* @brief Struct for representing JS null in a python object
* @version 0.1
* @date 2023-02-22
*
* @copyright Copyright (c) 2023
*
*/

#ifndef PythonMonkey_NullType_
#define PythonMonkey_NullType_

#include "PyType.hh"
#include "TypeEnum.hh"

#include <iostream>

/**
* @brief This struct represents the JS null type in Python using a singleton object on the pythonmonkey module. It inherits from the PyType struct
*/
struct NullType : public PyType {
public:
NullType();
const TYPE returnType = TYPE::PYTHONMONKEY_NULL;

protected:
virtual void print(std::ostream &os) const override;
};

#endif
4 changes: 3 additions & 1 deletion include/TypeEnum.hh
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ enum class TYPE {
DICT,
LIST,
TUPLE,
DATE
DATE,
NONE,
PYTHONMONKEY_NULL,
};

#endif
27 changes: 27 additions & 0 deletions include/jsTypeFactory.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/**
* @file jsTypeFactory.hh
* @author Caleb Aikens (caleb@distributive.network)
* @brief
* @version 0.1
* @date 2023-02-15
*
* @copyright Copyright (c) 2023
*
*/

#ifndef PythonMonkey_JsTypeFactory_
#define PythonMonkey_JsTypeFactory_

#include "include/PyType.hh"

#include <jsapi.h>

/**
* @brief Function that takes a PyType and returns a corresponding JS::Value, doing shared memory management when necessary
*
* @param object - Pointer to the PyObject who's type and value we wish to encapsulate
* @return JS::Value - A JS::Value corresponding to the PyType
*/
JS::Value jsTypeFactory(PyObject *object);

#endif
36 changes: 26 additions & 10 deletions include/modules/pythonmonkey/pythonmonkey.hh
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,10 @@

#include <Python.h>

/**
* @brief Callback function passed to JS_SetGCCallback to handle PythonMonkey shared memory
*
* @param cx - Pointer to the JS Context (not used)
* @param status - enum specifying whether the Callback triggered at the beginning or end of the GC Cycle
* @param reason - reason for the GC Cycle
* @param data -
*/
void handleSharedPythonMonkeyMemory(JSContext *cx, JSGCStatus status, JS::GCReason reason, void *data);
#define PythonMonkey_Null PyObject_GetAttrString(PyState_FindModule(&pythonmonkey), "null") /**< macro for python null object*/

static JSContext *GLOBAL_CX; /**< pointer to PythonMonkey's JSContext */
static JS::Rooted<JSObject *> *global; /**< pointer to the global object of PythonMonkey's JSContext */

/**
* @brief Destroys the JSContext and deletes associated memory. Called when python quits or faces a fatal exception.
Expand All @@ -44,7 +39,17 @@ static void cleanup();
* @param pyType - Pointer to the PyType to be memoized
* @param GCThing - Pointer to the GCThing to be memoized
*/
static void memoizePyTypeAndGCThing(PyType *pyType, JS::PersistentRootedValue *GCThing);
void memoizePyTypeAndGCThing(PyType *pyType, JS::Handle<JS::Value> GCThing);

/**
* @brief Callback function passed to JS_SetGCCallback to handle PythonMonkey shared memory
*
* @param cx - Pointer to the JS Context (not used)
* @param status - enum specifying whether the Callback triggered at the beginning or end of the GC Cycle
* @param reason - reason for the GC Cycle
* @param data -
*/
void handleSharedPythonMonkeyMemory(JSContext *cx, JSGCStatus status, JS::GCReason reason, void *data);

/**
* @brief Function exposed by the python module that calls the spidermonkey garbage collector
Expand Down Expand Up @@ -80,4 +85,15 @@ static PyObject *eval(PyObject *self, PyObject *args);
*/
PyMODINIT_FUNC PyInit_pythonmonkey(void);

/**
* @brief Array of method definitions for the pythonmonkey module
*
*/
extern PyMethodDef PythonMonkeyMethods[];

/**
* @brief Module definition for the pythonmonkey module
*
*/
extern struct PyModuleDef pythonmonkey;
#endif
23 changes: 22 additions & 1 deletion include/pyTypeFactory.hh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* @file pyTypeFactory.hh
* @author Caleb Aikens (caleb@distributive.network) & Giovanni Tedesco (giovanni@distributive.network)
* @brief Function for wrapping arbitrary PyObjects into the appropriate PyType class
* @brief Function for wrapping arbitrary PyObjects into the appropriate PyType class, and coercing JS types to python types
* @version 0.1
* @date 2022-08-08
*
Expand All @@ -14,6 +14,8 @@

#include "PyType.hh"

#include <jsapi.h>

#include <Python.h>

/** @brief Function that takes an arbitrary PyObject* and returns a corresponding PyType* object
Expand All @@ -25,4 +27,23 @@
*/
PyType *pyTypeFactory(PyObject *object);

/**
* @brief Function that takes a JS::Value and returns a corresponding PyType* object, doing shared memory management when necessary
*
* @param cx - Pointer to the javascript context of the JS::Value
* @param global - Pointer to the javascript global object
* @param rval - Pointer to the JS::Value who's type and value we wish to encapsulate
* @return PyType* - Pointer to a PyType object corresponding to the JS::Value
*/
PyType *pyTypeFactory(JSContext *cx, JS::Rooted<JSObject *> *global, JS::Rooted<JS::Value> *rval);

/**
* @brief Helper function for pyTypeFactory to create FuncTypes through PyCFunction_New
*
* @param JSFuncAddress - Pointer to a PyLongObject containing the memory address of JS::Value containing the JSFunction*
* @param args - Pointer to a PyTupleObject containing the arguments to the python function
* @return PyObject* - The result of the JSFunction called with args coerced to JS types, coerced back to a PyObject type, or NULL if coercion wasn't possible
*/
static PyObject *callJSFunc(PyObject *JSFuncAddress, PyObject *args);

#endif
7 changes: 4 additions & 3 deletions setup.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
apt-get update --yes
apt-get upgrade --yes
apt-get install cmake python3-dev doxygen graphviz gcovr llvm --yes
apt-get install cmake python3-dev python3-pytest doxygen graphviz gcovr llvm m4 --yes
curl --proto '=https' --tlsv1.3 https://sh.rustup.rs -sSf | sh -s -- -y #install rust compiler
wget -q https://ftp.mozilla.org/pub/firefox/releases/102.2.0esr/source/firefox-102.2.0esr.source.tar.xz
tar xf firefox-102.2.0esr.source.tar.xz
cd firefox-102.2.0/js/src
cd firefox-102.2.0/js
sed -i 's/bool Unbox/JS_PUBLIC_API bool Unbox/g' ./public/Class.h # need to manually add JS_PUBLIC_API to js::Unbox until it gets fixed in Spidermonkey
sed -i 's/bool js::Unbox/JS_PUBLIC_API bool js::Unbox/g' ./vm/JSObject.cpp # same here
sed -i 's/bool js::Unbox/JS_PUBLIC_API bool js::Unbox/g' ./src/vm/JSObject.cpp # same here
cd src
cp ./configure.in ./configure
chmod +x ./configure
mkdir _build
Expand Down
Loading