Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

g_signal_connect returns int while GLib returns gulong, so DropTarget handler ids break at 2^31

オープン
#3,509 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
58/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
静か
技術スタック
java
領域
desktop

調査の方向性

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

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

eclipse-platform/eclipse.platform.swt のほかの issue

eclipse-platform/eclipse.platform.swt の issue をすべて見る

似ている issue

Java の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。