Skip to content

Commit 0519003

Browse files
committed
Merge pull request #549 from java-native-access/fix-pictformat-struct
Fix PictFormat assignment error in X11 libraries
2 parents 7f3c757 + 539e731 commit 0519003

File tree

3 files changed

+54
-0
lines changed

3 files changed

+54
-0
lines changed

CHANGES.md

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ Features
2323

2424
Bug Fixes
2525
---------
26+
* [#549](https://github.com/java-native-access/jna/pull/549): Fixed bug in types derived from XID - [@twall](https://github.com/twall).
2627

2728
Release 4.2.1
2829
=============

contrib/platform/src/com/sun/jna/platform/unix/X11.java

+17
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,19 @@ public interface X11 extends Library {
3535

3636
class VisualID extends NativeLong {
3737
private static final long serialVersionUID = 1L;
38+
public static final VisualID None = null;
3839
public VisualID() { this(0); }
3940
public VisualID(long value) { super(value, true); }
41+
protected boolean isNone(Object o) {
42+
return o == null
43+
|| (o instanceof Number
44+
&& ((Number)o).longValue() == X11.None);
45+
}
46+
public Object fromNative(Object nativeValue, FromNativeContext context) {
47+
if (isNone(nativeValue))
48+
return None;
49+
return new VisualID(((Number)nativeValue).longValue());
50+
}
4051
}
4152

4253
class XID extends NativeLong {
@@ -286,8 +297,14 @@ protected List getFieldOrder() {
286297
}
287298
class PictFormat extends XID {
288299
private static final long serialVersionUID = 1L;
300+
public static final PictFormat None = null;
289301
public PictFormat(long value) { super(value); }
290302
public PictFormat() { this(0); }
303+
public Object fromNative(Object nativeValue, FromNativeContext context) {
304+
if (isNone(nativeValue))
305+
return None;
306+
return new PictFormat(((Number)nativeValue).longValue());
307+
}
291308
}
292309
class XRenderPictFormat extends Structure {
293310
public PictFormat id;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/* Copyright (c) 2015 Timothy Wall, All Rights Reserved
2+
*
3+
* This library is free software; you can redistribute it and/or
4+
* modify it under the terms of the GNU Lesser General Public
5+
* License as published by the Free Software Foundation; either
6+
* version 2.1 of the License, or (at your option) any later version.
7+
* <p/>
8+
* This library is distributed in the hope that it will be useful,
9+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11+
* Lesser General Public License for more details.
12+
*/
13+
package com.sun.jna.platform.unix;
14+
15+
import junit.framework.TestCase;
16+
17+
/**
18+
* Exercise the {@link X11} class.
19+
*
20+
* @author twalljava@java.net
21+
*/
22+
// @SuppressWarnings("unused")
23+
public class X11Test extends TestCase {
24+
25+
public void testXrender() {
26+
X11.Xrender.XRenderPictFormat s = new X11.Xrender.XRenderPictFormat();
27+
s.getPointer().setInt(0, 25);
28+
s.read();
29+
}
30+
31+
public static void main(java.lang.String[] argList) {
32+
junit.textui.TestRunner.run(X11Test.class);
33+
}
34+
}
35+
36+

0 commit comments

Comments
 (0)