[Mono-bugs] [Bug 472845] New: Need proper support for __arglist keyword in compiler and P/Invoke
bugzilla_noreply at novell.com
bugzilla_noreply at novell.com
Thu Feb 5 08:27:13 EST 2009
https://bugzilla.novell.com/show_bug.cgi?id=472845
Summary: Need proper support for __arglist keyword in compiler
and P/Invoke
Classification: Mono
Product: Mono: Runtime
Version: 2.2.x
Platform: Other
OS/Version: Other
Status: NEW
Severity: Normal
Priority: P5 - None
Component: io-layer
AssignedTo: dick at novell.com
ReportedBy: eugeny.grishul at gmail.com
QAContact: mono-bugs at lists.ximian.com
Found By: ---
User-Agent: Opera/9.63 (Windows NT 6.0; U; ru) Presto/2.1.1
1) gmcs currently supports only __arglist keyword, but sometimes generates
incorrect CIL. That code works while compiling with csc.exe, but leads to
segmentation fault/incorrect CIL after gmsc (I tried it on Mac OS 10.5, Mono
2.2 ):
================== CODE ===========================
using System;
using System.Runtime.InteropServices;
using System.Threading;
namespace NObjective
{
public class Program
{
static volatile bool ProcessExiting = false;
[DllImport( "libc.dylib" )]
public extern static void printf( string format, __arglist );
private static void ArglistMethod(__arglist )
{
var iter = new ArgIterator( __arglist );
for( var n = iter.GetRemainingCount(); n > 0; n-- )
Console.WriteLine( TypedReference.ToObject( iter.GetNextArg() )
);
}
static unsafe void Main( string[] args )
{
ArglistMethod( __arglist( 1, 2, 3 ) );
}
}
}
===================================================
2) Mono VES currently supports mkrefany, refanyval, refanytype, arglist
instructions for non-P/Invoke scenario. But only csc.exe can insert
mkrefany,refanyval,refanytype CIL instructions into assembly.
3) Mono JIT & P/Invoke layer don't like __arglist parameters and reports
something like this: Invalid IL code in NObjective.Program:Main (string[]):
IL_0021: ret
================== CODE ===========================
[DllImport( "libc.dylib" )]
public extern static void printf( string format, __arglist );
..
printf( "ytu", __arglist( "44" ) );
===================================================
If compiler will be able generate correct CIL it will be useful for debugging
future P/Invoke layer that will able to work with __arglist
My project (NObjective) contains about of 43000 generated methods (generated
from Objective-C method signatures) accessible by user that looks like:
================== CODE ===========================
unsafe public static bool writeToURL_atomically_( this NSData ___this, NSURL
url, bool atomically ) {
RuntimeObject ___occuredException;
var ___result = NativeMethods.writeToURL_atomically_( ___this,
CachedSelectors.writeToURL_atomically_, out ___occuredException, sizeof( NSURL
) + sizeof( bool ), url, atomically );
if( ___occuredException != RuntimeObject.Null ) throw
RuntimeException.Create( ___occuredException );
return ___result;
}
unsafe public static bool writeToURL_options_error_( this NSData ___this, NSURL
url, uint options, ref NSError error ) {
RuntimeObject ___occuredException;
var ___result = NativeMethods.writeToURL_options_error_( ___this,
CachedSelectors.writeToURL_options_error_, out ___occuredException, sizeof(
NSURL ) + sizeof( uint ) + sizeof( IntPtr ), url, options, ref error );
if( ___occuredException != RuntimeObject.Null ) throw
RuntimeException.Create( ___occuredException );
return ___result;
}
(See full source:
http://code.google.com/p/nobjective/source/browse/trunk/Proxies/10.5/HIToolbox.cs)
===================================================
Each generated method have a generated P/Invoke counterpart with same entry
point and nearly same signature (another 43000 methods!):
================== CODE ===========================
[DllImport(Runtime.InteropLibrary, EntryPoint = "objc_msgSend_eh2")]
public static extern bool writeToURL_atomically_( RuntimeObject ___object,
Selector ___selector, out RuntimeObject ___occuredException, int ___stackSize,
NSURL url, bool atomically );
[DllImport(Runtime.InteropLibrary, EntryPoint = "objc_msgSend_eh2")]
public static extern bool writeToURL_options_error_( RuntimeObject ___object,
Selector ___selector, out RuntimeObject ___occuredException, int ___stackSize,
NSURL url, uint options, ref NSError error );
===================================================
With proper __arglist support in VES/gmcs unnecessary P/Invokes can be easily
removed ( -43000 methods = assembly will hold much less metadata ) and all
calls redirected to small set __arglist methods (one method per primitive
return type - int,IntPtr etc.):
================== CODE ===========================
unsafe public static bool writeToURL_atomically_( this NSData ___this, NSURL
url, bool atomically ) {
RuntimeObject ___occuredException;
var ___result = NativeMethods.FutureArglistMethod( ___this,
CachedSelectors.writeToURL_atomically_, out ___occuredException, sizeof( NSURL
) + sizeof( bool ), __arglist( url, atomically ) );
if( ___occuredException != RuntimeObject.Null ) throw
RuntimeException.Create( ___occuredException );
return ___result;
}
unsafe public static bool writeToURL_options_error_( this NSData ___this, NSURL
url, uint options, ref NSError error ) {
RuntimeObject ___occuredException;
var ___result = NativeMethods.FutureArglistMethod( ___this,
CachedSelectors.writeToURL_options_error_, out ___occuredException, sizeof(
NSURL ) + sizeof( uint ) + sizeof( IntPtr ), __arglist( url, options, ref error
) );
if( ___occuredException != RuntimeObject.Null ) throw
RuntimeException.Create( ___occuredException );
return ___result;
}
..
[DllImport(Runtime.InteropLibrary, EntryPoint = "objc_msgSend_eh2")]
public static extern bool FutureArglistMethod( RuntimeObject ___object,
Selector ___selector, out RuntimeObject ___occuredException, int ___stackSize,
__arglist );
===================================================
WBR,
Eugeny Grishul
Reproducible: Always
Actual Results:
P/Invoke not works with vararg (__arglist) calls
gmcs not support __makeref, __refvalue, __reftype keywords.
gmcs generates incorrect CIL for __arglist
Expected Results:
All is OK.
--
Configure bugmail: https://bugzilla.novell.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.
More information about the mono-bugs
mailing list