bugDotGNU Portable.NET - Bugs: bug #20354, Problems with pinvoke declared to...

 
 

You are not allowed to post comments on this tracker with your current authentication level.

bug #20354: Problems with pinvoke declared to return struct

Submitted by:  Radek Polak <radekp>
Submitted on:  Thu 05 Jul 2007 07:28:48 AM UTC  
 
Category: NoneSeverity: 3 - Normal
Item Group: NoneStatus: Invalid
Privacy: PublicAssigned to: None
Open/Closed: Closed

Thu 05 Jul 2007 12:15:55 PM UTC, comment #1:

It seems that the code works only on windows. On linux (even with mono) it fails because of different calling conventions.

[13:47] <klausT|work> the pinvoked function doesn't return a struct
[13:51] <radekp> yep
[13:51] <klausT|work> does the function return an int or a boolean?
[13:51] <radekp> int
[13:52] <klausT|work> so you declared the return type in C# as int too?
[13:52] <radekp> if i declare return type as int it works
[13:53] <radekp> but if i declare it with return type as struct it fails
[13:53] <klausT|work> yes, of course it fails
[13:53] <radekp> on .NET it works on pnet no
[13:53] <klausT|work> because the signatures don't match
[13:54] <radekp> and on .NET they match?
[13:54] <klausT|work> on Windows you have usually the WINAPI/STDCALL calling convention
[13:55] <klausT|work> the struct return value is handled different there
[13:55] <klausT|work> the callee pops the args from the stack and pushes the return value
[13:57] <klausT|work> o no additional arg for the return value
[13:59] <radekp> so the conclusion is that the pinvoking is badly declared and will work on windows only?
[14:01] <klausT|work> yes, if the c function returns an int the return value in C# has to be int too

Radek Polak <radekp>
Project Member
Thu 05 Jul 2007 07:28:48 AM UTC, original submission:

Hi,
in the attached sample we call Fn() via pinvoke.

If the pinvoke is declared to return int everything works.
If the pinvoke is declared to return struct with one int field, the arguments are shifted.

Both declarations should work. This was tested with jit coder.

Radek Polak <radekp>
Project Member

 

Attached Files
file #13251:  pinvoke.tar.gz added by radekp (4KiB - application/gzip)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -unavailable- added by radekp (Submitted the item)
  •  

    Do you think this task is very important?
    If so, you can click here to add your encouragement to it.
    This task has 0 encouragements so far.

    Only logged-in users can vote.

     

    Please enter the title of George Orwell's famous dystopian book (it's a date):

     

     

    Follow 3 latest changes.

    Date Changed By Updated Field Previous Value => Replaced By
    Thu 05 Jul 2007 12:15:55 PM UTCradekpStatusNone=>Invalid
      Open/ClosedOpen=>Closed
    Thu 05 Jul 2007 07:28:48 AM UTCradekpAttached File-=>Added pinvoke.tar.gz, #13251

    Back to the top


    Powered by Savane 3.1-cleanup1