From d25f23805c6d7128b508a359d47af136dd2fd0db Mon Sep 17 00:00:00 2001 From: Sebastiano Tronto Date: Mon, 11 Aug 2025 10:22:56 +0200 Subject: Wrapped pthread use in custom API --- build | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) (limited to 'build') diff --git a/build b/build index 310bd28..e689b19 100755 --- a/build +++ b/build @@ -117,15 +117,23 @@ parsesanitize() { done } +maybe_pthread() { + if [ "$THREADS" -gt 1 ]; then + echo "-pthread" + else + echo "" + fi +} + # Build flags -CFLAGS="-std=c11 -fPIC -D_POSIX_C_SOURCE=199309L -pthread" -PYCFLAGS="-std=c11 -fPIC -pthread" +CFLAGS="-std=c11 -fPIC -D_POSIX_C_SOURCE=199309L $(maybe_pthread)" +PYCFLAGS="-std=c11 -fPIC $(maybe_pthread)" [ "$ARCH" = "AVX2" ] && CFLAGS="$CFLAGS -mavx2" WFLAGS="-pedantic -Wall -Wextra -Wno-unused-parameter -Wno-unused-function" OFLAGS="$OPTIMIZE" DFLAGS="-DDEBUG -g3 $(parsesanitize "$SANITIZE")" MFLAGS="-DTHREADS=$THREADS -D$ARCH" -CPPFLAGS="-std=c++20 -pthread" +CPPFLAGS="-std=c++20 $(maybe_pthread)" # TODO: # MEMORY64 is supported on Firefox (from version 134) and Chrome (from 133), @@ -140,9 +148,9 @@ CPPFLAGS="-std=c++20 -pthread" # The options below have to be adjusted when native WASM_SIMD is implemented. # Build flags for emscripten (WASM target) -WASMCFLAGS="-std=c11 -fPIC -D_POSIX_C_SOURCE=199309L -pthread +WASMCFLAGS="-std=c11 -fPIC -D_POSIX_C_SOURCE=199309L $(maybe_pthread) -mfpu=neon -mrelaxed-simd" -WASMCPPFLAGS="-std=c++20 -pthread" +WASMCPPFLAGS="-std=c++20 $(maybe_pthread)" WASMDBGFLAGS="-sASSERTIONS" WASMMFLAGS="-DTHREADS=$THREADS -DNEON" WASMLINKFLAGS="--no-entry -sEXPORT_NAME='Nissy' -sMODULARIZE -- cgit v1.3 From 4544e08997a7af6a8defa47efae1e9ba5c2c30f6 Mon Sep 17 00:00:00 2001 From: Sebastiano Tronto Date: Mon, 11 Aug 2025 12:05:08 +0200 Subject: Simplified name of Python module --- .gitignore | 1 + README.md | 4 ++-- build | 2 +- python/examples/move.py | 7 +++++-- python/examples/solve.py | 11 ++++++----- python/examples/variations.py | 5 +++-- python/nissy_module.c | 6 +++--- 7 files changed, 21 insertions(+), 15 deletions(-) (limited to 'build') diff --git a/.gitignore b/.gitignore index 3e5bc85..1611bcc 100644 --- a/.gitignore +++ b/.gitignore @@ -36,6 +36,7 @@ tools/results *.a *.o *.so +*/*.so *.s *.pyd *.dll diff --git a/README.md b/README.md index 34d5f72..d025f89 100644 --- a/README.md +++ b/README.md @@ -224,8 +224,8 @@ $ ./build python And to import it ``` -$ python # In the main folder ->>> import nissy_python_module as nissy # In the python shell +$ python # In the main folder or in the python subfolder +>>> import nissy # In the python shell ``` From here you can call the library functions directly, for example: diff --git a/build b/build index e689b19..cdf0c79 100755 --- a/build +++ b/build @@ -280,7 +280,7 @@ build_python() { fi build_nissy || exit 1 run $CC $PYCFLAGS $WFLAGS $PYTHON3_INCLUDES $OFLAGS -shared \ - -o nissy_python_module.so nissy.o python/nissy_module.c + -o python/nissy.so nissy.o python/nissy_module.c } build_cpp() { diff --git a/python/examples/move.py b/python/examples/move.py index 9c7a756..0ed879b 100644 --- a/python/examples/move.py +++ b/python/examples/move.py @@ -1,10 +1,13 @@ -# Small example of nissy_python_module usage +# Small example of nissy Python module usage # See the solve.py example for more details on how this works import os, sys +# Assume we are eithe rin the top-level directory of the nissy-core repo, +# or in the python subdirectory sys.path.append(os.getcwd()) -import nissy_python_module as nissy +sys.path.append(os.getcwd() + os.path.sep + "python") +import nissy cube = nissy.applymoves(nissy.solved_cube, "R' U' F"); print("Cube after the moves R' U' F:") diff --git a/python/examples/solve.py b/python/examples/solve.py index e3752fe..d77dd74 100644 --- a/python/examples/solve.py +++ b/python/examples/solve.py @@ -1,14 +1,15 @@ -# Small example of nissy_python_module usage +# Small example of nissy Python module usage -# Compile the python module with "make python", then run this from the main -# folder containing nissy_python_module.so +# Run "./build python", then run this from either the top-level directory +# of the nissy-core repo or from the python subdirectory. -# Append the main folder to the python path so we can load the module +# Append the directories to the python path so we can load the module import sys, os sys.path.append(os.getcwd()) +sys.path.append(os.getcwd() + os.path.sep + "python") # Import with a nicer name -import nissy_python_module as nissy +import nissy # Choose the solver you prefer solver = "h48h0k4" diff --git a/python/examples/variations.py b/python/examples/variations.py index 1a9d5bb..2507e6e 100644 --- a/python/examples/variations.py +++ b/python/examples/variations.py @@ -1,9 +1,10 @@ -# Small example of nissy_python_module usage +# Small example of nissy Python module usage # See the solve.py example for more details on how this works import sys, os sys.path.append(os.getcwd()) -import nissy_python_module as nissy +sys.path.append(os.getcwd() + os.path.sep + "python") +import nissy moves = "R U' Bw2 M D' x' F B(E2 F D B' Lw2 U2 U' S2 B)" diff --git a/python/nissy_module.c b/python/nissy_module.c index 88109d3..bff4ead 100644 --- a/python/nissy_module.c +++ b/python/nissy_module.c @@ -431,7 +431,7 @@ static PyMethodDef nissy_methods[] = { { NULL, NULL, 0, NULL } }; -static struct PyModuleDef nissy_python_module = { +static struct PyModuleDef nissy = { .m_base = PyModuleDef_HEAD_INIT, .m_name = "nissy", .m_doc = "python module for libnissy", @@ -449,11 +449,11 @@ log_stdout(const char *str, void *unused) fprintf(stderr, "%s", str); } -PyMODINIT_FUNC PyInit_nissy_python_module(void) { +PyMODINIT_FUNC PyInit_nissy(void) { PyObject *module; nissy_setlogger(log_stdout, NULL); - module = PyModule_Create(&nissy_python_module); + module = PyModule_Create(&nissy); PyModule_AddStringConstant(module, "solved_cube", NISSY_SOLVED_CUBE); PyModule_AddIntConstant(module, "nissflag_normal", NISSY_NISSFLAG_NORMAL); -- cgit v1.3