For the sake of curiosity I'm in charge porting some JNI code to JNA. My target refactoring was JLine because I like very much this library, it is simple but complete. During the port I've spotted some interesting problems:
Well, after just 2 hours of "soft hacking" (while watching a movie!) I've successfully revamped the WindowsTerminal class using JNA. Unit tests still passes on Windows. The real problem is refactoring the call to stty on UNIX. I'm wondering about a fork of JLine. * the memory leak: JNIEXPORT jint JNICALL Java_jline_WindowsTerminal_getWindowsTerminalHeight (JNIEnv *env, jclass class) { HANDLE outputHandle = GetStdHandle(STD_OUTPUT_HANDLE); PCONSOLE_SCREEN_BUFFER_INFO info = malloc(sizeof CONSOLE_SCREEN_BUFFER_INFO); GetConsoleScreenBufferInfo(outputHandle, info); return info->srWindow.Bottom - info->srWindow.Top+1; } as you can see info is never released within this function. Now take a look at the Java version: private int getWindowsTerminalWidth() { int h = kernel32.GetStdHandle(kernel32.STD_OUTPUT_HANDLE); CONSOLE_SCREEN_BUFFER_INFO info = new CONSOLE_SCREEN_BUFFER_INFO(); kernel32.GetConsoleScreenBufferInfo(h, info); return info.wWindowRight - info.wWindowLeft + 1; } |

