Prototype.l (return a long) don't work

Just starting out? Need help? Post your questions and find answers here.
Lebostein
Addict
Addict
Posts: 807
Joined: Fri Jun 11, 2004 7:07 am

Prototype.l (return a long) don't work

Post by Lebostein »

Hi,

in normal case a long procedure returns a long-limited number (that is what I want):

Code: Select all

Procedure.l test()
  ProcedureReturn $FFFFFFFF ; = 4294967295
EndProcedure
Debug test() ; returns -1
But in my VLC-Video-Wrapper for example the set_volume function should return -1 if it fails, but I get 4294967295. How a long procedure can get values greater than 2147483647?
0 if the volume was set, -1 if it was out of range
https://www.videolan.org/developers/vlc ... 19203302a3

Code: Select all

CompilerSelect #PB_Compiler_OS
CompilerCase #PB_OS_Windows
  SetEnvironmentVariable("VLC_PLUGIN_PATH", GetEnvironmentVariable("ProgramFiles") + "\VideoLAN\VLC\plugins\")
  SetEnvironmentVariable("VLC_LIBRARY_PATH", GetEnvironmentVariable("ProgramFiles") + "\VideoLAN\VLC\libvlc.dll")
  SetEnvironmentVariable("PATH", GetEnvironmentVariable("PATH") + ";" + GetPathPart(GetEnvironmentVariable("VLC_LIBRARY_PATH")))
CompilerCase #PB_OS_MacOS
  SetEnvironmentVariable("VLC_PLUGIN_PATH", "/Applications/VLC.app/Contents/MacOS/plugins/")
  SetEnvironmentVariable("VLC_LIBRARY_PATH", "/Applications/VLC.app/Contents/MacOS/lib/libvlc.dylib")
CompilerCase #PB_OS_Linux
  SetEnvironmentVariable("VLC_PLUGIN_PATH", "/usr/lib/vlc/codecs/")
  SetEnvironmentVariable("VLC_LIBRARY_PATH", "/usr/lib/libvlc.so")
CompilerEndSelect

Global libvlc_main = OpenLibrary(#PB_Any, GetEnvironmentVariable("VLC_LIBRARY_PATH"))

PrototypeC.i p_libvlc_new(argc.i, *argv)
Global libvlc_new.p_libvlc_new = GetFunction(libvlc_main, "libvlc_new")

PrototypeC.i p_libvlc_media_player_new(*p_instance)
Global libvlc_media_player_new.p_libvlc_media_player_new = GetFunction(libvlc_main, "libvlc_media_player_new")

PrototypeC.l p_libvlc_audio_set_volume(*p_ml, i_volume.i) ; should return a long!
Global libvlc_audio_set_volume.p_libvlc_audio_set_volume = GetFunction(libvlc_main, "libvlc_audio_set_volume")

*vlc_inst = libvlc_new(0, 0)
Debug *vlc_inst 
*vlc_player = libvlc_media_player_new(*vlc_inst)
Debug *vlc_player
Debug libvlc_audio_set_volume(*vlc_player, -4545) ; enter an invalid volume, get an error 4294967295 (should be -1)
PS: I need no workaround. I know I can save the result in a long variable before. I am interested in the limitation of Prototype.<type>
Last edited by Lebostein on Wed Nov 15, 2017 9:18 am, edited 1 time in total.
User avatar
Shield
Addict
Addict
Posts: 1021
Joined: Fri Jan 21, 2011 8:25 am
Location: 'stralia!
Contact:

Re: Prototype.l (return a long) don't work

Post by Shield »

You can mask it.

Code: Select all

Procedure.l test()
  ProcedureReturn $FFFFFFFF ; = 4294967295
EndProcedure
a.q = test() & $FFFFFFFF
Debug a
Edit:
Not sure I get what you mean. If the command returns a signed 4 byte integer, which it seems it does,
then 4294967295 is equal to -1 because of how they wrap, so you don't even need to do a conversion.

Code: Select all

a.l = 4294967295
b.l = -1

If a = b
    Debug "They are equal"
EndIf
Image
Blog: Why Does It Suck? (http://whydoesitsuck.com/)
"You can disagree with me as much as you want, but during this talk, by definition, anybody who disagrees is stupid and ugly."
- Linus Torvalds
Lebostein
Addict
Addict
Posts: 807
Joined: Fri Jun 11, 2004 7:07 am

Re: Prototype.l (return a long) don't work

Post by Lebostein »

You don't understand my problem. I will get a -1 from a long-procedure, like in the first example. But I get a value 4294967295 from a long-prototype-procedure. It is a bug?
infratec
Always Here
Always Here
Posts: 6817
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Prototype.l (return a long) don't work

Post by infratec »

Hi,

I think it's a bug.

You declared the prototype as .l but it returns an .i (you are using PB x64 ?)
Example to demonstrate the behaviour (use PB x64):

Code: Select all

Procedure.i testi()
  ProcedureReturn $FFFFFFFF
EndProcedure

Procedure.l testl()
  ProcedureReturn $FFFFFFFF
EndProcedure

Debug testi()
Debug testl()
Procedure.l works, but PrototypeC.l does not. -> bug

Which PB version and which OS Version?
Lebostein
Addict
Addict
Posts: 807
Joined: Fri Jun 11, 2004 7:07 am

Re: Prototype.l (return a long) don't work

Post by Lebostein »

infratec wrote:Which PB version and which OS Version?
PB 5.61 (x64) Mac OS
Wolfram
Enthusiast
Enthusiast
Posts: 567
Joined: Thu May 30, 2013 4:39 pm

Re: Prototype.l (return a long) don't work

Post by Wolfram »

Same problem here on PB 5.6 and 5.46
It return a integer.
macOS Catalina 10.15.7
Justin
Addict
Addict
Posts: 829
Joined: Sat Apr 26, 2003 2:49 pm

Re: Prototype.l (return a long) don't work

Post by Justin »

I had the same problem with this lib and another functions. Looks like a bug, should be in the bugs sectoon.
User avatar
skywalk
Addict
Addict
Posts: 3972
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: Prototype.l (return a long) don't work

Post by skywalk »

Expanding infratec's reply...Are you saying an external library does not return -1 for longs?

Code: Select all

Prototype.l ptesti()
Procedure.i testi()
  ProcedureReturn $FFFFFFFF
EndProcedure
Prototype.l ptestl()
Procedure.l testl()
  ProcedureReturn $FFFFFFFF
EndProcedure
Define ptestl.ptestl = @testl()
Define ptesti.ptesti = @testi()
Debug "ptestl() = " + Str(ptestl())  ;ptestl() = -1
Debug "ptesti() = " + Str(ptesti())  ;ptesti() = 4294967295
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
Wolfram
Enthusiast
Enthusiast
Posts: 567
Joined: Thu May 30, 2013 4:39 pm

Re: Prototype.l (return a long) don't work

Post by Wolfram »

skywalk wrote:Expanding infratec's reply...Are you saying an external library does not return -1 for longs?
yes, your example works, but the code from Lebostein not.

Code: Select all

PrototypeC.l p_libvlc_audio_set_volume(*p_ml, i_volume.i) ; should return a long!
Global libvlc_audio_set_volume.p_libvlc_audio_set_volume = GetFunction(libvlc_main, "libvlc_audio_set_volume")
On OSX this returns 4294967295 instead of -1
Last edited by Wolfram on Thu Nov 16, 2017 8:44 pm, edited 1 time in total.
macOS Catalina 10.15.7
User avatar
skywalk
Addict
Addict
Posts: 3972
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: Prototype.l (return a long) don't work

Post by skywalk »

Ok, just trying to understand if error exists on Windows?

Code: Select all

Prototype.l ptesti()
Procedure.i testi()
  ProcedureReturn $FFFFFFFF
EndProcedure
Prototype.l ptestl()
Procedure.l testl()
  ProcedureReturn $FFFFFFFF
EndProcedure
PrototypeC.l ptestlc(x.l)
ProcedureC.l testlc(x.l)
  ProcedureReturn x
EndProcedure
Define ptestl.ptestl = @testl()
Define ptesti.ptesti = @testi()
Define ptestlc.ptestlc = @testlc()
Debug "ptestl()  = " + Str(ptestl())    ;ptestl() = -1
Debug "ptesti()  = " + Str(ptesti())    ;ptesti() = 4294967295
Debug "ptestlc() = " + Str(ptestlc(4294967295))  ;ptestlc() = -1
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
Wolfram
Enthusiast
Enthusiast
Posts: 567
Joined: Thu May 30, 2013 4:39 pm

Re: Prototype.l (return a long) don't work

Post by Wolfram »

skywalk wrote:Ok, just trying to understand if error exists on Windows?

Code: Select all

Prototype.l ptesti()
Procedure.i testi()
  ProcedureReturn $FFFFFFFF
EndProcedure
Prototype.l ptestl()
Procedure.l testl()
  ProcedureReturn $FFFFFFFF
EndProcedure
PrototypeC.l ptestlc(x.l)
ProcedureC.l testlc(x.l)
  ProcedureReturn x
EndProcedure
Define ptestl.ptestl = @testl()
Define ptesti.ptesti = @testi()
Define ptestlc.ptestlc = @testlc()
Debug "ptestl()  = " + Str(ptestl())    ;ptestl() = -1
Debug "ptesti()  = " + Str(ptesti())    ;ptesti() = 4294967295
Debug "ptestlc() = " + Str(ptestlc(4294967295))  ;ptestlc() = -1
You can't reproduce the problem this way.
The problem is here

Code: Select all

PrototypeC.l p_libvlc_audio_set_volume(*p_ml, i_volume.i)
This returns an unsigned long or an integer and not a signed long. (4294967295 instead of -1)
macOS Catalina 10.15.7
Post Reply