It is currently Sat Feb 23, 2019 6:07 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 12 posts ] 
Author Message
 Post subject: Array parameter in procedures
PostPosted: Tue Mar 01, 2011 12:31 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Fri Jan 29, 2010 1:05 pm
Posts: 221
Location: Brazil
Hi!

I'm just new to Tailbite...
I'm trying to make an userlib from this procedure:

Code:
 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:
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


Top
 Profile  
Reply with quote  
 Post subject: Re: Array parameter in procedures
PostPosted: Wed Mar 02, 2011 10:33 pm 
Offline
Addict
Addict

Joined: Sat Apr 10, 2004 1:20 pm
Posts: 1143
Location: Germany
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:
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


Top
 Profile  
Reply with quote  
 Post subject: Re: Array parameter in procedures
PostPosted: Wed Mar 02, 2011 11:44 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Fri Jan 29, 2010 1:05 pm
Posts: 221
Location: Brazil
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! :mrgreen:


Top
 Profile  
Reply with quote  
 Post subject: Re: Array parameter in procedures
PostPosted: Thu Mar 03, 2011 5:04 am 
Offline
Addict
Addict

Joined: Sun May 15, 2005 5:15 am
Posts: 1027
Location: Australia
@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...

_________________
Demonio Ardente

Currently managing Linux & OS X Tailbite
OS X TailBite now up to date with Windows!


Top
 Profile  
Reply with quote  
 Post subject: Re: Array parameter in procedures
PostPosted: Thu Mar 03, 2011 10:41 am 
Offline
Addict
Addict

Joined: Sat Apr 10, 2004 1:20 pm
Posts: 1143
Location: Germany
@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:
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
;


Top
 Profile  
Reply with quote  
 Post subject: Re: Array parameter in procedures
PostPosted: Thu Mar 03, 2011 2:00 pm 
Offline
Addict
Addict

Joined: Sun May 15, 2005 5:15 am
Posts: 1027
Location: Australia
The difference appears to be how PB calls the procedure, which was my first thought...

No TB:
Code:
PUSH   dword a_teste

With TB:
Code:
PUSH   dword [a_teste]


So it would appear we need to do something to it when we detect an array is used (and probably for lists and maps! :x )

_________________
Demonio Ardente

Currently managing Linux & OS X Tailbite
OS X TailBite now up to date with Windows!


Top
 Profile  
Reply with quote  
 Post subject: Re: Array parameter in procedures
PostPosted: Thu Mar 03, 2011 3:06 pm 
Offline
Addict
Addict

Joined: Sat Apr 10, 2004 1:20 pm
Posts: 1143
Location: Germany
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.


Top
 Profile  
Reply with quote  
 Post subject: Re: Array parameter in procedures
PostPosted: Fri Mar 04, 2011 11:33 am 
Offline
Addict
Addict

Joined: Sun May 15, 2005 5:15 am
Posts: 1027
Location: Australia
ah of course...
Perhaps it is a PB problem, unless i made and error when testing...

_________________
Demonio Ardente

Currently managing Linux & OS X Tailbite
OS X TailBite now up to date with Windows!


Top
 Profile  
Reply with quote  
 Post subject: Re: Array parameter in procedures
PostPosted: Fri Mar 04, 2011 7:45 pm 
Offline
Addict
Addict

Joined: Sat Apr 10, 2004 1:20 pm
Posts: 1143
Location: Germany
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 :wink:


Top
 Profile  
Reply with quote  
 Post subject: Re: Array parameter in procedures
PostPosted: Sat Mar 05, 2011 1:21 pm 
Offline
Addict
Addict

Joined: Sun May 15, 2005 5:15 am
Posts: 1027
Location: Australia
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...

_________________
Demonio Ardente

Currently managing Linux & OS X Tailbite
OS X TailBite now up to date with Windows!


Top
 Profile  
Reply with quote  
 Post subject: Re: Array parameter in procedures
PostPosted: Thu Jul 14, 2011 8:16 am 
Offline
Enthusiast
Enthusiast

Joined: Tue Jun 21, 2011 10:39 am
Posts: 326
PureLeo wrote:
This procedure works fine.. but when I make a lib from it and run something like this:
Code:
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:
...
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.


Top
 Profile  
Reply with quote  
 Post subject: Re: Array parameter in procedures
PostPosted: Sun Jul 17, 2011 10:14 am 
Offline
Addict
Addict

Joined: Sun May 15, 2005 5:15 am
Posts: 1027
Location: Australia
if you can find an ASM solution we can put it in TB, otherwise it's doubtful..

_________________
Demonio Ardente

Currently managing Linux & OS X Tailbite
OS X TailBite now up to date with Windows!


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 12 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye