Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

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

Aperta
#3,509 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
58/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Tranquilla
Stack tecnologico
java
Ambito
desktop

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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.

Lingua principale
Java
Stelle
202
Fork
206
Merge medio
16h 56m
PR unite (30g)
110

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di eclipse-platform/eclipse.platform.swt

Tutte le issue di eclipse-platform/eclipse.platform.swt

Issue simili

Altre issue su Java

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.