[Mono-list] Wrapper additions
Dietmar Maurer
dietmar@ximian.com
Thu, 20 Sep 2001 12:23:56 +0200
--------------CA0FAFD6A97BA4C74D07CFE2
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Paolo Molaro wrote:
> On 09/20/01 Dietmar Maurer wrote:
> > Yes, looks better ;-) Please commit. Although I think returning a String
> > will not work with our current PInvoke implementation. Does that work on
> > M$ platform without problems (is the code tested)?
>
> I think we shouldn't use the string type to pass char* data back and forth
> to unix APIs. The problem is: string is supposed to be unicode chars, but
> what encoding does that API use? latin1? utf8?
UTF8, or the same char set which is used for system calls?
> We don't know and the lame
> attribute MS added (CHAR_SET_ANSI) is only usable with their APIs.
> We should probably use byte[] and have the caller decide the proper encoding.
> Comments welcome.
I thought its the task of PInvoke to convert from unicode to the system char set
and back? Passing a byte[] only moves the problem to another location.
> > > +int
> > > +mono_wrapper_opendir (const char * path)
> > > +{
> > > + return (int)opendir(path);
> > > +}
>
> opendir () return a pointer and you can't cast it (portably) to
> an int. Use gpointer (the same issue is in mono_wrapper_getenv and
> mono_wrapper_environ).
The problem is in the perl script. Here is a patch:
Index: genwrapper.pl
===================================================================
RCS file: /cvs/public/mono/mono/wrapper/genwrapper.pl,v
retrieving revision 1.4
diff -u -r1.4 genwrapper.pl
--- genwrapper.pl 2001/09/10 09:03:07 1.4
+++ genwrapper.pl 2001/09/20 06:24:03
@@ -245,7 +245,7 @@
%tmap = ("void" => "void",
- "IntPtr" => "int",
+ "IntPtr" => "gpointer",
"sbyte" => "gint8",
"byte" => "guint8",
"short" => "gint16",
Index: wrapper.c
===================================================================
RCS file: /cvs/public/mono/mono/wrapper/wrapper.c,v
retrieving revision 1.2
diff -u -r1.2 wrapper.c
--- wrapper.c 2001/09/10 07:39:00 1.2
+++ wrapper.c 2001/09/20 06:24:03
@@ -4,32 +4,32 @@
#include "wrapper.h"
gint64
-mono_wrapper_seek (int fd, gint64 offset, gint32 whence)
+mono_wrapper_seek (gpointer fd, gint64 offset, gint32 whence)
{
if (offset > INT_MAX || offset < INT_MIN)
return -1;
- return lseek (fd, offset, whence);
+ return lseek ((int)fd, offset, whence);
}
gint32
-mono_wrapper_read (int fd, void* buf, gint32 count)
+mono_wrapper_read (gpointer fd, void* buf, gint32 count)
{
- return read (fd, buf, count);
+ return read ((int)fd, buf, count);
}
gint32
-mono_wrapper_write (int fd, void* buf, gint32 count)
+mono_wrapper_write (gpointer fd, void* buf, gint32 count)
{
- return write (fd, buf, count);
+ return write ((int)fd, buf, count);
}
gint32
-mono_wrapper_fstat (int fd, MonoWrapperStat* buf)
+mono_wrapper_fstat (gpointer fd, MonoWrapperStat* buf)
{
struct stat fs;
- if (fstat (fd, &fs) != 0)
+ if (fstat ((int)fd, &fs) != 0)
return -1;
buf->st_dev = fs.st_dev;
@@ -46,24 +46,24 @@
}
gint32
-mono_wrapper_ftruncate (int fd, gint64 length)
+mono_wrapper_ftruncate (gpointer fd, gint64 length)
{
if (length > INT_MAX || length < INT_MIN)
return -1;
- return ftruncate (fd, length);
+ return ftruncate ((int)fd, length);
}
-int
+gpointer
mono_wrapper_open (const char * path, gint32 flags, gint32 mode)
{
- return open (path, flags, mode);
+ return (gpointer) open (path, flags, mode);
}
gint32
-mono_wrapper_close (int fd)
+mono_wrapper_close (gpointer fd)
{
- return close (fd);
+ return close ((int)fd);
}
gint32
--------------CA0FAFD6A97BA4C74D07CFE2
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
Paolo Molaro wrote:
<blockquote TYPE=CITE>On 09/20/01 Dietmar Maurer wrote:
<br>> Yes, looks better ;-) Please commit. Although I think returning a
String
<br>> will not work with our current PInvoke implementation. Does that
work on
<br>> M$ platform without problems (is the code tested)?
<p>I think we shouldn't use the string type to pass char* data back and
forth
<br>to unix APIs. The problem is: string is supposed to be unicode chars,
but
<br>what encoding does that API use? latin1? utf8?</blockquote>
UTF8, or the same char set which is used for system calls?
<blockquote TYPE=CITE>We don't know and the lame
<br>attribute MS added (CHAR_SET_ANSI) is only usable with their APIs.
<br>We should probably use byte[] and have the caller decide the proper
encoding.
<br>Comments welcome.</blockquote>
I thought its the task of PInvoke to convert from unicode to the system
char set and back? Passing a byte[] only moves the problem to another location.
<blockquote TYPE=CITE>> > +int
<br>> > +mono_wrapper_opendir (const char * path)
<br>> > +{
<br>> > + return (int)opendir(path);
<br>> > +}
<p>opendir () return a pointer and you can't cast it (portably) to
<br>an int. Use gpointer (the same issue is in mono_wrapper_getenv and
<br>mono_wrapper_environ).</blockquote>
The problem is in the perl script. Here is a patch:
<pre>Index: genwrapper.pl
===================================================================
RCS file: /cvs/public/mono/mono/wrapper/genwrapper.pl,v
retrieving revision 1.4
diff -u -r1.4 genwrapper.pl
--- genwrapper.pl 2001/09/10 09:03:07 1.4
+++ genwrapper.pl 2001/09/20 06:24:03
@@ -245,7 +245,7 @@
%tmap = ("void" => "void",
- "IntPtr" => "int",
+ "IntPtr" => "gpointer",
"sbyte" => "gint8",
"byte" => "guint8",
"short" => "gint16",
Index: wrapper.c
===================================================================
RCS file: /cvs/public/mono/mono/wrapper/wrapper.c,v
retrieving revision 1.2
diff -u -r1.2 wrapper.c
--- wrapper.c 2001/09/10 07:39:00 1.2
+++ wrapper.c 2001/09/20 06:24:03
@@ -4,32 +4,32 @@
#include "wrapper.h"
gint64
-mono_wrapper_seek (int fd, gint64 offset, gint32 whence)
+mono_wrapper_seek (gpointer fd, gint64 offset, gint32 whence)
{
if (offset > INT_MAX || offset < INT_MIN)
return -1;
- return lseek (fd, offset, whence);
+ return lseek ((int)fd, offset, whence);
}
gint32
-mono_wrapper_read (int fd, void* buf, gint32 count)
+mono_wrapper_read (gpointer fd, void* buf, gint32 count)
{
- return read (fd, buf, count);
+ return read ((int)fd, buf, count);
}
gint32
-mono_wrapper_write (int fd, void* buf, gint32 count)
+mono_wrapper_write (gpointer fd, void* buf, gint32 count)
{
- return write (fd, buf, count);
+ return write ((int)fd, buf, count);
}
gint32
-mono_wrapper_fstat (int fd, MonoWrapperStat* buf)
+mono_wrapper_fstat (gpointer fd, MonoWrapperStat* buf)
{
struct stat fs;
- if (fstat (fd, &fs) != 0)
+ if (fstat ((int)fd, &fs) != 0)
return -1;
buf->st_dev = fs.st_dev;
@@ -46,24 +46,24 @@
}
gint32
-mono_wrapper_ftruncate (int fd, gint64 length)
+mono_wrapper_ftruncate (gpointer fd, gint64 length)
{
if (length > INT_MAX || length < INT_MIN)
return -1;
- return ftruncate (fd, length);
+ return ftruncate ((int)fd, length);
}
-int
+gpointer
mono_wrapper_open (const char * path, gint32 flags, gint32 mode)
{
- return open (path, flags, mode);
+ return (gpointer) open (path, flags, mode);
}
gint32
-mono_wrapper_close (int fd)
+mono_wrapper_close (gpointer fd)
{
- return close (fd);
+ return close ((int)fd);
}
gint32
</pre>
</html>
--------------CA0FAFD6A97BA4C74D07CFE2--