3 messages in net.java.dev.jna.users[jna-users] fseek in windows crashes JVM
FromSent OnAttachments
Luigi BitontiSep 4, 2008 7:42 am 
Timothy WallSep 4, 2008 9:30 am 
Luigi BitontiSep 11, 2008 6:55 am 
Actions with this message:
Paste this link in email or IM:
Paste this link in email or IM:
Atom feed for this thread
Paste this URL into your reader:
Subject:[jna-users] fseek in windows crashes JVMActions...
From:Luigi Bitonti (ukna@yahoo.com)
Date:Sep 4, 2008 7:42:39 am
List:net.java.dev.jna.users

Hi,

First of all, thanks very much to all the people that contributed to this great
project.

I have written a Lame  (mp3 encoding library) wrapper based on JNA, for which I have made a first alpha relase. It is called Lamejb and can be found at http://lamejb.sourceforge.net/

At the moment I have one (known) bug on Windows and I would be grateful if anyone of you could give me an idea of why this does not work as expected.

I have the following mappings declared for the fopen and fclose C library
functions:

public interface FileUtil extends Library {         FileUtil INSTANCE =         (FileUtil)Native.loadLibrary((Platform.isWindows() ? "msvcrt" : "c"),
FileUtil.class);

    /**      * <pre>FILE *fopen(const char *filename, const char *mode); </pre>      */     Pointer fopen(String filename,String mode);         /**      * <pre>int fclose(FILE *stream);</pre>      */     int fclose(Pointer stream);

}

These are in turn used by another mapping to a native library call that takes a file pointer as argument and writes some tags in a file (for variable bit rates). This is the sequence of calls:

Pointer fp = FileUtil.INSTANCE.fopen( mp3File, "rb+" );             Lame.INSTANCE.lame_mp3_tags_fid( flags, fp );

FileUtil.INSTANCE.fclose( fp );

The second call (Lame.INSTANCE.lame_mp3_tags_fid( flags, fp )) crashes the VM on
Windows, but works on Linux. I have found out that what makes the VM crash in Windows is a call to the native function fseek,
specifically:

fseek(FILE *_File, long _Offset, int _Origin)

Does anyone have an idea of the reason why this happens?

Thanks in advance for your help.

Luigi