* Fix#633: Bound ChaiScript call stack to prevent native stack overflow
Recursive user-defined operators (e.g. a `string::/=` whose body calls
itself through string interpolation) drove the AST evaluator into
unbounded native recursion and crashed the host process with SIGSEGV.
The dispatcher now refuses to enter a new function frame once
`Stack_Holder::call_depth` reaches `chaiscript::max_call_depth`
(default 256, overridable via the `CHAISCRIPT_MAX_CALL_DEPTH` macro)
and throws the new `chaiscript::exception::stack_overflow_error`
instead, letting both ChaiScript-level `try`/`catch` and C++ hosts
recover from runaway recursion.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* Address review: tighten max_call_depth on MSVC Debug
Windows MSVC Debug builds crashed unit.recursion_depth_protection.chai
with SEGFAULT before the depth check could fire. Windows defaults to a
1 MiB thread stack and Debug builds emit much larger per-frame native
stack usage (no inlining, /RTC, buffer security checks), so 256 nested
ChaiScript calls overflow the native stack long before the dispatcher
reaches max_call_depth. Linux/macOS and MSVC Release pass at 256.
Pick a tighter default (32) only for the MSVC + _DEBUG configuration
that needs it, leaving every other build at the original 256, and shrink
the count_down recursion in the regression test so the bounded path
stays well below every platform's default.
Requested by @lefticus in PR #700 review.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* Address review: use CHAISCRIPT_DEBUG instead of _DEBUG
Switch CHAISCRIPT_DEBUG from a true/false definition to 1/0 so it can
be used in preprocessor #if expressions, then reuse it for the MSVC
Debug guard around CHAISCRIPT_MAX_CALL_DEPTH instead of testing the
compiler-private _DEBUG macro directly. The C++ debug_build constant
keeps its bool value through implicit conversion.
Requested by @lefticus in PR #700 review.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* Address review: restore CHAISCRIPT_DEBUG to true/false for stronger typing
C++ preserves the true/false keywords in #if directives ([cpp.cond]),
so the MSVC Debug guard around CHAISCRIPT_MAX_CALL_DEPTH still works
without weakening the macro to integer 1/0.
Requested by @lefticus in PR #700 review.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
---------
Co-authored-by: leftibot <leftibot@users.noreply.github.com>
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
The function_less_than comparator used by std::stable_sort violated the
strict-weak ordering requirement in two ways: (1) functions with different
arities but matching overlapping parameters were treated as equivalent,
breaking transitivity, and (2) the dynamic_object_type_name comparison
silently fell through when one side had an empty type name. Fixed by
ordering by arity when overlapping parameters match, and imposing a total
order on dynamic object type names.
Co-authored-by: leftibot <leftibot@users.noreply.github.com>
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-authored-by: Jason Turner <jason@emptycrate.com>
* Fix#655: Join async threads before engine destruction to prevent heap-use-after-free
Issues #632 and #636 (PRs #651 and #653) both stem from the same root cause: async
threads spawned via async() can outlive the Dispatch_Engine, accessing shared state
(global objects map, type maps) after it has been destroyed. The fix moves async()
registration from the stdlib module into ChaiScript_Basic, where spawned threads are
tracked via Dispatch_Engine. The engine's destructor now joins all outstanding async
threads before destroying shared data structures.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* Address review: follow rule of 5, explicitly default move operations
Requested by @lefticus in PR #656 review.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
---------
Co-authored-by: leftibot <leftibot@users.noreply.github.com>
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* Fix#201: Add class inheritance support with Derived : Base syntax
Classes can now inherit methods and attributes from a base class using
C++-style syntax: `class Derived : Base { ... }`. Base class methods and
attributes are automatically available on derived objects. Derived classes
can override base methods by defining a method with the same name.
Inheritance relationships are tracked to support proper type matching
in the dispatch system.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* Address review: use implicit derived-to-base matching instead of copying base class functions
Instead of copying all base class methods/attributes into derived classes,
make the type matching system recognize inheritance relationships. Base class
methods now naturally match derived objects through dynamic_object_typename_match,
and dispatch ordering ensures derived overrides are preferred over base methods.
This is simpler (net -25 lines) and avoids duplicating function registrations.
Requested by @lefticus in PR #641 review.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* Add tests for passing derived objects to functions expecting Base
Tests cover: free functions calling base methods on derived objects,
polymorphic dispatch through containers, base attribute access on
derived objects, and multi-level inheritance (GrandChild : Derived : Base).
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* Add typed parameter tests for class inheritance
Use typed function signatures (e.g., `def call_do_something(Base obj)`)
instead of untyped parameters to test that derived objects are accepted
by functions expecting a base type, with correct polymorphic dispatch.
Requested by @lefticus in PR #641 review.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
---------
Co-authored-by: leftibot <leftibot@users.noreply.github.com>
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
I initially tried to use the existing .clang-format file,
but it does not match the code style (at least with clang-format 11)
and the formatting is not consistent across files.
Therefore, I decided to rewrite the .clang-format with some personal
preferences.
Used command
find . -iname "*.hpp" -o -iname "*.cpp" | xargs clang-format -i -style=file
This modifies no logic, it simply adds the keyword `noexcept`
I believe this is 100% correct. It calls methods that are not
guaranteed to be `noexcept`, such as `operator[]` but have
no logically way of throwing.