[Mono-list] Managed equivalent of memset?
Frederik Carlier
frederik.carlier at carlier-online.be
Tue Feb 20 09:12:53 EST 2007
Here's the C# code:
The declaration of the struct
[StructLayout(LayoutKind.Sequential)]
public struct TidyBuffer
{
public IntPtr allocator; /**< Memory allocator */
public IntPtr bp; /**< Pointer to bytes */
public uint size; /**< # bytes currently in use */
public uint allocated; /**< # bytes allocated */
public uint next; /**< Offset of current input position */
}
Calling setErrorBuffer
// Assign the error buffer
errorBuffer = new TidyBuffer();
TidyWrapper.tidySetErrorBuffer(tidyDoc, errorBuffer);
The declaration of tidySetErrorBuffer
[DllImport("libtidy")]
public static extern int tidySetErrorBuffer(IntPtr tdoc,
TidyBuffer errbuf);
And the C equivalent for the buffer
/** TidyBuffer - A chunk of memory */
TIDY_STRUCT
struct _TidyBuffer
{
TidyAllocator* allocator; /**< Memory allocator */
byte* bp; /**< Pointer to bytes */
uint size; /**< # bytes currently in use */
uint allocated; /**< # bytes allocated */
uint next; /**< Offset of current input position */
};
The tidySetErrorBuffer function
int TIDY_CALL tidySetErrorBuffer(TidyDoc tdoc, TidyBuffer * errbuf)
TidyDoc itself is an opaque data type.
Thanks,
Frederik.
Robert Jordan schreef:
> Frederik Carlier wrote:
>
>> Hi,
>>
>> As a quick introduction, I'm trying to convert a C++.NET wrapper around
>> HTML Tidy to C#, because of the lack of a C++.NET compiler for Linux.
>> I'm by no means an expert in unmanaged code, but things are going well.
>>
>> I am, however, hitting a problem with a struct. The C++ code that
>> initializes the struct reads as follows:
>>
>> [C++]
>> m_errbuf = new TidyBuffer;
>> memset(m_errbuf,0,sizeof(TidyBuffer));
>> tidySetErrorBuffer(m_tdoc,m_errbuf);
>>
>> Re-creating the struct and calling tidySetErrorBuffer is easy enough,
>> but what is the managed equivalent of memset? If I just 'omit' the
>> memset line, I get the following failed assertion:
>>
>
> Zeroing memory is usually not necessary because structs allocated
> by C# are initialized with zero.
>
>
>> mono: src/buffio.c:184: tidyBufPutByte: Assertion `buf != ((void *)0)'
>> failed.
>>
>
> Assertion `buf != ((void *)0)' means that the unmanaged library
> is expecting something != 0 but it got a 0, so your problem is
> most likely not related to memset. Please post some code.
>
> Robert
>
> _______________________________________________
> Mono-list maillist - Mono-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-list
>
More information about the Mono-list
mailing list