[Mono-dev] InterOp problems with 1.2.6pre2

Robert Jordan robertj at gmx.net
Fri Nov 30 14:18:22 EST 2007


Hi,

Prakash Punnoor wrote:
> Hi
> 
> I am wondering whether this problem is not interesting anyone? In the 
> meanwhile I could pinpoint the troublemaker.

well, we'd be interested but you did not post a reproducible
test case.

> 
> Basically it is a float[] field I declared in the struct Encoding context:
> 

This doesn't look like a valid struct for p/invoke. Is this
the real code?

Aften's context does not declare a float array at this position.


Robert

> 	public struct EncodingContext
> 	{
> 		public EncodingParameters EncodingParameters;
> 		public Metadata Metadata;
> 		public Status Status;
> 		public SystemParameters SystemParameters;
> 		public int Verbosity;
> 		public int Channels;
> 		public AudioCodingMode AudioCodingMode;
> 		public bool HasLfe;
> 		public int SampleRate;
> 		internal A52SampleFormat SampleFormat;
> 
> 		public float[] InitialSamples; // the trouble maker
> 
> 		private IntPtr m_Context;
> 	}
> 
> and I have and InterOp like this:
> 
> 	public abstract class FrameEncoder
> 	{
> 		[DllImport( "aften.dll" )]
> 		private static extern void aften_set_defaults( ref EncodingContext 
> context );
> 
> 		public static EncodingContext GetDefaultsContext()
> 		{
> 			EncodingContext context = new EncodingContext();
> 			aften_set_defaults( ref context );
> 
> 			return context;
> 		}
> 	}
> 
> This causes the crash/exception in mono (see quoted mail). So it doesn't have 
> anything to do with generics as I suspected at first. If I change the float[] 
> to IntPtr mono seems to work. As I said VS2008beta2 doesn't have any 
> problems.
> 
> Cheers,
> 
> Prakash
> 
> On the day of Saturday 24 November 2007 Prakash Punnoor hast written:
>> Hi,
>>
>> mono 1.2.6pre1 and pre2 on Linux x86_64 can't run some C# bindings to a C
>> library (an ac3 encoder), which works perfectly with vs2008beta2 and
>> .net2.0 target on x86.
>>
>> You can get the sources at http://sourceforge.net/projects/aften/ in svn
>> (revision 659). Compile it using cmake. To build C# bindings,
>> pass -DBINDINGS_CS=1 to cmake. It worked with mono with the floating point
>> samples case before I switched the bindings to using generics to have other
>> types of samples supported (revision 651; though there were bugs in my code
>> at that time ;).
>>
>> The testing code is this (remember the bindings are the troublemaker, not
>> this code):
>>
>> using System;
>> using System.IO;
>> using System.Runtime.InteropServices;
>>
>> using Aften;
>>
>>
>> namespace AftenTest
>> {
>> 	class MainClass
>> 	{
>> 		public static int Main(string[] args)
>> 		{
>> 			Console.WriteLine("Aften AC3 Encoding Demo");
>> 			if (args.Length != 2)
>> 			{
>>
>> Console.WriteLine("Usage:
>> "+Path.GetFileNameWithoutExtension(Environment.CommandLine)+" <input.wav>
>> <output.ac3>");
>> 				return -1;
>> 			}
>> 			EncodingContext context = FrameEncoder.GetDefaultsContext();
>> 			context.Channels = 2;
>> 			context.AudioCodingMode = AudioCodingMode.Stereo;
>> 			context.SampleRate = 48000;
>> 			context.HasLfe = false;
>> 			context.SystemParameters.ThreadsCount = 1;
>>
>> 			FrameEncoderInt16 encoder = new FrameEncoderInt16(ref context);
>>
>> 			using (FileStream inputStream = new FileStream(args[0], FileMode.Open))
>> 			using (FileStream outputStream = new FileStream(args[1],
>> FileMode.CreateNew))
>> 			{
>> 				inputStream.Seek(44, SeekOrigin.Begin); //Skip WAVE header...
>> 				encoder.Encode(inputStream, outputStream);
>> 			}
>>
>> 			Console.WriteLine("Done");
>> 			Console.ReadLine();
>> 			return 0;
>> 		}
>> 	}
>> }
>>
>> The error I get with mono:
>> mono  AftenTest.exe ~/Projects/bill.wav encoded.ac3
>> Aften AC3 Encoding Demo
>>
>> ** ERROR **: Structure field of type Single[] can't be marshalled as
>> LPArray aborting...
>> Stacktrace:
>>
>>   at AftenTest.MainClass.Main (string[]) <0xffffffff>
>>   at AftenTest.MainClass.Main (string[]) <0x000b8>
>>   at (wrapper runtime-invoke)
>> AftenTest.MainClass.runtime_invoke_int_string[]
>> (object,intptr,intptr,intptr) <0xffffffff>
>>
>> Native stacktrace:
>>
>>         mono [0x51fe5d]
>>         /lib/libpthread.so.0 [0x2b86da225880]
>>         /lib/libc.so.6(gsignal+0x35) [0x2b86da6e4fa5]
>>         /lib/libc.so.6(abort+0x110) [0x2b86da6e6a00]
>>         /usr/lib/libglib-2.0.so.0 [0x2b86d9d80dec]
>>         /usr/lib/libglib-2.0.so.0(g_log+0x83) [0x2b86d9d80e73]
>>         mono [0x48ba04]
>>         mono [0x48e297]
>>         mono [0x48f449]
>>         mono [0x493642]
>>         mono [0x4942db]
>>         mono [0x500646]
>>         mono [0x50bc76]
>>         mono [0x50d3da]
>>         mono [0x43df62]
>>         [0x4000015b]
>>
>> Debug info from gdb:
>>
>> Using host libthread_db library "/lib/libthread_db.so.1".
>> [Thread debugging using libthread_db enabled]
>> [New Thread 0x2b86dac1bb40 (LWP 19911)]
>> [New Thread 0x40224950 (LWP 19913)]
>> [New Thread 0x40023950 (LWP 19912)]
>> 0x00002b86da22465b in read () from /lib/libpthread.so.0
>>   3 Thread 0x40023950 (LWP 19912)  0x00002b86da224f11 in nanosleep ()
>>    from /lib/libpthread.so.0
>>   2 Thread 0x40224950 (LWP 19913)  0x00002b86da221c39 in
>> pthread_cond_wait@@GLIBC_2.3.2 () from /lib/libpthread.so.0
>>   1 Thread 0x2b86dac1bb40 (LWP 19911)  0x00002b86da22465b in read ()
>>    from /lib/libpthread.so.0
>>
>> Thread 3 (Thread 0x40023950 (LWP 19912)):
>> #0  0x00002b86da224f11 in nanosleep () from /lib/libpthread.so.0
>> #1  0x00000000004d283f in collection_thread (unused=<value optimized out>)
>>     at collection.c:34
>> #2  0x00002b86da21d477 in start_thread () from /lib/libpthread.so.0
>> #3  0x00002b86da78b3ad in clone () from /lib/libc.so.6
>>
>> Thread 2 (Thread 0x40224950 (LWP 19913)):
>> #0  0x00002b86da221c39 in pthread_cond_wait@@GLIBC_2.3.2 ()
>>    from /lib/libpthread.so.0
>> #1  0x00000000004ce015 in timedwait_signal_poll_cond (cond=0x2aaaab6be268,
>>     mutex=0x2aaaab6be240, timeout=0x1, alertable=-1) at handles.c:1443
>> #2  0x00000000004d05eb in _wapi_handle_timedwait_signal_handle (
>>     handle=<value optimized out>, timeout=0x0, alertable=0) at
>> handles.c:1523 #3  0x00000000004c06af in WaitForSingleObjectEx
>> (handle=0x404,
>>     timeout=4294967295, alertable=0) at wait.c:200
>> #4  0x0000000000498db1 in finalizer_thread (unused=<value optimized out>)
>>     at gc.c:843
>> #5  0x0000000000480b53 in start_wrapper (data=<value optimized out>)
>>     at threads.c:550
>> #6  0x00000000004c2677 in thread_start_routine (args=0x2aaaab72a0d0)
>>     at threads.c:264
>> #7  0x00000000004db4f2 in GC_start_routine ()
>> #8  0x00002b86da21d477 in start_thread () from /lib/libpthread.so.0
>> #9  0x00002b86da78b3ad in clone () from /lib/libc.so.6
>>
>> Thread 1 (Thread 0x2b86dac1bb40 (LWP 19911)):
>> #0  0x00002b86da22465b in read () from /lib/libpthread.so.0
>> #1  0x00002b86d9da63e0 in read_ints () from /usr/lib/libglib-2.0.so.0
>> #2  0x00002b86d9da68c7 in fork_exec_with_pipes ()
>>    from /usr/lib/libglib-2.0.so.0
>> #3  0x00002b86d9da721f in g_spawn_sync () from /usr/lib/libglib-2.0.so.0
>> #4  0x00002b86d9da76d8 in g_spawn_command_line_sync ()
>>    from /usr/lib/libglib-2.0.so.0
>> #5  0x000000000051feee in mono_handle_native_sigsegv (
>>     signal=<value optimized out>, ctx=<value optimized out>)
>>     at mini-exceptions.c:1061
>> #6  <signal handler called>
>> #7  0x00002b86da6e4fa5 in raise () from /lib/libc.so.6
>> #8  0x00002b86da6e6a00 in abort () from /lib/libc.so.6
>> #9  0x00002b86d9d80dec in g_logv () from /usr/lib/libglib-2.0.so.0
>> #10 0x00002b86d9d80e73 in g_log () from /usr/lib/libglib-2.0.so.0
>> #11 0x000000000048ba04 in emit_struct_conv (mb=0x8fe000, klass=0x8abe88,
>>     to_object=1) at marshal.c:2758
>> #12 0x000000000048e297 in emit_marshal_vtype (m=<value optimized out>,
>>     argnum=0, t=0x8abf78, spec=<value optimized out>, conv_arg=3,
>>     conv_arg_type=<value optimized out>, action=<value optimized out>)
>>     at marshal.c:6192
>> #13 0x000000000048f449 in emit_marshal (m=0x7fffd1180200, argnum=0,
>>     t=0x8abf78, spec=0x0, conv_arg=3, conv_arg_type=0x0,
>>     action=MARSHAL_ACTION_CONV_OUT) at marshal.c:8357
>> #14 0x0000000000493642 in mono_marshal_emit_native_wrapper (
>>     image=<value optimized out>, mb=0x8fe000, sig=0x8bc940,
>> piinfo=0x8ae570, mspecs=0x8c1240, func=0x2aaaabcde7c0) at marshal.c:8584
>> #15 0x00000000004942db in mono_marshal_get_native_wrapper (method=0x8ae570)
>>     at marshal.c:8731
>> #16 0x0000000000500646 in mono_method_to_ir (cfg=0x8c9600, method=0x8b6c68,
>>     start_bblock=0x91aa00, end_bblock=0x91ab08, locals_offset=0,
>>     return_var=0x0, dont_inline=0x91f4e0, inline_args=0x0, inline_offset=0,
>>     is_virtual_call=0, shared_context=0x0) at mini.c:4817
>> #17 0x000000000050bc76 in mini_method_compile (method=0x8b6c68,
>> opts=5318911, domain=0x2aaaaab6ce00, run_cctors=<value optimized out>,
>>     compile_aot=<value optimized out>, parts=0) at mini.c:10728
>> #18 0x000000000050d3da in mono_jit_compile_method (method=0x8) at
>> mini.c:11141 #19 0x000000000043df62 in mono_magic_trampoline
>> (regs=0x7fffd1180a48, code=0x40010418 "��", m=0x8b6c68,
>>     tramp=0xffffffffffffffff <Address 0xffffffffffffffff out of bounds>)
>>     at mini-trampolines.c:121
>> #20 0x000000004000015b in ?? ()
>> #21 0x0000000000000000 in ?? ()
>> #0  0x00002b86da22465b in read () from /lib/libpthread.so.0
>>
>>
>> =================================================================
>> Got a SIGABRT while executing native code. This usually indicates
>> a fatal error in the mono runtime or one of the native libraries
>> used by your application.
>> =================================================================
>>
>> Would a fix be possible for 1.2.6 release?
>>
>> Cheers,
> 
> 
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> Mono-devel-list mailing list
> Mono-devel-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-devel-list




More information about the Mono-devel-list mailing list