Archive: Stack plugin


Stack plugin
Last few days I'm wrote header on "C" with linear (one direction) and bilinear (two directions) stack functions. I has thought if make NSIS plugin that probably will be useful for somebody.

Functions for working with NSIS stack (linear):
ns_push_front (same as Push)
ns_pop_front (same as Pop)
ns_push_back
ns_stack_read
ns_stack_write
ns_stack_size
ns_stack_free

Functions for working with private stack (bilinear):
dll_push_front
dll_pop_front
dll_push_back
dll_pop_back
dll_stack_read
dll_stack_write
dll_stack_insert
dll_stack_delete
dll_stack_size
dll_stack_free


Cool :up:
I can share with you my NOT crt function of lstrcmp since once I also use it :tinfoil:

int_stdcall_strcmp(char*s1,char*s2)

{
for(;*
s1&&*s2;++s1,++s2)
{
if(*
s1!=*s2)
{
break;
}
}
return*
s1-*s2;
}

If you talk about lstrcmp, probably the correct variant will be:

int__stdcall_strcmp(char*s1,char*s2)

{
for(;(*
s1)&&(*s2);++s1,++s2)
if(*
s1<*s2)
return-
1;
elseif(*
s1>*s2)
return
1;

if((!*
s1)&&(!*s2))
return
0;
elseif(!*
s1)
return-
1;
else
return
1;
}

lstrcmp is not part of CRT. You're confusing it with strcmp. lstrcmp is a Windows API, defined in kernel32.dll. There's no need to write a replacement for it.


Changes:

- New: Supports multi-stack (StackFunc.h).
- Fixed: xitoa string missing terminating null character when number is "0" (ConvFunc.h).

Functions for working with NSIS stack (linear):
- ns_stack_free->ns_stack_clear (function now not uses pop_frontL)

Functions for working with private stack (bilinear):
- Changed: stack_insert now can insert element to the top and first places
- dll_stack_free->dll_stack_clear (function now not uses pop_front)
- New: stack_exchange
- New: stack_delete_range
- New: stack_move
- New: stack_move_range
- New: stack_sort
- New: stack_reverse_range


Changes:

- New: stack::dll_push_sort (Pushs element to the stack and sorts alphabetically in ascending or descending)

- Added example how to sort lines in a text file

- Supports custom structures (StackFunc.h)


"Stack" plugin v1.2


1. New:
dll_push_sort_int
dll_sort_all_int
Debug

2. Renamed:
ns_stack_read->ns_read
ns_stack_write->ns_write
ns_stack_size->ns_size
ns_stack_clear->ns_clear
dll_stack_read->dll_read
dll_stack_write->dll_write
dll_stack_insert->dll_insert
dll_stack_exchange->dll_exchange
dll_stack_reverse_range->dll_reverse_range
dll_stack_delete->dll_delete
dll_stack_delete_range->dll_delete_range
dll_stack_move->dll_move
dll_stack_move_range->dll_move_range
dll_stack_sort->dll_sort_all
dll_stack_size->dll_size
dll_stack_clear->dll_clear

Update from previous versions:
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- Insert line in script:
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;!include "Stack.nsh"
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- Replace:
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;stack::ns_push_front -> ${stack::ns_push_front} ...
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- Replace:
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.r0 -> $0, .r1 -> $1 ... .R0 -> $R0, .R1 -> $R1 ...


"Stack" plugin v1.4


nice one.


Updated: "StackFunc.h" to v1.7
Added: now possible dynamically create private stacks, all private stack functions
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;now require stack handle in first parameter
Removed: dll_push_front, dll_pop_front, dll_push_back, dll_pop_back, because
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dll_insert and dll_delete can be used

"Stack" plugin v1.5


Updated: "StackFunc.h" to v1.8

"Stack" plugin v1.6


Updated: "StackFunc.h" to v3.0

"Stack" plugin v1.7


The documentation doesn't mention that you have to clear a private stack before you destroy it, otherwise memory is leaked for the elements on the stack!


There appears to be a memory leak in the private stacks. I just created a test script that inserts 10,000 elements, then deletes them.
Memory usage before create: 1,380KB
Memory usage after create: 1,392KB
Memory usage after 10,000 inserts: 12,432KB
Memory usage after 10,000 deletes: 2,712KB
Destroyed but not unloaded: 2,588 KB

I tried the same thing with inserting and deleting 1,000,000 elements (this took a long time to run) and the memory usage at the end was over 190 MB !


Added: full unicode support on NSIS Unicode.
Fixed: ${stack::dll_destroy} didn't erase the stack before destroying.

Stack plugin v1.8


I've found Stack precious in several scripts, thank you. Nice to see it up to date.


Added: ${stack::ns_pop_back} - removes the element from the end of the NSIS stack and puts it in the variable.
Added: ${stack::ns_insert} - inserts new element at specified index of the NSIS stack.
Added: ${stack::ns_delete} - finds the NSIS element by index, puts it in the variable and removes it.

Stack plugin v2.0