Commit graph

404 commits

Author SHA1 Message Date
Alexander Motzkau
831aaf0c05 Add iterators to variables and functions types
Allow iterating over function list, local and global variables. The
iterators will give the list of functions/variables in program order.
2025-07-07 22:14:05 +02:00
Alexander Motzkau
d0904f9913 Added str() operator to Python representation of LPC types
str(lpctype) returns the LPC code of the LPC type.
2025-07-07 22:14:05 +02:00
Alexander Motzkau
25ab0f48bc Added separate Python types for various closure types
Added LfunClosure, (Simul)EfunClosure, (Unbound/Bound)LambdaClosure and
OperatorClosure types for Python.
2025-07-07 22:14:05 +02:00
Alexander Motzkau
f7c95ae898 Add program_name member function to ldmud.Object object
To streamline Python representations for normal and lightweight objects
also add a program_name member function to normal objects.
2025-07-07 22:14:05 +02:00
Alexander Motzkau
1895ab4790 Make struct members iterable in Python
Add len and [] implementation to Python struct member list,
so they can be iterated over in definition order.
2025-07-07 22:14:05 +02:00
Alexander Motzkau
2c173d9322 Make Python representations of LPC values hashable
Add hash and eq function to all Python implementations,
so all LPC values can be used in Python dictionaries as keys.
2025-07-07 22:14:05 +02:00
Alexander Motzkau
8b3031d3b4 With pragma save_local_names save debugging info for local variables
Previously pragma save_local_names was only used to store information of
variables of coroutines to be inspected by Python code. Extend this to
all local variables.
2025-07-07 22:14:05 +02:00
Alexander Motzkau
eade730e47 Publish standard and Python registered structs
Standard struct definition where not usable in dynamic settings
(e.g. to_type()), as the definition was not registered to the corresponding
struct name and type.
2025-07-07 22:14:05 +02:00
Alexander Motzkau
15166819ed Implement Python-registered structs
Python can register global struct definitions via ldmud.register_struct().
Also added corresponding namespace ldmud.registered_structs that contains
all registered struct types.
2025-07-07 22:14:05 +02:00
Alexander Motzkau
0142ebbd27 Added abilities to Python integration to trace LPC program execution
Added BEFORE_INSTRUCTION hook to be called for every instruction.
Added call_stack property to query the current stack.
2025-07-07 22:14:05 +02:00
Alexander Motzkau
6ab27def56 Fix detection of inherited prototypes with optional arguments
Prototype-only functions are detected by looking at the first opcode of the
function. If the prototype has optional arguments, then the first bytes is
a jump table for argument initialization. The detection needs to look beyond
that.
2025-07-07 22:12:22 +02:00
Alexander Motzkau
629bb1bba9 Fix crash when calling an undefined function without optional arguments
For every prototype-only function the compiler creates a stub at the end that
throws the undefined function error. However this stub was missing the jump
table for optional arguments, writing the error opcode in its place instead.
This resulted in an invalid table and missing opcode after the table.
Both could result in a crash, depending on whether the function is called
with or without the optional argument.
2025-07-07 22:12:22 +02:00
Alexander Motzkau
3a44b17698 Fixed several problems with parse_command()
The pattern leaked (Thanks, Daniel Nilsson for the fix).
An explicitly passed preposition array would leak.
Arguments were treated as unprotected lvalues, even though they are protected.
The cleanup routine was not called, thus leaking data in global variables.
2025-04-01 21:40:42 +02:00
Adam Michaud
657e3ccab1 Mention the file name on inherit-self errors
Adds the name of the file that is trying to inherit itself,
making it easier to track down circular inheritance issues.
2025-03-22 21:12:48 +01:00
Alexander Motzkau
f7e47e3d79 Fix m_contains() to copy values as rvalues
If the mapping contains rvalue references (e.g. created by walk_mapping)
dereference them before copying them into the target lvalues.
2025-03-21 21:30:30 +01:00
Alexander Motzkau
9317cc0116 Fix compile error with pragma save_local_names
When pragma save_local_names was in effect, a former local variable could
lead to the compile error "Missing variable information" as the compiler
was trying to save that name as well.
2025-03-21 21:30:30 +01:00
Alexander Motzkau
e453976fdd Fix crash in Python's register_type() function
When a type was registered a second time, the cleanup function might call
xfree() on invalid pointers.
2025-03-21 21:30:30 +01:00
Alexander Motzkau
1359334924 Fix memory leak and information leakage in execute_command()
When execute_command() is called, the marker was not freed.
Also it added a byte from the previous invocation to the end of the command.
2025-03-21 21:30:30 +01:00
Alexander Motzkau
1dcd72d0cb Add tests for match_command() 2025-03-21 21:30:30 +01:00
Alexander Motzkau
b6e70a7e6c Fix crash when Python calls a destructed object
When calling an lfun from Python, the corresponding object was not
checked accordingly.
2025-03-21 21:30:30 +01:00
Alexander Motzkau
eb6032b002 Fix variable/function use in inline closures in compile_string()
When a variable, function or struct given via a lookup mapping or
closure to compile_string() was used in different closures
(e.g., used directly and used in an inline closure), the necessary
values were only added to one of the generated lambda closures,
resulting in a crash when executing the other.
2025-03-21 21:30:30 +01:00
Alexander Motzkau
ce768cdc16 Don't use transfer_svalue() for apply_return_value
Several functions use apply_return_value to store the result of a callback
call. transfer_svalue() should override any previous value in it, but if
it contains an lvalue, the new value will be assigned to the lvalue instead.
Use pop_apply_value() instead, it makes sure, this doesn't happen.
2025-03-21 21:30:30 +01:00
Alexander Motzkau
2520452295 Fix non-virtual variable lookup in compile_string()
When use_object_variables is true and the object has virtual as well as
non-virtual variables, the access to the non-virtual variables by
compile_string() was off by the number of virtual variables.
2025-03-21 21:30:30 +01:00
Alexander Motzkau
7b35a5463b Added Menaures' Crasher as a test setup
With './run.sh crasher' the crasher can be called for testing the driver
without a mudlib. The config.h contains some configuration options.
2025-03-21 21:30:30 +01:00
Alexander Motzkau
50ab31c108 Fix cleanup when building arguments for LPC calls from Python
When Python code called into LPC with invalid arguments,
there was an off-by-one error when cleaning up arguments on the stack.
2025-03-21 21:30:30 +01:00
Alexander Motzkau
1db6633aab Implement to_type() efun
to_type() converts a value to a given target type.
If required, does so recursively.
2025-03-21 21:30:30 +01:00
Alexander Motzkau
d2f1b8bb1f Implemented asynchronous name lookup using C-Ares
Added build option --enable-anl to enable asynchronous lookup for
net_connect() and logged on players. For the later replacing the ERQ
calls, thereby entirely removing the necessity of ERQ for the driver.
2025-03-21 21:30:30 +01:00
Alexander Motzkau
0849bc2fc1 Fix crash on __INT_MIN__ % -1
(At least) on Intel processors modulo division is done together with normal
division resulting in an exception when the division results exceeds the
value range. Therefore fix the special case of __INT_MIN__ % -1, where
division would not be allowed, but modulo is well defined.
2025-03-21 21:30:30 +01:00
Alexander Motzkau
aad939a23a Fix memory leak in sl_open() 2025-03-21 21:30:30 +01:00
Alexander Motzkau
ca277d588d Fix memory leak in to_text() 2025-03-21 21:30:30 +01:00
Alexander Motzkau
4a54615787 Fix a crash with or operator on lpctypes 2025-03-21 21:30:30 +01:00
Alexander Motzkau
b0960f7759 Check for uncallable closures on callback setup
Efuns like call_out, add_action, map or filter will throw immediately when
they're given an uncallable closure for callback. Also improved structure
of call_lambda() and fixed giving an error message without a control stack
entry. (Fixes #908)
2025-03-21 21:30:30 +01:00
Alexander Motzkau
8b2b719784 Added sub-namespace for registered efuns and types
ldmud.registered_efuns contains all registered Python efuns and
ldmud.registered_types provides all registered Python types.
Those are read-only, for manipulation there is (un)register_efun/type().
2025-03-21 21:30:30 +01:00
Alexander Motzkau
266d873998 Disregard negative zeros for floating point numbers
As LDMud doesn't support NaN and +/-Inf anyways, supporting negative zeros
is only confusing. So collapse them into normal zeroes. (This was the
case before LDMud 3.5.0 with the old float format anyways.)
2025-03-21 21:30:30 +01:00
Alexander Motzkau
5059b8583a Fix memory leak in compile_string()
When a provided variable/function/struct lookup function returns the same value
for different names, the returned object leaks.
2025-03-21 21:30:30 +01:00
Alexander Motzkau
2b07a966a4 Fix get_type_info()/closure_to_string() showing wrong program name
get_type_info(cl, 3) should return the program/inherit containing the
target function, but instead returned the object's main program.
Similarly closure_to_string() did not print the inherit name for
inherited functions.
2023-09-27 20:06:59 +02:00
Alexander Motzkau
611d9f7cd8 Fix variable_exists() hanging in certain virtual inherit scenarios
variable_exists() could sometimes end up in an endless loop trying to
find the correct inherit entry due to a mixup of virtual and non-virtual
variable indices.
2023-08-17 21:54:51 +02:00
Alexander Motzkau
d6d79c35c2 Added option to compile_string for end detection
compile_string() with .detect_end != 0 stops compilation without an error
when the following token (character/word) cannot continue a parsed expression
or block.
2023-08-16 00:45:32 +02:00
Alexander Motzkau
11144cb5c1 Notify Python about all handled signals
Added a Python hook for signals SIGINT, SIGTERM, SIGHUP, SIGUSR1 and SIGUSR2.
2023-03-04 19:52:58 +01:00
Alexander Motzkau
4acf9fce6a Added tests for signal handling
Test the DC_SIGACTION_* options.
2023-03-03 23:25:56 +01:00
Alexander Motzkau
9aa13c55b8 Add 'limit' modifier to catch()
With catch(<expr>; limit <num>) an upper limit for the eval costs of the
expression can be specified.
2023-02-27 23:11:41 +01:00
Alexander Motzkau
a152c2a3fc Prevent multiple 'reserve modifiers with #'catch
Specifying 'reserve multiple times in a lambda expression will lead to a crash.
2023-02-27 22:50:31 +01:00
Alexander Motzkau
9a5f8bf424 Fixed return type of catch()
catch() can return arbitrary values (when throw() is used),
but the compiler assumed string.
2023-02-27 22:46:39 +01:00
Alexander Motzkau
ba0a7e7f1a Implement RTTC for compile_string()
Allow runtime type checks in lambdas by storing
the expected type as a lambda value.
2023-02-26 22:55:07 +01:00
Alexander Motzkau
52dc66d499 Add support for LPC type objects in Python
Fully support the LPC type system in Python, providing representations
for basic types (int, float, string, bytes), named (lightweight) object
types, concrete struct types and union types.
2022-10-10 23:38:01 +02:00
Alexander Motzkau
c9307cd297 Adapt to OpenSSL 3
Replace calls to deprecated functions with their modern versions.
Also use OpenSSL's builtin DH parameters instead our own.
2023-02-19 18:07:36 +01:00
Alexander Motzkau
c8d9c099b7 Fix crash (bad stack) when calling coroutines with efun::trace()
When efun::trace() is active, the stack pointer was modified in a wrong
way when executing a yield() statement.
2023-02-14 22:24:25 +01:00
Alexander Motzkau
9c219db7cf Release Python global interpreter lock when not executing Python code
The global interpreter lock is acquired during initialization and never
released. So if any Python modules start additional threads they can
hardly run, because the lock is held by the main thread mostly all of
the time.
2022-11-07 22:27:52 +01:00
Alexander Motzkau
fb691fa2ea Implement LPC Type objects
Add a new type 'lpctype' to contain a type object, describing a compile-time
type, together with a decltype() operator and to_lpctype() and check_type()
efuns.
2022-09-25 22:20:32 +02:00
Alexander Motzkau
73ed64c46b Fix save_value()/save_object() for Python objects
For non-saveable Python objects the delimiter (comma) was printed twice.
2022-09-29 23:11:19 +02:00