[Mono-dev] [PATCH] Managed Marshal.Copy implemantations

Paolo Molaro lupus at ximian.com
Thu Dec 20 06:56:56 EST 2007


On 12/17/07 Kornél Pál wrote:
> >(for example the original C implementation has a bug and
> >in your code it's duplicated several times)
> 
> What is that bug?

Integer overflow when doing the array range check.

> >and you also managed to hide
> >the assignment of a local var inside of a conditional expression.
> 
> Is that a bad practice?

Yes, there is no reason to try to hide code.

> >Your code also omits a check that the current code does of the rank of
> >the array.
> 
> I don't see any reason for that check because as far as I know byte[,] for 
> example cannot be casted to byte[]. Did I miss something?

It's an extra check because the shared methods will have Array as the
type and they could be misused.

> My only problem is that I don't know how could I effectively obtain a pinned 
> pointer to a managed object (currently Array) using C#. Do you have a good 
> idea?

Until we support precise stack scanning in the GC it's not an issue
and you can use a simple IntPtr. When we'll add that support, the JIT
will be changed to insert an explicit pinning pointer local variable
to store the result of the new internal call.

lupus

-- 
-----------------------------------------------------------------
lupus at debian.org                                     debian/rules
lupus at ximian.com                             Monkeys do it better



More information about the Mono-devel-list mailing list