g_signal_connect returns int while GLib returns gulong, so DropTarget handler ids break at 2^31
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
調査の方向性
Read the native declarations in bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk/OS.java alongside the generated stubs in bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os.c. Then inspect the four handler fields and their connect/disconnect uses in bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/gtk/org/eclipse/swt/dnd/DropTarget.java. Done means the producer declarations and retained handler IDs preserve the GLib return value; build and test the GTK SWT bindings.
索引モデルが issue の本文から書いたものです。
説明
OS.g_signal_connect is declared to return a Java int. GLib's g_signal_connect is a macro over g_signal_connect_data, which returns gulong — 64-bit on LP64. The generated stub casts the result down with (jint), so the C compiler stays quiet and javac never sees the C declaration.
// bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk/OS.java:1357
public static final native int g_signal_connect(long instance, byte[] detailed_signal, long proc, long data);
// OS.java:1402 — this side was widened by #462 / 417af5e1
public static final native void g_signal_handler_disconnect(long instance, long handler_id);
/* bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os.c */
rc = (jint)g_signal_connect((gpointer)arg0, (const gchar *)lparg1, ...);
// bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/gtk/org/eclipse/swt/dnd/DropTarget.java
:103 int drag_motion_handler;
:206 drag_motion_handler = OS.g_signal_connect(control.handle, OS.drag_motion, ...);
:669 OS.g_signal_handler_disconnect(control.handle, drag_motion_handler);
What it can cause
#462 widened g_signal_handler_disconnect, but the id is truncated by the producer before it ever reaches the consumer, and DropTarget holds it in an int field. Java's int → long widening is a sign extension (JLS 5.1.2), so widening the parameter could not recover the bits:
| handler id | what GLib receives on disconnect | effect |
|---|---|---|
< 2^31 |
the same id | fine — which is why this has not been seen |
2^31 … 2^32 |
0xFFFFFFFF80000000-style |
an id GLib never issued; the handler is not disconnected and keeps running against a disposed DropTarget |
> 2^32 |
a different, small id (2^32 + 5 → 5) |
may name a live handler belonging to something else |
The threshold usually quoted for this is 4G, because that is where a gulong stops fitting in 32 bits. Java's int is signed and the conversion back is a sign extension, so the first id that fails to round-trip is 2 147 483 648, half of that. Against the rate measured in 417af5e1 ("counter jumps by ~20k" per window open and close), that halves the time to failure.
No observed failure — nothing here was built or run, and no id above 2^31 was witnessed. LP64 only; under LLP64 gulong is 32-bit and none of this applies.
Fix
Declare long on the producer — g_signal_connect, and the same for g_signal_connect_closure (OS.java:1364) and g_signal_connect_closure_by_id (:1372), which have the identical mismatch but whose returns no caller currently keeps — and widen the four DropTarget fields at :103-106 with them. The consumer side is already correct.
How this was found
By a research tool that compares each Java native declaration against the C declaration of the function its generated stub actually calls. The 2^31 threshold was then derived as arithmetic. Every line quoted above was re-read on master on 2026-08-16.
Edited 2026-08-16: shortened. The claim, the evidence and the line numbers are unchanged.
- 主要言語
- Java
- スター
- 202
- フォーク
- 206
- 平均マージ
- 14時間 7分
- マージ済み PR(30日)
- 103
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
eclipse-platform/eclipse.platform.swt のほかの issue
-
`SWT_AWT.initFrame` takes `(long, String)` in Java; the GTK native declares no `className` and the Cocoa native types it `const char *`対応中かも @GreenFuze が 2 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
eclipse-platform/eclipse.platform.swt#3665 · コメント 3 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
eclipse-platform/eclipse.platform.swt#3546 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
eclipse-platform/eclipse.platform.swt#3428 ·
メンテナーはふだん 1 日以内に返信
-
難易度 1/5 1〜3時間 初心者へのやさしさ 75/100
eclipse-platform/eclipse.platform.swt#3336 · コメント 3 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 4/5 3〜5日 初心者へのやさしさ 30/100
eclipse-platform/eclipse.platform.swt#3718 ·
メンテナーはふだん 1 日以内に返信
eclipse-platform/eclipse.platform.swt の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
メンテナーはふだん 1 日以内に返信
-
bug new windows
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
GantMan/jail-monkey#380 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
objectionary/jucs#145 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
objectionary/lints#1559 ·
メンテナーはふだん 2 日以内に返信