Compare commits
18 Commits
v1.0.0-pre.3
..
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 5509c18b17 | |||
| cc39200917 | |||
| 95d7191fdd | |||
| eb4b4c1f80 | |||
| 7b7916911c | |||
| e46ec52c72 | |||
| 09528d60fd | |||
| d1004d8840 | |||
| 6fbd03f863 | |||
| 0cd50a5781 | |||
| 0ebeafd4bb | |||
| 03cce766cd | |||
| 5b252d2b4e | |||
| 08c846d641 | |||
| 6ca46fe79f | |||
| ba3a9dd163 | |||
| a28c4818ab | |||
| 49ecd8fde5 |
+66
-1
@@ -7,6 +7,62 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
|
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
|
|
||||||
|
## [1.0.0-pre.12] - 2026-03-29
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
- `gmake.mk`: changed static library extension on Windows from `.lib` to `.a` for MinGW compatibility
|
||||||
|
- `module_loader`: use `RTLD_GLOBAL` when loading modules to correctly expose host symbols to dynamic libraries
|
||||||
|
|
||||||
|
## [1.0.0-pre.11] - 2026-03-15
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
- `gmake.mk`: `PREFIX` now defaults to `/usr` on Linux instead of `/usr/local`
|
||||||
|
|
||||||
|
## [1.0.0-pre.10] - 2026-03-14
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
- `bmake.mk`: all target and object paths now anchored with `${.CURDIR}` to fix incorrect path nesting when building from outside the project root; substitution delimiters switched to `|` to avoid conflicts with path separators; compile rules now emit `-MT`/`-MF` for correct dependency file targeting; removed stale `.-include` directives for `.d` files; release lib rules now use `${.TARGET}` consistently
|
||||||
|
- `gmake.mk`: removed `AR`/`ARFLAGS_STATIC` variables and the `ifeq`-guarded static lib rules; both debug and release static lib rules now use `ar rcs` directly, as MinGW ships `ar` and `lib.exe` was incorrect
|
||||||
|
|
||||||
|
## [1.0.0-pre.9] - 2026-03-12
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
- `debug` and `release` targets now produce both a shared and static library alongside each other
|
||||||
|
- obj directories split into `shared/` and `static/` subdirs to keep `-fPIC` objects isolated
|
||||||
|
- `install` no longer depends on `release`; guards with an existence check and exits with a clear message if artifacts are missing
|
||||||
|
- `uninstall` removes static lib alongside shared lib
|
||||||
|
- `build.sh`: `install` and `uninstall` now handle privilege escalation automatically via `doas` or `sudo`; skips escalation if already root
|
||||||
|
|
||||||
|
## [1.0.0-pre.8] - 2026-03-08
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
- `stk_poll()`: stale index corruption when simultaneous load and unload events occurred in the same poll cycle. New modules were previously loaded into pre-compaction slot indices; they now always append to the compacted array via `module_count + successful_appends`, matching the `append_modules` path. The two load loops have been unified into one.
|
||||||
|
- `stk_poll()`: `cascade_indices` was a fixed-size stack array of `STK_PATH_MAX` (256) elements with no bounds check. It is now heap-allocated to `module_count` entries per iteration, eliminating the silent overflow risk.
|
||||||
|
- `stk_pending_retry()`: module array was pre-allocated to `module_count + stk_pending_count` but never shrunk when fewer entries loaded than were pending. Now calls `stk_module_realloc_memory(module_count)` after the retry loop completes.
|
||||||
|
- `stk_collect_dependents()`: missing bounds guard on the `indices` write: `(*count)++` had no check against the buffer capacity before writing. Added `capacity` parameter (passed as `module_count` from the call site) and a guard that skips the write if the capacity is reached, preventing a silent overflow.
|
||||||
|
- `stk_log_modules()`: `%lu` format specifier used with `size_t` is undefined behaviour on platforms where `unsigned long` is narrower than `size_t` (e.g. MSVC 64-bit). Fixed with an explicit `(unsigned long)` cast, preserving C89 compatibility.
|
||||||
|
|
||||||
|
## [1.0.0-pre.7] - 2026-03-07
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
- `stk_module_load()`: added missing dependency failure logging when a module is deferred to the pending queue.
|
||||||
|
|
||||||
|
## [1.0.0-pre.6] - 2026-03-07
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
- `stk_poll()`: replaced per-module `stk_pending_add()` calls inside the load holes and `append_modules` loops with batch collection followed by a single `stk_pending_add_batch()` call after both loops complete.
|
||||||
|
|
||||||
|
## [1.0.0-pre.5] - 2026-03-07
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
- `stk_init()`: replaced per-module `stk_pending_add()` calls inside the deferred module loop with batch collection followed by a single `stk_pending_add_batch()` call after the loop.
|
||||||
|
|
||||||
|
## [1.0.0-pre.4] - 2026-03-07
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
- `stk_pending_retry()`: replaced per-module `realloc` at `attempt_load` with a single bulk allocation upfront (`module_count + stk_pending_count`) before the retry loop.
|
||||||
|
- `stk_poll()`: replaced per-module `stk_pending_add()` calls inside the unload and cascade loops with batch collection followed by a single `stk_pending_add_batch()` call after each loop.
|
||||||
|
|
||||||
## [1.0.0-pre.3] - 2026-03-07
|
## [1.0.0-pre.3] - 2026-03-07
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
@@ -162,7 +218,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
- Dependency management and versioning not yet implemented
|
- Dependency management and versioning not yet implemented
|
||||||
- API is unstable and subject to change in future releases
|
- API is unstable and subject to change in future releases
|
||||||
|
|
||||||
[Unreleased]: https://github.com/anth64/stk/compare/v1.0.0-pre.3...HEAD
|
[Unreleased]: https://github.com/anth64/stk/compare/v1.0.0-pre.12...HEAD
|
||||||
|
[1.0.0-pre.12]: https://github.com/anth64/stk/compare/v1.0.0-pre.11...v1.0.0-pre.12
|
||||||
|
[1.0.0-pre.11]: https://github.com/anth64/stk/compare/v1.0.0-pre.10...v1.0.0-pre.11
|
||||||
|
[1.0.0-pre.10]: https://github.com/anth64/stk/compare/v1.0.0-pre.9...v1.0.0-pre.10
|
||||||
|
[1.0.0-pre.9]: https://github.com/anth64/stk/compare/v1.0.0-pre.8...v1.0.0-pre.9
|
||||||
|
[1.0.0-pre.8]: https://github.com/anth64/stk/compare/v1.0.0-pre.7...v1.0.0-pre.8
|
||||||
|
[1.0.0-pre.7]: https://github.com/anth64/stk/compare/v1.0.0-pre.6...v1.0.0-pre.7
|
||||||
|
[1.0.0-pre.6]: https://github.com/anth64/stk/compare/v1.0.0-pre.5...v1.0.0-pre.6
|
||||||
|
[1.0.0-pre.5]: https://github.com/anth64/stk/compare/v1.0.0-pre.4...v1.0.0-pre.5
|
||||||
|
[1.0.0-pre.4]: https://github.com/anth64/stk/compare/v1.0.0-pre.3...v1.0.0-pre.4
|
||||||
[1.0.0-pre.3]: https://github.com/anth64/stk/compare/v1.0.0-pre.2...v1.0.0-pre.3
|
[1.0.0-pre.3]: https://github.com/anth64/stk/compare/v1.0.0-pre.2...v1.0.0-pre.3
|
||||||
[1.0.0-pre.2]: https://github.com/anth64/stk/compare/v1.0.0-pre.1...v1.0.0-pre.2
|
[1.0.0-pre.2]: https://github.com/anth64/stk/compare/v1.0.0-pre.1...v1.0.0-pre.2
|
||||||
[1.0.0-pre.1]: https://github.com/anth64/stk/compare/v0.1.3...v1.0.0-pre.1
|
[1.0.0-pre.1]: https://github.com/anth64/stk/compare/v0.1.3...v1.0.0-pre.1
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ It is designed to run on modern systems running POSIX and Windows using C89.
|
|||||||
- **Hot-swapping** of modules at runtime
|
- **Hot-swapping** of modules at runtime
|
||||||
- **Cross-platform** (Linux, BSD, Windows, macOS)
|
- **Cross-platform** (Linux, BSD, Windows, macOS)
|
||||||
- **Optional WASM support** for multi-language modules (planned)
|
- **Optional WASM support** for multi-language modules (planned)
|
||||||
- **Developer tools**: lightweight metadata, logging/tracing, and dependency management (in progress)
|
- **Developer tools**: lightweight metadata, logging/tracing, and dependency management
|
||||||
- **Minimal, portable API**
|
- **Minimal, portable API**
|
||||||
|
|
||||||
---
|
---
|
||||||
@@ -43,19 +43,19 @@ build.bat debug release
|
|||||||
|
|
||||||
#### Unix (Linux/BSD/macOS)
|
#### Unix (Linux/BSD/macOS)
|
||||||
```bash
|
```bash
|
||||||
sudo ./build.sh install
|
./build.sh install
|
||||||
```
|
```
|
||||||
|
|
||||||
Installs to `/usr/local` by default. Use `PREFIX` to customize:
|
Installs to `/usr` on Linux, `/usr/local` on BSD/macOS by default. Use `PREFIX` to customize:
|
||||||
```bash
|
```bash
|
||||||
sudo ./build.sh PREFIX=$HOME/.local install
|
./build.sh PREFIX=$HOME/.local install
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Windows
|
#### Windows
|
||||||
```
|
```
|
||||||
build.bat release
|
build.bat release
|
||||||
```
|
```
|
||||||
* Once finished building, copy the headers from `include/` to `your_project/include/stk/` and `bin/release/stk.dll` to your project's lib directory.
|
* Once finished building, copy the headers from `include/` to `your_project/include/stk/` and copy `bin/release/stk.dll` or `bin/release/stk.lib` to your project's `lib` directory, depending on whether you are linking dynamically or statically.
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -234,7 +234,7 @@ stk_init();
|
|||||||
|
|
||||||
## Project Status
|
## Project Status
|
||||||
|
|
||||||
**Current Version:** 1.0.0-pre.3
|
**Current Version:** 1.0.0-pre.12
|
||||||
|
|
||||||
### What Works
|
### What Works
|
||||||
- Cross-platform module loading and hot-reloading
|
- Cross-platform module loading and hot-reloading
|
||||||
|
|||||||
@@ -12,44 +12,59 @@ FULL_LIB = lib${LIB_NAME}.dylib
|
|||||||
FULL_LIB = lib${LIB_NAME}.so
|
FULL_LIB = lib${LIB_NAME}.so
|
||||||
.endif
|
.endif
|
||||||
|
|
||||||
|
STATIC_LIB = lib${LIB_NAME}.a
|
||||||
|
|
||||||
LDFLAGS_PLAT = -ldl
|
LDFLAGS_PLAT = -ldl
|
||||||
CFLAGS_PLAT = -fPIC
|
CFLAGS_PLAT = -fPIC
|
||||||
CFLAGS_BASE = -Wall -Wpedantic -I${.CURDIR}/${INC_DIR} -std=c89 ${CFLAGS_PLAT}
|
CFLAGS_BASE = -Wall -Wpedantic -I${.CURDIR}/${INC_DIR} -std=c89 ${CFLAGS_PLAT}
|
||||||
|
CFLAGS_STATIC =
|
||||||
|
|
||||||
.PHONY: all debug release clean test install uninstall
|
.PHONY: all debug release clean test install uninstall
|
||||||
|
|
||||||
all: debug
|
all: debug
|
||||||
|
|
||||||
OBJS_DEBUG = ${SRCS:S/^src\//obj\/debug\//:S/.c$/.o/}
|
OBJS_DEBUG_SHARED = ${SRCS:S|^src/|${.CURDIR}/obj/debug/shared/|:S/.c$/.o/}
|
||||||
OBJS_RELEASE = ${SRCS:S/^src\//obj\/release\//:S/.c$/.o/}
|
OBJS_DEBUG_STATIC = ${SRCS:S|^src/|${.CURDIR}/obj/debug/static/|:S/.c$/.o/}
|
||||||
|
OBJS_RELEASE_SHARED = ${SRCS:S|^src/|${.CURDIR}/obj/release/shared/|:S/.c$/.o/}
|
||||||
|
OBJS_RELEASE_STATIC = ${SRCS:S|^src/|${.CURDIR}/obj/release/static/|:S/.c$/.o/}
|
||||||
|
|
||||||
debug: ${BIN_DIR}/debug/${FULL_LIB}
|
debug: ${.CURDIR}/${BIN_DIR}/debug/${FULL_LIB} ${.CURDIR}/${BIN_DIR}/debug/${STATIC_LIB}
|
||||||
release: ${BIN_DIR}/release/${FULL_LIB}
|
release: ${.CURDIR}/${BIN_DIR}/release/${FULL_LIB} ${.CURDIR}/${BIN_DIR}/release/${STATIC_LIB}
|
||||||
|
|
||||||
${BIN_DIR}/debug/${FULL_LIB}: ${OBJS_DEBUG}
|
${.CURDIR}/${BIN_DIR}/debug/${FULL_LIB}: ${OBJS_DEBUG_SHARED}
|
||||||
@mkdir -p ${.TARGET:H}
|
@mkdir -p ${.TARGET:H}
|
||||||
${CC} -shared -o ${.TARGET} ${.ALLSRC} ${LDFLAGS_PLAT}
|
${CC} -shared -o ${.TARGET} ${.ALLSRC} ${LDFLAGS_PLAT}
|
||||||
|
|
||||||
${BIN_DIR}/release/${FULL_LIB}: ${OBJS_RELEASE}
|
${.CURDIR}/${BIN_DIR}/debug/${STATIC_LIB}: ${OBJS_DEBUG_STATIC}
|
||||||
@mkdir -p ${.CURDIR}/${BIN_DIR}/release
|
@mkdir -p ${.TARGET:H}
|
||||||
${CC} -shared -s -o ${.CURDIR}/${BIN_DIR}/release/${FULL_LIB} ${.ALLSRC} ${LDFLAGS_PLAT}
|
ar rcs ${.TARGET} ${.ALLSRC}
|
||||||
|
|
||||||
|
${.CURDIR}/${BIN_DIR}/release/${FULL_LIB}: ${OBJS_RELEASE_SHARED}
|
||||||
|
@mkdir -p ${.TARGET:H}
|
||||||
|
${CC} -shared -s -o ${.TARGET} ${.ALLSRC} ${LDFLAGS_PLAT}
|
||||||
|
|
||||||
|
${.CURDIR}/${BIN_DIR}/release/${STATIC_LIB}: ${OBJS_RELEASE_STATIC}
|
||||||
|
@mkdir -p ${.TARGET:H}
|
||||||
|
ar rcs ${.TARGET} ${.ALLSRC}
|
||||||
|
|
||||||
.for _src in ${SRCS}
|
.for _src in ${SRCS}
|
||||||
_obj_base = ${_src:S/^src\///:S/.c$/.o/}
|
${.CURDIR}/obj/debug/shared/${_src:S|^src/||:S/.c$/.o/}: ${.CURDIR}/${_src}
|
||||||
|
|
||||||
obj/debug/${_obj_base}: ${_src}
|
|
||||||
@mkdir -p ${.TARGET:H}
|
@mkdir -p ${.TARGET:H}
|
||||||
${CC} ${CFLAGS_BASE} -g -O0 -MMD -MP -c ${.ALLSRC} -o ${.TARGET}
|
${CC} ${CFLAGS_BASE} -g -O0 -MMD -MP -MT ${.TARGET} -MF ${.TARGET:S/.o$/.d/} -c ${.ALLSRC} -o ${.TARGET}
|
||||||
|
|
||||||
obj/release/${_obj_base}: ${_src}
|
${.CURDIR}/obj/debug/static/${_src:S|^src/||:S/.c$/.o/}: ${.CURDIR}/${_src}
|
||||||
@mkdir -p ${.TARGET:H}
|
@mkdir -p ${.TARGET:H}
|
||||||
${CC} ${CFLAGS_BASE} -O2 -MMD -MP -c ${.ALLSRC} -o ${.TARGET}
|
${CC} ${CFLAGS_BASE} ${CFLAGS_STATIC} -g -O0 -MMD -MP -MT ${.TARGET} -MF ${.TARGET:S/.o$/.d/} -c ${.ALLSRC} -o ${.TARGET}
|
||||||
|
|
||||||
|
${.CURDIR}/obj/release/shared/${_src:S|^src/||:S/.c$/.o/}: ${.CURDIR}/${_src}
|
||||||
|
@mkdir -p ${.TARGET:H}
|
||||||
|
${CC} ${CFLAGS_BASE} -O2 -MMD -MP -MT ${.TARGET} -MF ${.TARGET:S/.o$/.d/} -c ${.ALLSRC} -o ${.TARGET}
|
||||||
|
|
||||||
|
${.CURDIR}/obj/release/static/${_src:S|^src/||:S/.c$/.o/}: ${.CURDIR}/${_src}
|
||||||
|
@mkdir -p ${.TARGET:H}
|
||||||
|
${CC} ${CFLAGS_BASE} ${CFLAGS_STATIC} -O2 -MMD -MP -MT ${.TARGET} -MF ${.TARGET:S/.o$/.d/} -c ${.ALLSRC} -o ${.TARGET}
|
||||||
.endfor
|
.endfor
|
||||||
|
|
||||||
.-include "obj/debug/*.d"
|
|
||||||
.-include "obj/release/*.d"
|
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -rf ${.CURDIR}/${OBJ_DIR} ${.CURDIR}/${BIN_DIR}
|
rm -rf ${.CURDIR}/${OBJ_DIR} ${.CURDIR}/${BIN_DIR}
|
||||||
|
|
||||||
@@ -57,13 +72,16 @@ test: debug
|
|||||||
@echo "=== Building and running stk tests ==="
|
@echo "=== Building and running stk tests ==="
|
||||||
cd ${.CURDIR}/test && ${MAKE} -f bmake.mk
|
cd ${.CURDIR}/test && ${MAKE} -f bmake.mk
|
||||||
|
|
||||||
install: release
|
install:
|
||||||
|
@test -f ${.CURDIR}/${BIN_DIR}/release/${FULL_LIB} || { echo "Run 'make -f bmake.mk release' before installing."; exit 1; }
|
||||||
install -d ${LIBDIR} ${INCDIR}/stk
|
install -d ${LIBDIR} ${INCDIR}/stk
|
||||||
install -m 755 ${.CURDIR}/${BIN_DIR}/release/${FULL_LIB} ${LIBDIR}/
|
install -m 755 ${.CURDIR}/${BIN_DIR}/release/${FULL_LIB} ${LIBDIR}/
|
||||||
|
install -m 644 ${.CURDIR}/${BIN_DIR}/release/${STATIC_LIB} ${LIBDIR}/
|
||||||
install -m 644 ${.CURDIR}/${INC_DIR}/stk.h ${INCDIR}/stk/
|
install -m 644 ${.CURDIR}/${INC_DIR}/stk.h ${INCDIR}/stk/
|
||||||
install -m 644 ${.CURDIR}/${INC_DIR}/stk_version.h ${INCDIR}/stk/
|
install -m 644 ${.CURDIR}/${INC_DIR}/stk_version.h ${INCDIR}/stk/
|
||||||
install -m 644 ${.CURDIR}/${INC_DIR}/stk_log.h ${INCDIR}/stk/
|
install -m 644 ${.CURDIR}/${INC_DIR}/stk_log.h ${INCDIR}/stk/
|
||||||
|
|
||||||
uninstall:
|
uninstall:
|
||||||
rm -f ${LIBDIR}/${FULL_LIB}
|
rm -f ${LIBDIR}/${FULL_LIB}
|
||||||
|
rm -f ${LIBDIR}/${STATIC_LIB}
|
||||||
rm -rf ${INCDIR}/stk
|
rm -rf ${INCDIR}/stk
|
||||||
|
|||||||
@@ -8,4 +8,32 @@ else
|
|||||||
MK_FILE="bmake.mk"
|
MK_FILE="bmake.mk"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
make -f "$MK_FILE" "$@"
|
HAS_INSTALL=0
|
||||||
|
HAS_UNINSTALL=0
|
||||||
|
for arg in "$@"; do
|
||||||
|
case "$arg" in
|
||||||
|
install) HAS_INSTALL=1 ;;
|
||||||
|
uninstall) HAS_UNINSTALL=1 ;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
if [ "$HAS_INSTALL" = "1" ] || [ "$HAS_UNINSTALL" = "1" ]; then
|
||||||
|
if [ "$HAS_INSTALL" = "1" ]; then
|
||||||
|
make -f "$MK_FILE" release
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "$(id -u)" = "0" ]; then
|
||||||
|
PRIV=""
|
||||||
|
elif command -v doas > /dev/null 2>&1; then
|
||||||
|
PRIV="doas"
|
||||||
|
elif command -v sudo > /dev/null 2>&1; then
|
||||||
|
PRIV="sudo"
|
||||||
|
else
|
||||||
|
echo "error: install requires root. neither doas nor sudo found." >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
$PRIV make -f "$MK_FILE" "$@"
|
||||||
|
else
|
||||||
|
make -f "$MK_FILE" "$@"
|
||||||
|
fi
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ OBJ_DIR = obj
|
|||||||
BIN_DIR = bin
|
BIN_DIR = bin
|
||||||
|
|
||||||
LIB_NAME = stk
|
LIB_NAME = stk
|
||||||
|
STATIC_LIB = lib$(LIB_NAME).a
|
||||||
|
|
||||||
SRCS = src/module.c \
|
SRCS = src/module.c \
|
||||||
src/platform.c \
|
src/platform.c \
|
||||||
|
|||||||
@@ -2,15 +2,19 @@ include config.mk
|
|||||||
|
|
||||||
ifeq ($(OS),Windows_NT)
|
ifeq ($(OS),Windows_NT)
|
||||||
SHELL := cmd.exe
|
SHELL := cmd.exe
|
||||||
FULL_LIB := $(LIB_NAME).dll
|
FULL_LIB := $(LIB_NAME).dll
|
||||||
LDFLAGS_PLAT :=
|
STATIC_LIB := lib$(LIB_NAME).a
|
||||||
CFLAGS_PLAT :=
|
LDFLAGS_PLAT :=
|
||||||
|
CFLAGS_PLAT :=
|
||||||
|
CFLAGS_STATIC :=
|
||||||
MKDIR = if not exist $(subst /,\,$(1)) mkdir $(subst /,\,$(1))
|
MKDIR = if not exist $(subst /,\,$(1)) mkdir $(subst /,\,$(1))
|
||||||
RMDIR = if exist $(subst /,\,$(1)) rd /s /q $(subst /,\,$(1))
|
RMDIR = if exist $(subst /,\,$(1)) rd /s /q $(subst /,\,$(1))
|
||||||
else
|
else
|
||||||
FULL_LIB := lib$(LIB_NAME).so
|
FULL_LIB := lib$(LIB_NAME).so
|
||||||
LDFLAGS_PLAT := -ldl
|
STATIC_LIB := lib$(LIB_NAME).a
|
||||||
CFLAGS_PLAT := -fPIC
|
LDFLAGS_PLAT := -ldl
|
||||||
|
CFLAGS_PLAT := -fPIC
|
||||||
|
CFLAGS_STATIC :=
|
||||||
MKDIR = mkdir -p $(1)
|
MKDIR = mkdir -p $(1)
|
||||||
RMDIR = rm -rf $(1)
|
RMDIR = rm -rf $(1)
|
||||||
endif
|
endif
|
||||||
@@ -18,37 +22,55 @@ endif
|
|||||||
RELEASE_LDFLAGS := -s
|
RELEASE_LDFLAGS := -s
|
||||||
CFLAGS_BASE := -Wall -Wpedantic -I$(INC_DIR) -std=c89 $(CFLAGS_PLAT)
|
CFLAGS_BASE := -Wall -Wpedantic -I$(INC_DIR) -std=c89 $(CFLAGS_PLAT)
|
||||||
|
|
||||||
PREFIX ?= /usr/local
|
PREFIX ?= /usr
|
||||||
LIBDIR ?= $(PREFIX)/lib
|
LIBDIR ?= $(PREFIX)/lib
|
||||||
INCDIR ?= $(PREFIX)/include
|
INCDIR ?= $(PREFIX)/include
|
||||||
|
|
||||||
.PHONY: all debug release clean test install uninstall
|
.PHONY: all debug release clean test install uninstall
|
||||||
|
|
||||||
all: debug
|
all: debug
|
||||||
|
|
||||||
debug: $(BIN_DIR)/debug/$(FULL_LIB)
|
debug: $(BIN_DIR)/debug/$(FULL_LIB) $(BIN_DIR)/debug/$(STATIC_LIB)
|
||||||
release: $(BIN_DIR)/release/$(FULL_LIB)
|
release: $(BIN_DIR)/release/$(FULL_LIB) $(BIN_DIR)/release/$(STATIC_LIB)
|
||||||
|
|
||||||
# Debug Rules
|
# Debug Rules
|
||||||
$(BIN_DIR)/debug/$(FULL_LIB): $(SRCS:src/%.c=obj/debug/%.o)
|
$(BIN_DIR)/debug/$(FULL_LIB): $(SRCS:src/%.c=obj/debug/shared/%.o)
|
||||||
@$(call MKDIR,$(@D))
|
@$(call MKDIR,$(@D))
|
||||||
$(CC) -shared -o $@ $^ $(LDFLAGS_PLAT)
|
$(CC) -shared -o $@ $^ $(LDFLAGS_PLAT)
|
||||||
|
|
||||||
obj/debug/%.o: src/%.c
|
$(BIN_DIR)/debug/$(STATIC_LIB): $(SRCS:src/%.c=obj/debug/static/%.o)
|
||||||
@$(call MKDIR,$(@D))
|
@$(call MKDIR,$(@D))
|
||||||
$(CC) $(CFLAGS_BASE) -g -O0 -MMD -MP -c $< -o $@
|
ar rcs $@ $^
|
||||||
|
|
||||||
|
obj/debug/shared/%.o: src/%.c
|
||||||
|
@$(call MKDIR,$(@D))
|
||||||
|
$(CC) $(CFLAGS_BASE) -g -O0 -MMD -MP -c $< -o $@
|
||||||
|
|
||||||
|
obj/debug/static/%.o: src/%.c
|
||||||
|
@$(call MKDIR,$(@D))
|
||||||
|
$(CC) $(CFLAGS_BASE) $(CFLAGS_STATIC) -g -O0 -MMD -MP -c $< -o $@
|
||||||
|
|
||||||
# Release Rules
|
# Release Rules
|
||||||
$(BIN_DIR)/release/$(FULL_LIB): $(SRCS:src/%.c=obj/release/%.o)
|
$(BIN_DIR)/release/$(FULL_LIB): $(SRCS:src/%.c=obj/release/shared/%.o)
|
||||||
@$(call MKDIR,$(@D))
|
@$(call MKDIR,$(@D))
|
||||||
$(CC) -shared $(RELEASE_LDFLAGS) -o $@ $^ $(LDFLAGS_PLAT)
|
$(CC) -shared $(RELEASE_LDFLAGS) -o $@ $^ $(LDFLAGS_PLAT)
|
||||||
|
|
||||||
obj/release/%.o: src/%.c
|
$(BIN_DIR)/release/$(STATIC_LIB): $(SRCS:src/%.c=obj/release/static/%.o)
|
||||||
@$(call MKDIR,$(@D))
|
@$(call MKDIR,$(@D))
|
||||||
$(CC) $(CFLAGS_BASE) -O2 -MMD -MP -c $< -o $@
|
ar rcs $@ $^
|
||||||
|
|
||||||
-include $(wildcard obj/debug/*.d)
|
obj/release/shared/%.o: src/%.c
|
||||||
-include $(wildcard obj/release/*.d)
|
@$(call MKDIR,$(@D))
|
||||||
|
$(CC) $(CFLAGS_BASE) -O2 -MMD -MP -c $< -o $@
|
||||||
|
|
||||||
|
obj/release/static/%.o: src/%.c
|
||||||
|
@$(call MKDIR,$(@D))
|
||||||
|
$(CC) $(CFLAGS_BASE) $(CFLAGS_STATIC) -O2 -MMD -MP -c $< -o $@
|
||||||
|
|
||||||
|
-include $(wildcard obj/debug/shared/*.d)
|
||||||
|
-include $(wildcard obj/debug/static/*.d)
|
||||||
|
-include $(wildcard obj/release/shared/*.d)
|
||||||
|
-include $(wildcard obj/release/static/*.d)
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
@$(call RMDIR,$(OBJ_DIR))
|
@$(call RMDIR,$(OBJ_DIR))
|
||||||
@@ -58,23 +80,26 @@ test: debug
|
|||||||
@echo "=== Building and running stk tests ==="
|
@echo "=== Building and running stk tests ==="
|
||||||
@$(MAKE) -C test -f gmake.mk
|
@$(MAKE) -C test -f gmake.mk
|
||||||
|
|
||||||
# Installation (Unix only)
|
|
||||||
ifneq ($(OS),Windows_NT)
|
ifneq ($(OS),Windows_NT)
|
||||||
install: release
|
install:
|
||||||
|
@test -f $(BIN_DIR)/release/$(FULL_LIB) || { echo "Run 'make -f gmake.mk release' before installing."; exit 1; }
|
||||||
install -d $(LIBDIR) $(INCDIR)/stk
|
install -d $(LIBDIR) $(INCDIR)/stk
|
||||||
install -m 755 $(BIN_DIR)/release/$(FULL_LIB) $(LIBDIR)/
|
install -m 755 $(BIN_DIR)/release/$(FULL_LIB) $(LIBDIR)/
|
||||||
|
install -m 644 $(BIN_DIR)/release/$(STATIC_LIB) $(LIBDIR)/
|
||||||
install -m 644 $(INC_DIR)/stk.h $(INCDIR)/stk/
|
install -m 644 $(INC_DIR)/stk.h $(INCDIR)/stk/
|
||||||
install -m 644 $(INC_DIR)/stk_version.h $(INCDIR)/stk/
|
install -m 644 $(INC_DIR)/stk_version.h $(INCDIR)/stk/
|
||||||
install -m 644 $(INC_DIR)/stk_log.h $(INCDIR)/stk/
|
install -m 644 $(INC_DIR)/stk_log.h $(INCDIR)/stk/
|
||||||
|
|
||||||
uninstall:
|
uninstall:
|
||||||
rm -f $(LIBDIR)/$(FULL_LIB)
|
rm -f $(LIBDIR)/$(FULL_LIB)
|
||||||
|
rm -f $(LIBDIR)/$(STATIC_LIB)
|
||||||
rm -rf $(INCDIR)/stk
|
rm -rf $(INCDIR)/stk
|
||||||
else
|
else
|
||||||
install:
|
install:
|
||||||
@echo "make install is not supported on Windows."
|
@echo "make install is not supported on Windows."
|
||||||
@echo "Copy include/ directory contents to your_project/include/stk/"
|
@echo "Copy include/ directory contents to your_project/include/stk/"
|
||||||
@echo "Copy bin/release/stk.dll to your project's lib directory."
|
@echo "Copy bin/release/stk.dll to your project's lib directory."
|
||||||
|
@echo "Copy bin/release/stk.lib to your project's lib directory."
|
||||||
|
|
||||||
uninstall:
|
uninstall:
|
||||||
@echo "make uninstall is not supported on Windows."
|
@echo "make uninstall is not supported on Windows."
|
||||||
|
|||||||
+10
-4
@@ -563,6 +563,7 @@ unsigned char stk_module_load(const char *path, int index)
|
|||||||
|
|
||||||
result = stk_validate_dependencies_single(index);
|
result = stk_validate_dependencies_single(index);
|
||||||
if (result != STK_MOD_INIT_SUCCESS) {
|
if (result != STK_MOD_INIT_SUCCESS) {
|
||||||
|
stk_log_dependency_failures(index, "Deferring");
|
||||||
stk_module_discard(index);
|
stk_module_discard(index);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -746,7 +747,7 @@ cleanup:
|
|||||||
free(result);
|
free(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
void stk_collect_dependents(size_t *indices, size_t *count)
|
void stk_collect_dependents(size_t *indices, size_t *count, size_t capacity)
|
||||||
{
|
{
|
||||||
size_t i, d;
|
size_t i, d;
|
||||||
int in_set, changed;
|
int in_set, changed;
|
||||||
@@ -777,6 +778,8 @@ void stk_collect_dependents(size_t *indices, size_t *count)
|
|||||||
for (k = 0; k < *count; k++) {
|
for (k = 0; k < *count; k++) {
|
||||||
if (indices[k] ==
|
if (indices[k] ==
|
||||||
(size_t)dep_index) {
|
(size_t)dep_index) {
|
||||||
|
if (*count >= capacity)
|
||||||
|
goto next_module;
|
||||||
indices[(*count)++] = i;
|
indices[(*count)++] = i;
|
||||||
changed = 1;
|
changed = 1;
|
||||||
goto next_module;
|
goto next_module;
|
||||||
@@ -1026,6 +1029,9 @@ size_t stk_pending_retry(void)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (stk_module_realloc_memory(module_count + stk_pending_count) != 0)
|
||||||
|
return 0;
|
||||||
|
|
||||||
for (i = 0; i < stk_pending_count; i++) {
|
for (i = 0; i < stk_pending_count; i++) {
|
||||||
extract_module_id(stk_pending[i], pending_id);
|
extract_module_id(stk_pending[i], pending_id);
|
||||||
if (is_mod_loaded(pending_id) >= 0) {
|
if (is_mod_loaded(pending_id) >= 0) {
|
||||||
@@ -1073,9 +1079,6 @@ size_t stk_pending_retry(void)
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
attempt_load:
|
attempt_load:
|
||||||
if (stk_module_realloc_memory(module_count + 1) != 0)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
result = stk_module_load(stk_pending[i], module_count);
|
result = stk_module_load(stk_pending[i], module_count);
|
||||||
if (result != STK_MOD_INIT_SUCCESS)
|
if (result != STK_MOD_INIT_SUCCESS)
|
||||||
continue;
|
continue;
|
||||||
@@ -1092,6 +1095,9 @@ size_t stk_pending_retry(void)
|
|||||||
if (stk_pending_count == 0)
|
if (stk_pending_count == 0)
|
||||||
stk_pending_free();
|
stk_pending_free();
|
||||||
|
|
||||||
|
if (loaded > 0)
|
||||||
|
stk_module_realloc_memory(module_count);
|
||||||
|
|
||||||
return loaded;
|
return loaded;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -278,7 +278,7 @@ void *platform_load_library(const char *path)
|
|||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
return (void *)LoadLibraryA(path);
|
return (void *)LoadLibraryA(path);
|
||||||
#else
|
#else
|
||||||
return dlopen(path, RTLD_NOW);
|
return dlopen(path, RTLD_NOW | RTLD_GLOBAL);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ void stk_pending_add_batch(const char (*paths)[STK_PATH_MAX_OS], size_t count);
|
|||||||
void stk_pending_remove(const char *id);
|
void stk_pending_remove(const char *id);
|
||||||
size_t stk_pending_retry(void);
|
size_t stk_pending_retry(void);
|
||||||
void stk_sort_unload_order(size_t *indices, size_t n);
|
void stk_sort_unload_order(size_t *indices, size_t n);
|
||||||
void stk_collect_dependents(size_t *indices, size_t *count);
|
void stk_collect_dependents(size_t *indices, size_t *count, size_t capacity);
|
||||||
void stk_sort_load_order(int *file_indices, size_t n,
|
void stk_sort_load_order(int *file_indices, size_t n,
|
||||||
char (*file_names)[STK_PATH_MAX], const char *tmp_dir);
|
char (*file_names)[STK_PATH_MAX], const char *tmp_dir);
|
||||||
|
|
||||||
@@ -123,7 +123,8 @@ static void stk_log_module(size_t index)
|
|||||||
static void stk_log_modules(void)
|
static void stk_log_modules(void)
|
||||||
{
|
{
|
||||||
size_t i;
|
size_t i;
|
||||||
stk_log(STK_LOG_INFO, "Loaded modules (%lu):", module_count);
|
stk_log(STK_LOG_INFO,
|
||||||
|
"Loaded modules (%lu):", (unsigned long)module_count);
|
||||||
for (i = 0; i < module_count; i++)
|
for (i = 0; i < module_count; i++)
|
||||||
stk_log_module(i);
|
stk_log_module(i);
|
||||||
}
|
}
|
||||||
@@ -136,10 +137,11 @@ unsigned char stk_init(void)
|
|||||||
size_t index, test_count;
|
size_t index, test_count;
|
||||||
char full_path[STK_PATH_MAX_OS];
|
char full_path[STK_PATH_MAX_OS];
|
||||||
char tmp_path[STK_PATH_MAX_OS];
|
char tmp_path[STK_PATH_MAX_OS];
|
||||||
char mod_tmp_path[STK_PATH_MAX_OS];
|
|
||||||
int load_result;
|
int load_result;
|
||||||
unsigned char dep_result;
|
unsigned char dep_result;
|
||||||
size_t *order = NULL;
|
size_t *order = NULL;
|
||||||
|
char (*init_batch)[STK_PATH_MAX_OS] = NULL;
|
||||||
|
size_t init_batch_count = 0;
|
||||||
|
|
||||||
platform_mkdir(stk_mod_dir);
|
platform_mkdir(stk_mod_dir);
|
||||||
build_path(stk_tmp_dir, sizeof(stk_tmp_dir), stk_mod_dir, stk_tmp_name);
|
build_path(stk_tmp_dir, sizeof(stk_tmp_dir), stk_mod_dir, stk_tmp_name);
|
||||||
@@ -206,17 +208,25 @@ unsigned char stk_init(void)
|
|||||||
stk_error_string(dep_result));
|
stk_error_string(dep_result));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
init_batch = malloc(module_count * sizeof(*init_batch));
|
||||||
|
|
||||||
for (j = 0; j < module_count; j++) {
|
for (j = 0; j < module_count; j++) {
|
||||||
index = order ? order[j] : j;
|
index = order ? order[j] : j;
|
||||||
dep_result = stk_validate_dependencies_single(index);
|
dep_result = stk_validate_dependencies_single(index);
|
||||||
if (dep_result != STK_MOD_INIT_SUCCESS) {
|
if (dep_result != STK_MOD_INIT_SUCCESS) {
|
||||||
stk_log_dependency_failures(index, "Deferring");
|
stk_log_dependency_failures(index, "Deferring");
|
||||||
build_path(mod_tmp_path, sizeof(mod_tmp_path),
|
if (init_batch) {
|
||||||
stk_tmp_dir, stk_modules[index].id);
|
build_path(init_batch[init_batch_count],
|
||||||
strncat(mod_tmp_path, STK_MODULE_EXT,
|
sizeof(init_batch[init_batch_count]),
|
||||||
sizeof(mod_tmp_path) - strlen(mod_tmp_path) -
|
stk_tmp_dir, stk_modules[index].id);
|
||||||
1);
|
strncat(
|
||||||
stk_pending_add(mod_tmp_path);
|
init_batch[init_batch_count],
|
||||||
|
STK_MODULE_EXT,
|
||||||
|
sizeof(init_batch[init_batch_count]) -
|
||||||
|
strlen(init_batch[init_batch_count]) -
|
||||||
|
1);
|
||||||
|
init_batch_count++;
|
||||||
|
}
|
||||||
stk_module_discard(index);
|
stk_module_discard(index);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -227,6 +237,14 @@ unsigned char stk_init(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (init_batch_count > 0)
|
||||||
|
stk_pending_add_batch(
|
||||||
|
(const char (*)[STK_PATH_MAX_OS])init_batch,
|
||||||
|
init_batch_count);
|
||||||
|
|
||||||
|
free(init_batch);
|
||||||
|
init_batch = NULL;
|
||||||
|
|
||||||
if (order) {
|
if (order) {
|
||||||
free(order);
|
free(order);
|
||||||
order = NULL;
|
order = NULL;
|
||||||
@@ -291,7 +309,7 @@ size_t stk_poll(void)
|
|||||||
unload_count = 0;
|
unload_count = 0;
|
||||||
int *reloaded_mod_indices = NULL, *reloaded_mod_file_indices = NULL,
|
int *reloaded_mod_indices = NULL, *reloaded_mod_file_indices = NULL,
|
||||||
*unloaded_mod_indices = NULL, *loaded_mod_indices = NULL;
|
*unloaded_mod_indices = NULL, *loaded_mod_indices = NULL;
|
||||||
size_t remaining_loads, new_capacity, holes_to_fill;
|
size_t new_capacity;
|
||||||
char full_path[STK_PATH_MAX_OS], tmp_path[STK_PATH_MAX_OS];
|
char full_path[STK_PATH_MAX_OS], tmp_path[STK_PATH_MAX_OS];
|
||||||
char mod_id[STK_MOD_ID_BUFFER];
|
char mod_id[STK_MOD_ID_BUFFER];
|
||||||
int load_result;
|
int load_result;
|
||||||
@@ -303,15 +321,17 @@ size_t stk_poll(void)
|
|||||||
size_t expanded_count;
|
size_t expanded_count;
|
||||||
size_t index, oi;
|
size_t index, oi;
|
||||||
int is_orig;
|
int is_orig;
|
||||||
char dep_tmp_path[STK_PATH_MAX_OS];
|
|
||||||
size_t write;
|
size_t write;
|
||||||
size_t li;
|
int file_index, mod_index;
|
||||||
int fi;
|
size_t *cascade_indices = NULL;
|
||||||
int file_index, mod_index, target_index;
|
|
||||||
size_t cascade_indices[STK_PATH_MAX];
|
|
||||||
size_t cascade_count;
|
size_t cascade_count;
|
||||||
char cascade_tmp_path[STK_PATH_MAX_OS];
|
|
||||||
size_t j, k, cascade_write;
|
size_t j, k, cascade_write;
|
||||||
|
char (*dep_batch)[STK_PATH_MAX_OS] = NULL;
|
||||||
|
size_t dep_batch_count = 0;
|
||||||
|
char (*cascade_batch)[STK_PATH_MAX_OS] = NULL;
|
||||||
|
size_t cascade_batch_count = 0;
|
||||||
|
char (*load_batch)[STK_PATH_MAX_OS] = NULL;
|
||||||
|
size_t load_batch_count = 0;
|
||||||
|
|
||||||
if (module_count > 0) {
|
if (module_count > 0) {
|
||||||
module_ids = malloc(module_count * sizeof(*module_ids));
|
module_ids = malloc(module_count * sizeof(*module_ids));
|
||||||
@@ -387,8 +407,7 @@ size_t stk_poll(void)
|
|||||||
goto begin_operations;
|
goto begin_operations;
|
||||||
|
|
||||||
handle_grow:
|
handle_grow:
|
||||||
remaining_loads = load_count - unload_count;
|
new_capacity = module_count + load_count;
|
||||||
new_capacity = module_count + remaining_loads;
|
|
||||||
if (stk_module_realloc_memory(new_capacity) != STK_MOD_INIT_SUCCESS)
|
if (stk_module_realloc_memory(new_capacity) != STK_MOD_INIT_SUCCESS)
|
||||||
goto free_poll;
|
goto free_poll;
|
||||||
|
|
||||||
@@ -400,9 +419,13 @@ begin_operations:
|
|||||||
for (i = 0; i < unload_count; i++)
|
for (i = 0; i < unload_count; i++)
|
||||||
unload_order[i] = (size_t)unloaded_mod_indices[i];
|
unload_order[i] = (size_t)unloaded_mod_indices[i];
|
||||||
|
|
||||||
stk_collect_dependents(unload_order, &expanded_count);
|
stk_collect_dependents(unload_order, &expanded_count,
|
||||||
|
module_count);
|
||||||
stk_sort_unload_order(unload_order, expanded_count);
|
stk_sort_unload_order(unload_order, expanded_count);
|
||||||
|
|
||||||
|
dep_batch = malloc(expanded_count * sizeof(*dep_batch));
|
||||||
|
dep_batch_count = 0;
|
||||||
|
|
||||||
for (i = 0; i < expanded_count; i++) {
|
for (i = 0; i < expanded_count; i++) {
|
||||||
index = unload_order[i];
|
index = unload_order[i];
|
||||||
|
|
||||||
@@ -417,17 +440,27 @@ begin_operations:
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!is_orig) {
|
if (!is_orig && dep_batch) {
|
||||||
build_path(dep_tmp_path, sizeof(dep_tmp_path),
|
build_path(dep_batch[dep_batch_count],
|
||||||
|
sizeof(dep_batch[dep_batch_count]),
|
||||||
stk_tmp_dir, stk_modules[index].id);
|
stk_tmp_dir, stk_modules[index].id);
|
||||||
strncat(dep_tmp_path, STK_MODULE_EXT,
|
strncat(
|
||||||
sizeof(dep_tmp_path) -
|
dep_batch[dep_batch_count], STK_MODULE_EXT,
|
||||||
strlen(dep_tmp_path) - 1);
|
sizeof(dep_batch[dep_batch_count]) -
|
||||||
stk_pending_add(dep_tmp_path);
|
strlen(dep_batch[dep_batch_count]) - 1);
|
||||||
|
dep_batch_count++;
|
||||||
}
|
}
|
||||||
|
|
||||||
stk_module_unload(index);
|
stk_module_unload(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (dep_batch_count > 0)
|
||||||
|
stk_pending_add_batch(
|
||||||
|
(const char (*)[STK_PATH_MAX_OS])dep_batch,
|
||||||
|
dep_batch_count);
|
||||||
|
|
||||||
|
free(dep_batch);
|
||||||
|
dep_batch = NULL;
|
||||||
free(unload_order);
|
free(unload_order);
|
||||||
unload_order = NULL;
|
unload_order = NULL;
|
||||||
} else {
|
} else {
|
||||||
@@ -479,14 +512,12 @@ begin_operations:
|
|||||||
stk_error_string(load_result));
|
stk_error_string(load_result));
|
||||||
}
|
}
|
||||||
|
|
||||||
holes_to_fill = (load_count < unload_count) ? load_count : unload_count;
|
for (i = 0; i < load_count; i++) {
|
||||||
|
file_index = loaded_mod_indices[i];
|
||||||
for (li = 0; li < load_count; li++) {
|
|
||||||
fi = loaded_mod_indices[li];
|
|
||||||
build_path(full_path, sizeof(full_path), stk_mod_dir,
|
build_path(full_path, sizeof(full_path), stk_mod_dir,
|
||||||
file_list[fi]);
|
file_list[file_index]);
|
||||||
build_path(tmp_path, sizeof(tmp_path), stk_tmp_dir,
|
build_path(tmp_path, sizeof(tmp_path), stk_tmp_dir,
|
||||||
file_list[fi]);
|
file_list[file_index]);
|
||||||
platform_copy_file(full_path, tmp_path);
|
platform_copy_file(full_path, tmp_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -494,33 +525,10 @@ begin_operations:
|
|||||||
stk_sort_load_order(loaded_mod_indices, load_count, file_list,
|
stk_sort_load_order(loaded_mod_indices, load_count, file_list,
|
||||||
stk_tmp_dir);
|
stk_tmp_dir);
|
||||||
|
|
||||||
for (i = 0; i < holes_to_fill; ++i) {
|
load_batch = malloc(load_count * sizeof(*load_batch));
|
||||||
target_index = unloaded_mod_indices[i];
|
load_batch_count = 0;
|
||||||
file_index = loaded_mod_indices[i];
|
|
||||||
|
|
||||||
build_path(tmp_path, sizeof(tmp_path), stk_tmp_dir,
|
for (i = 0; i < load_count; ++i) {
|
||||||
file_list[file_index]);
|
|
||||||
|
|
||||||
load_result = stk_module_load(tmp_path, target_index);
|
|
||||||
if (load_result == STK_MOD_DEP_NOT_FOUND_ERROR ||
|
|
||||||
load_result == STK_MOD_DEP_VERSION_MISMATCH_ERROR) {
|
|
||||||
stk_pending_add(tmp_path);
|
|
||||||
} else if (load_result != STK_MOD_INIT_SUCCESS) {
|
|
||||||
stk_log(STK_LOG_ERROR, "Failed to load module %s: %s",
|
|
||||||
file_list[file_index],
|
|
||||||
stk_error_string(load_result));
|
|
||||||
} else {
|
|
||||||
module_count++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (load_count > unload_count)
|
|
||||||
goto append_modules;
|
|
||||||
|
|
||||||
goto validate_deps;
|
|
||||||
|
|
||||||
append_modules:
|
|
||||||
for (; i < load_count; ++i) {
|
|
||||||
file_index = loaded_mod_indices[i];
|
file_index = loaded_mod_indices[i];
|
||||||
|
|
||||||
build_path(tmp_path, sizeof(tmp_path), stk_tmp_dir,
|
build_path(tmp_path, sizeof(tmp_path), stk_tmp_dir,
|
||||||
@@ -530,7 +538,9 @@ append_modules:
|
|||||||
successful_appends);
|
successful_appends);
|
||||||
if (load_result == STK_MOD_DEP_NOT_FOUND_ERROR ||
|
if (load_result == STK_MOD_DEP_NOT_FOUND_ERROR ||
|
||||||
load_result == STK_MOD_DEP_VERSION_MISMATCH_ERROR) {
|
load_result == STK_MOD_DEP_VERSION_MISMATCH_ERROR) {
|
||||||
stk_pending_add(tmp_path);
|
if (load_batch)
|
||||||
|
memcpy(load_batch[load_batch_count++], tmp_path,
|
||||||
|
STK_PATH_MAX_OS);
|
||||||
} else if (load_result != STK_MOD_INIT_SUCCESS) {
|
} else if (load_result != STK_MOD_INIT_SUCCESS) {
|
||||||
stk_log(STK_LOG_ERROR, "Failed to load module %s: %s",
|
stk_log(STK_LOG_ERROR, "Failed to load module %s: %s",
|
||||||
file_list[file_index],
|
file_list[file_index],
|
||||||
@@ -542,9 +552,17 @@ append_modules:
|
|||||||
|
|
||||||
module_count += successful_appends;
|
module_count += successful_appends;
|
||||||
|
|
||||||
if (successful_appends < (load_count - holes_to_fill))
|
if (successful_appends < load_count)
|
||||||
stk_module_realloc_memory(module_count);
|
stk_module_realloc_memory(module_count);
|
||||||
|
|
||||||
|
if (load_batch_count > 0)
|
||||||
|
stk_pending_add_batch(
|
||||||
|
(const char (*)[STK_PATH_MAX_OS])load_batch,
|
||||||
|
load_batch_count);
|
||||||
|
|
||||||
|
free(load_batch);
|
||||||
|
load_batch = NULL;
|
||||||
|
|
||||||
goto validate_deps;
|
goto validate_deps;
|
||||||
|
|
||||||
validate_deps:
|
validate_deps:
|
||||||
@@ -554,6 +572,10 @@ validate_deps:
|
|||||||
do {
|
do {
|
||||||
cascade_count = 0;
|
cascade_count = 0;
|
||||||
|
|
||||||
|
cascade_indices = malloc(module_count * sizeof(size_t));
|
||||||
|
if (!cascade_indices)
|
||||||
|
break;
|
||||||
|
|
||||||
for (j = 0; j < module_count; j++) {
|
for (j = 0; j < module_count; j++) {
|
||||||
if (stk_modules[j].dep_count == 0)
|
if (stk_modules[j].dep_count == 0)
|
||||||
continue;
|
continue;
|
||||||
@@ -566,21 +588,43 @@ validate_deps:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cascade_count == 0)
|
if (cascade_count == 0) {
|
||||||
|
free(cascade_indices);
|
||||||
|
cascade_indices = NULL;
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
cascade_batch = malloc(cascade_count * sizeof(*cascade_batch));
|
||||||
|
cascade_batch_count = 0;
|
||||||
|
|
||||||
for (j = 0; j < cascade_count; j++) {
|
for (j = 0; j < cascade_count; j++) {
|
||||||
index = cascade_indices[j];
|
index = cascade_indices[j];
|
||||||
stk_log_dependency_failures(index, "Unloading");
|
stk_log_dependency_failures(index, "Unloading");
|
||||||
build_path(cascade_tmp_path, sizeof(cascade_tmp_path),
|
if (cascade_batch) {
|
||||||
stk_tmp_dir, stk_modules[index].id);
|
build_path(
|
||||||
strncat(cascade_tmp_path, STK_MODULE_EXT,
|
cascade_batch[cascade_batch_count],
|
||||||
sizeof(cascade_tmp_path) -
|
sizeof(cascade_batch[cascade_batch_count]),
|
||||||
strlen(cascade_tmp_path) - 1);
|
stk_tmp_dir, stk_modules[index].id);
|
||||||
stk_pending_add(cascade_tmp_path);
|
strncat(
|
||||||
|
cascade_batch[cascade_batch_count],
|
||||||
|
STK_MODULE_EXT,
|
||||||
|
sizeof(cascade_batch[cascade_batch_count]) -
|
||||||
|
strlen(cascade_batch
|
||||||
|
[cascade_batch_count]) -
|
||||||
|
1);
|
||||||
|
cascade_batch_count++;
|
||||||
|
}
|
||||||
stk_module_unload(index);
|
stk_module_unload(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (cascade_batch_count > 0)
|
||||||
|
stk_pending_add_batch(
|
||||||
|
(const char (*)[STK_PATH_MAX_OS])cascade_batch,
|
||||||
|
cascade_batch_count);
|
||||||
|
|
||||||
|
free(cascade_batch);
|
||||||
|
cascade_batch = NULL;
|
||||||
|
|
||||||
cascade_write = 0;
|
cascade_write = 0;
|
||||||
for (j = 0; j < module_count; j++) {
|
for (j = 0; j < module_count; j++) {
|
||||||
if (stk_modules[j].handle != NULL) {
|
if (stk_modules[j].handle != NULL) {
|
||||||
@@ -592,6 +636,9 @@ validate_deps:
|
|||||||
}
|
}
|
||||||
module_count = cascade_write;
|
module_count = cascade_write;
|
||||||
|
|
||||||
|
free(cascade_indices);
|
||||||
|
cascade_indices = NULL;
|
||||||
|
|
||||||
} while (cascade_count > 0);
|
} while (cascade_count > 0);
|
||||||
|
|
||||||
if (module_count > 0)
|
if (module_count > 0)
|
||||||
|
|||||||
Reference in New Issue
Block a user