aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/undo.h
AgeCommit message (Collapse)AuthorFilesLines
2025-03-21fixed rubout of Q-Register specificationsRobin Haberkorn1-0/+1
* This was a regression introduced by 257a0bf128e109442dce91c4aaa1d97fed17ad1a. * The undo token that frees newly allocated teco_machine_qregspec_t must actually reset the pointer as well since any subsequent token, pushed by teco_undo_qregspec_own(), will expect a valid pointer. * Could have been done via ctx->expectqreg = NULL; teco_undo_qregspec_own(ctx->expectqreg); but using a special clear function requires less memory and is easier to understand. * Added test case. This wouldn't always crash, but should definitely show up in Valgrind.
2025-03-19fixed leaking data on ruboutRobin Haberkorn1-16/+21
* Objects, that are restored with TECO_DEFINE_UNDO_OBJECT_OWN(), could actually leak memory on rubout since the old object was not deleted when overwriting it. * Now that it is, it is crucial to at least nullify objects/pointers after calling the corresponding push-function. These conditions are now explicitly documented. * The test suite now runs successfully under Valgrind even with full leak checking.
2025-01-13updated copyright to 2025Robin Haberkorn1-1/+1
2024-09-12teco_string_get_coord() returns character offsets now (refs #5)Robin Haberkorn1-1/+1
* This is used for error messages (TECO macro stackframes), so it's important to display columns in characters. * Program counters are in bytes and therefore everywhere gsize. This is by glib convention.
2024-09-11the SciTECO parser is Unicode-based now (refs #5)Robin Haberkorn1-2/+2
The following rules apply: * All SciTECO macros __must__ be in valid UTF-8, regardless of the the register's configured encoding. This is checked against before execution, so we can use glib's non-validating UTF-8 API afterwards. * Things will inevitably get slower as we have to validate all macros first and convert to gunichar for each and every character passed into the parser. As an optimization, it may make sense to have our own inlineable version of g_utf8_get_char() (TODO). Also, Unicode glyphs in syntactically significant positions may be case-folded - just like ASCII chars were. This is is of course slower than case folding ASCII. The impact of this should be measured and perhaps we should restrict case folding to a-z via teco_ascii_toupper(). * The language itself does not use any non-ANSI characters, so you don't have to use UTF-8 characters. * Wherever the parser expects a single character, it will now accept an arbitrary Unicode/UTF-8 glyph as well. In other words, you can call macros like M§ instead of having to write M[§]. You can also get the codepoint of any Unicode character with ^^x. Pressing an Unicode character in the start state or in Ex and Fx will now give a sane error message. * When pressing a key which produces a multi-byte UTF-8 sequence, the character gets translated back and forth multiple times: 1. It's converted to an UTF-8 string, either buffered or by IME methods (Gtk). On Curses we could directly get a wide char using wget_wch(), but it's not currently used, so we don't depend on widechar curses. 2. Parsed into gunichar for passing into the edit command callbacks. This also validates the codepoint - everything later on can assume valid codepoints and valid UTF-8 strings. 3. Once the edit command handling decides to insert the key into the command line, it is serialized back into an UTF-8 string as the command line macro has to be in UTF-8 (like all other macros). 4. The parser reads back gunichars without validation for passing into the parser callbacks. * Flickering in the Curses UI and Pango warnings in Gtk, due to incompletely inserted and displayed UTF-8 sequences, are now fixed.
2024-01-21updated copyright to 2024Robin Haberkorn1-1/+1
2023-04-05updated copyright to 2023Robin Haberkorn1-1/+1
2022-06-21updated copyright to 2022 and updated TODORobin Haberkorn1-1/+1
2021-05-30THE GREAT CEEIFICATION EVENTRobin Haberkorn1-196/+203
This is a total conversion of SciTECO to plain C (GNU C11). The chance was taken to improve a lot of internal datastructures, fix fundamental bugs and lay the foundations of future features. The GTK user interface is now in an useable state! All changes have been squashed together. The language itself has almost not changed at all, except for: * Detection of string terminators (usually Escape) now takes the string building characters into account. A string is only terminated outside of string building characters. In other words, you can now for instance write I^EQ[Hello$world]$ This removes one of the last bits of shellisms which is out of place in SciTECO where no tokenization/lexing is performed. Consequently, the current termination character can also be escaped using ^Q/^R. This is used by auto completions to make sure that strings are inserted verbatim and without unwanted sideeffects. * All strings can now safely contain null-characters (see also: 8-bit cleanliness). The null-character itself (^@) is not (yet) a valid SciTECO command, though. An incomplete list of changes: * We got rid of the BSD headers for RB trees and lists/queues. The problem with them was that they used a form of metaprogramming only to gain a bit of type safety. It also resulted in less readble code. This was a C++ desease. The new code avoids metaprogramming only to gain type safety. The BSD tree.h has been replaced by rb3ptr by Jens Stimpfle (https://github.com/jstimpfle/rb3ptr). This implementation is also more memory efficient than BSD's. The BSD list.h and queue.h has been replaced with a custom src/list.h. * Fixed crashes, performance issues and compatibility issues with the Gtk 3 User Interface. It is now more or less ready for general use. The GDK lock is no longer used to avoid using deprecated functions. On the downside, the new implementation (driving the Gtk event loop stepwise) is even slower than the old one. A few glitches remain (see TODO), but it is hoped that they will be resolved by the Scintilla update which will be performed soon. * A lot of program units have been split up, so they are shorter and easier to maintain: core-commands.c, qreg-commands.c, goto-commands.c, file-utils.h. * Parser states are simply structs of callbacks now. They still use a kind of polymorphy using a preprocessor trick. TECO_DEFINE_STATE() takes an initializer list that will be merged with the default list of field initializers. To "subclass" states, you can simply define new macros that add initializers to existing macros. * Parsers no longer have a "transitions" table but the input_cb() may use switch-case statements. There are also teco_machine_main_transition_t now which can be used to implement simple transitions. Additionally, you can specify functions to execute during transitions. This largely avoids long switch-case-statements. * Parsers are embeddable/reusable now, at least in parse-only mode. This does not currently bring any advantages but may later be used to write a Scintilla lexer for TECO syntax highlighting. Once parsers are fully embeddable, it will also be possible to run TECO macros in a kind of coroutine which would allow them to process string arguments in real time. * undo.[ch] still uses metaprogramming extensively but via the C preprocessor of course. On the downside, most undo token generators must be initiated explicitly (theoretically we could have used embedded functions / trampolines to instantiate automatically but this has turned out to be dangereous). There is a TECO_DEFINE_UNDO_CALL() to generate closures for arbitrary functions now (ie. to call an arbitrary function at undo-time). This simplified a lot of code and is much shorter than manually pushing undo tokens in many cases. * Instead of the ridiculous C++ Curiously Recurring Template Pattern to achieve static polymorphy for user interface implementations, we now simply declare all functions to implement in interface.h and link in the implementations. This is possible since we no longer hace to define interface subclasses (all state is static variables in the interface's *.c files). * Headers are now significantly shorter than in C++ since we can often hide more of our "class" implementations. * Memory counting is based on dlmalloc for most platforms now. Unfortunately, there is no malloc implementation that provides an efficient constant-time memory counter that is guaranteed to decrease when freeing memory. But since we use a defined malloc implementation now, malloc_usable_size() can be used safely for tracking memory use. malloc() replacement is very tricky on Windows, so we use a poll thread on Windows. This can also be enabled on other supported platforms using --disable-malloc-replacement. All in all, I'm still not pleased with the state of memory limiting. It is a mess. * Error handling uses GError now. This has the advantage that the GError codes can be reused once we support error catching in the SciTECO language. * Added a few more test suite cases. * Haiku is no longer supported as builds are instable and I did not manage to debug them - quite possibly Haiku bugs were responsible. * Glib v2.44 or later are now required. The GTK UI requires Gtk+ v3.12 or later now. The GtkFlowBox fallback and sciteco-wrapper workaround are no longer required. * We now extensively use the GCC/Clang-specific g_auto feature (automatic deallocations when leaving the current code block). * Updated copyright to 2021. SciTECO has been in continuous development, even though there have been no commits since 2018. * Since these changes are so significant, the target release has been set to v2.0. It is planned that beginning with v3.0, the language will be kept stable.
2017-03-08undo stack reorganized into a stack of undo token listsRobin Haberkorn1-16/+28
* in a flat list of undo tokens, we need to store the program counter (ie. command line position) that the undo token corresponds to. Since in general there is more than one undo token per input character, this stored PCs redundantly. * For input characters with no undo tokens (only applies to NOPs like space in the command line macro), this needs one more pointer than before. * In case of 1 undo token per input character, the new implementation uses approx. the same memory. * In the most common case of more than one undo token per input character, this saves at least 4 bytes per undo token. * In large macros and long loops the effect is especially pronounced. E.g. 500000<%A> will use 8MB less memory with the new implementation.
2017-03-03updated copyright to 2017Robin Haberkorn1-1/+1
2016-11-20fixed glib warnings about using g_mem_set_vtable() and revised memory limitingRobin Haberkorn1-66/+6
* we were basing the glib allocators on throwing std::bad_alloc just like the C++ operators. However, this always was unsafe since we were throwing exceptions across plain-C frames (Glib). Also, the memory vtable has been deprecated in Glib, resulting in ugly warnings. * Instead, we now let the C++ new/delete operators work like Glib by basing them on g_malloc/g_slice. This means they will assert and the application will terminate abnormally in case of OOM. OOMs cannot be handled properly anyway, so it is more important to have a good memory limiting mechanism. * Memory limiting has been completely revised. Instead of approximating undo stack sizes using virtual methods (which is unprecise and comes with a performance penalty), we now use a common base class SciTECO::Object to count the memory required by all objects allocated within SciTECO. This is less precise than using global replacement new/deletes which would allow us to control allocations in all C++ code including Scintilla, but they are only supported as of C++14 (GCC 5) and adding compile-time checks would be cumbersome. In any case, we're missing Glib allocations (esp. strings). * As a platform-specific extension, on Linux/glibc we use mallinfo() to count the exact memory usage of the process. On Windows, we use GetProcessMemoryInfo() -- the latter implementation is currently UNTESTED. * We use g_malloc() for new/delete operators when there is malloc_trim() since g_slice does not free heap chunks properly (probably does its own mmap()ing), rendering malloc_trim() ineffective. We've also benchmarked g_slice on Linux/glib (malloc_trim() shouldn't be available elsewhere) and found that it brings no significant performance benefit. On all other platforms, we use g_slice since it is assumed that it at least does not hurt. The new g_slice based allocators should be tested on MSVCRT since I assume that they bring a significant performance benefit on Windows. * Memory limiting does now work in batch mode as well and is still enabled by default. * The old UndoTokenWithSize CRTP hack could be removed. UndoStack operations should be a bit faster now. But on the other hand, there will be an overhead due to repeated memory limit checking on every processed character.
2016-02-10avoid unnecessary undo token allocations in batch mode: greatly speeds up ↵Robin Haberkorn1-4/+44
batch mode * by using variadic templates, UndoStack::push() is now responsible for allocating undo tokens. This is avoided in batch mode. * The old UndoStack::push(UndoToken *) method has been made private to avoid confusion around UndoStack's API. The old UndoStack::push() no longer needs to handle !undo.enabled, but at least asserts on it. * C++11 support is now required, so variadic templates can be used. This could have also been done using manual undo.enabled checks; or using multiple versions of the template with different numbers of template arguments. The latter could be done if we one day have to support a non-C++11 compiler. However since we're depending on GCC 4.4, variadic template use should be OK. Clang supports it since v2.9. * Sometimes, undo token pushing passed ownership of some memory to the undo token. The old behaviour was relied on to reclaim the memory even in batch mode -- the undo token was always deleted. To avoid leaks or repeated manual undo.enabled checking, another method UndoStack::push_own() had to be introduced that makes sure that an undo token is always created. In batch mode (!undo.enabled), this will however create the object on the stack which is much cheaper than using `new`. * Having to know which kind of undo token is to be pushed (taking ownership or not) is inconvenient. It may be better to add static methods to the UndoToken classes that can take care of reclaiming memory. * Benchmarking certain SciTECO scripts have shown 50% (!!!) speed increases at the highest possible optimization level (-O3 -mtune=native -march=native).
2016-01-28updated copyright to 2016Robin Haberkorn1-1/+1
2015-03-02minor optimization: no need to check for NULL when using C++ delete operatorRobin Haberkorn1-4/+2
2015-03-01keep rubbed out command line for later re-insertion and massive Cmdline ↵Robin Haberkorn1-4/+4
cleanup/refactoring * characters rubbed out are not totally removed from the command line, but only from the *effective* command line. * The rubbed out command line is displayed after the command line cursor. On Curses it is grey and underlined. * When characters are inserted that are on the rubbed out part of the command line, the cursor simply moves forward. NOTE: There's currently no immediate editing command for reinserting the next character/word from the rubbed out command line. * Characters resulting in errors are no longer simply discarded but rubbed out, so they will stay in the rubbed out part of the command line, reminding you which character caused the error. * Improved Cmdline formatting on Curses UI: * Asterisk is printed bold * Control characters are printed in REVERSE style, similar to what Scinterm does. The controll character formatting has thus been moved from macro_echo() in cmdline.cpp to the UI implementations. * Updated the GTK+ UI (UNTESTED): I did only, the most important API adaptions. The command line still does not use any colors. * Refactored entire command line handling: * The command line is now a class (Cmdline), and most functions in cmdline.cpp have been converted to methods. * Esp. process_edit_cmd() (now Cmdline::process_edit_cmd()) has been simplified. There is no longer the possibility of a buffer overflow because of static insertion buffer sizes * Cleaned up usage of the cmdline_pos variable (now Cmdline::pc) which is really a program counter that used a different origin as macro_pc which was really confusing. * The new Cmdline class is theoretically 8-bit clean. However all of this will change again when we introduce Scintilla views for the command line. * Added 8-bit clean (null-byte aware) versions of QRegisterData::set_string() and QRegisterData::append_string()
2015-02-23implemented to undo stack memory limitingRobin Haberkorn1-6/+80
* acts as a safe-guard against uninterrupted infinite loops or other operations that are costly to undo in interactive mode. If we're out of memory, it is usually too late to react properly. This implementation tries to avoid OOMs due to SciTECO behaviour. We cannot fully exclude the chance of an OOM error. * The undo stack size is only approximated using the UndoToken::get_size() method. Other ways to measure the exact amount of allocated heap (including size fields in every heap object or using sbrk(0) and similar) are either costly in terms of memory or platform-specific. This implementation does not need any additional memory per heap object or undo token but exploits the fact that undo tokens are virtual already. The size of an undo token is determined at compile time. * Default memory limit of 500mb should be OK for most people. * The current limit can be queried with "2EJ" and set with <x>,2EJ. This also works interactively (a bit tricky!) * Limiting can be disabled. In this case, undo token processing is a bit faster. * closes #3
2015-02-11updated copyright to 2015Robin Haberkorn1-1/+1
2014-11-16first working version of the one-view-per-buffer designRobin Haberkorn1-23/+0
The user interface provides a Scintilla view abstraction and every buffer is based on a view. All Q-Register strings use a single dedicated view to save memory and initialization time when using many string registers. * this means we can finally implement a working lexer configuration and it only has to be done once when the buffer is first added to the ring. It is unnecessary to magically restore the lexer styles upon rubout of EB (very hard to implement anyway). It is also not necessary to rerun the lexer configuration macro upon rubout which would be hard to reconcile with SciTECO's basic design since every side-effect should be attached to a character. * this means that opening buffers is slightly slower now because of the view initialization * on the other hand, macros with many string q-reg operations are faster now, since the document must no longer be changed on the buffer's view and restored later on. * also now we can make a difference between editing a document in a view and changing the current view, which reduces UI calls * the Document class has been retained as an abstraction about Scintilla documents, used by QRegister Strings. It had to be made virtual, so the view on which the document is created can be specified by a virtual function. There is no additional space overhead for Documents.
2014-11-11added all of SciTECO's declarations to the "SciTECO" namespaceRobin Haberkorn1-1/+5
normally, since SciTECO is not a library, this is not strictly necessary since every library should use proper name prefixes or namespaces for all global declarations to avoid name clashes. However * you cannot always rely on that * Scintilla does violate the practice of using prefixes or namespaces. The public APIs are OK, but it does define global functions/methods, e.g. for "Document" that clashed with SciTECO's "TECODocument" class at link-time. Scintilla can put its definitions in a namespace, but this feature cannot be easily enabled without patching Scintilla. * a "SciTECO" namespace will be necessary if "SciTECO" is ever to be turned into a library. Even if this library will have only a C-linkage API, it must ensure it doesn't clutter the global namespace. So the old "TECODocument" class was renamed back to "Document" (SciTECO::Document).
2014-02-15updated Copyright to year 2014Robin Haberkorn1-1/+1
2013-02-17made UndoStack::push_msg() inlineRobin Haberkorn1-2/+6
2013-02-14undo tokens for changing an object pointerRobin Haberkorn1-0/+40
will care about the eventual deletion of the object
2013-01-19updated copyright (2012-2013)Robin Haberkorn1-1/+1
2012-12-04added copyright notice to every source fileRobin Haberkorn1-0/+17
2012-12-04autoconf preparation: move everything into src/ subdirRobin Haberkorn1-0/+134