Page 1 of 1

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

Posted: Wed Nov 15, 2017 8:36 am
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>

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

Posted: Wed Nov 15, 2017 9:00 am
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

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

Posted: Wed Nov 15, 2017 9:17 am
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?

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

Posted: Wed Nov 15, 2017 11:06 am
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?

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

Posted: Wed Nov 15, 2017 2:04 pm
by Lebostein
infratec wrote:Which PB version and which OS Version?
PB 5.61 (x64) Mac OS

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

Posted: Wed Nov 15, 2017 8:10 pm
by Wolfram
Same problem here on PB 5.6 and 5.46
It return a integer.

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

Posted: Thu Nov 16, 2017 11:02 am
by Justin
I had the same problem with this lib and another functions. Looks like a bug, should be in the bugs sectoon.

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

Posted: Thu Nov 16, 2017 3:41 pm
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

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

Posted: Thu Nov 16, 2017 4:37 pm
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

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

Posted: Thu Nov 16, 2017 5:29 pm
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

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

Posted: Sun Nov 19, 2017 11:56 am
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)