Page 1 of 1
Array parameter in procedures
Posted: Tue Mar 01, 2011 12:31 pm
by PureLeo
Hi!
I'm just new to Tailbite...
I'm trying to make an userlib from this procedure:
Code: Select all
ProcedureDLL QuickSort(Array a(1), g.l, d.l)
If g < d
v = a(d)
i = g-1
j = d
Repeat
Repeat
i=i+1
Until a(i) >= v
ok = 0
Repeat
If j>0
j=j-1
Else
ok=1
EndIf
If a(j) <= v
ok=1
EndIf
Until ok<>0
tmp.l = a(i)
a(i) = a(j)
a(j) = tmp
Until j <= i
t = a(j)
a(j) = a(i)
a(i) = a(d)
a(d) = t
QuickSort(a(), g, i-1)
QuickSort(a(), i+1, d)
EndIf
EndProcedure
This procedure works fine.. but when I make a lib from it and run something like this:
Code: Select all
Dim teste(50)
teste(0) = 5
teste(1) = 2
teste(2) = 4
teste(3) = 3
teste(4) = 1
teste(5) = 6
QuickSort(teste(), 0,5) ;IMA
For a=0 To 5
Debug teste(a)
Next
Then I get an invalid memory access error...
I'm also too tired, maybe I'm missing something obvious, sorry if thats the case
Re: Array parameter in procedures
Posted: Wed Mar 02, 2011 10:33 pm
by ABBKlaus
i don´t know if this ever worked before, but the TailBiten code does not receive the adress to the array instead it points to the adress of the first element
Here is a workaround if you need one :
Code: Select all
Dim teste(50)
teste(0) = 5
teste(1) = 2
teste(2) = 4
teste(3) = 3
teste(4) = 1
teste(5) = 6
temp=@teste()
QuickSort(@temp, 0,5) ;No IMA
For a=0 To 5
Debug teste(a)
Next
Re: Array parameter in procedures
Posted: Wed Mar 02, 2011 11:44 pm
by PureLeo
Yes. I've just read that DLL's procedures also couldn't have an Array as parameter if it would be changed by the procedure... didn't know about that :/
But that's the kind of workaround I was looking for!
Thank you!
Re: Array parameter in procedures
Posted: Thu Mar 03, 2011 5:04 am
by lexvictory
@ABB: does the TB code even have checks for Array or List, etc in it?
I'm not sure that it does... Which would mean the Desc doesnt have the Array, etc keyword for the parameter, but the datatype of the array...
Re: Array parameter in procedures
Posted: Thu Mar 03, 2011 10:41 am
by ABBKlaus
@lexvictory your are right, the desc file is missing the array keyword.
If renamed to array does not work also !
@Fred / Freak could you investigate if this is a problem of the LibraryMaker.exe / PBCompiler.exe please ?
Code: Select all
ASM
;
1
KERNEL32
;
LIB
;
0
;
Quicksort_Test.chm
;
Quicksort, Long, Long, Long (Array a(1), g.l, d.l) ; <- TB generated : first paramter is wrong
;Quicksort, Array, Long, Long (Array a(1), g.l, d.l) ; <- Renamed : first paramter is Array !
None | StdCall | UNICODE | THREAD
;
Quicksort_Test_Init
InitFunction | StdCall | UNICODE | THREAD
;
Re: Array parameter in procedures
Posted: Thu Mar 03, 2011 2:00 pm
by lexvictory
The difference appears to be how PB calls the procedure, which was my first thought...
No TB:
With TB:
So it would appear we need to do something to it when we detect an array is used (and probably for lists and maps!
)
Re: Array parameter in procedures
Posted: Thu Mar 03, 2011 3:06 pm
by ABBKlaus
lexvictory wrote:So it would appear we need to do something to it when we detect an array is used
you can´t do anything with PUSH dword [a_teste], because its the content of the first element and in this example is a value of '5' / [05 00 00 00].
lexvictory wrote:and probably for lists and maps!
Lists are working fine, only maps need to be renamed in the desc to work properly.
Re: Array parameter in procedures
Posted: Fri Mar 04, 2011 11:33 am
by lexvictory
ah of course...
Perhaps it is a PB problem, unless i made and error when testing...
Re: Array parameter in procedures
Posted: Fri Mar 04, 2011 7:45 pm
by ABBKlaus
ah i was only halfway right, the square-brackets means indirect adressing.
So the TailBiten procedure receives the adress to the first array-element which is normal for externalisation like in a dll.
But we need the pointer to the PB-Object we don´t have, and i guess fred would say this is no bug.
Its more or less a feature request
Re: Array parameter in procedures
Posted: Sat Mar 05, 2011 1:21 pm
by lexvictory
I thought a PB array was the same as a C array, just the initialisation numbering was different?
They certainly work the same with Vlc anyway...
Re: Array parameter in procedures
Posted: Thu Jul 14, 2011 8:16 am
by coder14
PureLeo wrote:This procedure works fine.. but when I make a lib from it and run something like this:
Code: Select all
Dim teste(50)
...
QuickSort(teste(), 0,5)
Then I get an invalid memory access error...
Hi guys! Sorry to bump this topic up, but I've just stumbled into this same problem. ABBKlaus has a workaround which passes the
address of the address of the array to the procedure in the library:
Code: Select all
...
temp=@teste()
QuickSort(@temp, 0,5)
This works, but I was wondering if there was any other solution to this issue. It's a little inept to expect the user to pass the address of the address of the array, rather than the array itself, to be filled.
Any ideas?
Thanks in advance.
Re: Array parameter in procedures
Posted: Sun Jul 17, 2011 10:14 am
by lexvictory
if you can find an ASM solution we can put it in TB, otherwise it's doubtful..