Bug with the callbacks

Project:GNU Smalltalk
Component:VM
Category:bug
Priority:normal
Assigned:Unassigned
Status:invalid
Description

If I eval that code inside the workspace the vm crashes :
GTK.Gtk keySnooperInstall: (CCallbackDescriptor

    for: [ :aGtkWidget :aGdkEventKey :aFuncData |
   'here' printNl.
   false ]
    returning: #boolean
    withArgs: #(#long #long #cObject)) funcData: nil.

I've attached the backtrace

Updates

#1 submitted by Paolo Bonzini on Fri, 09/17/2010 - 07:26
  1. 0 0x00007ffff67cda75 in *__GI_raise (sig=) at ../nptl/sysdeps/unix/sysv/linux/raise.c:64
  2. 1 0x00007ffff67d15c0 in *__GI_abort () at abort.c:92
  3. 2 0x00007ffff68074fb in __libc_message (do_abort=, fmt=) at ../sysdeps/unix/sysv/linux/libc_fatal.c:189
  4. 3 0x00007ffff68115b6 in malloc_printerr (action=3, str=0x7ffff68e4b58 "munmap_chunk(): invalid pointer", ptr=) at malloc.c:6264
  5. 4 0x00007ffff7b1c36b in _gst_free_cobject (cObjOOP=) at dict.c:2121
  6. 5 0x00007ffff7b50db6 in VMpr_CObject_free (id=, numArgs=0) at prims.def:4408
  7. 6 0x00007ffff7b4b747 in execute_primitive_operation (primitive=193, numArgs=0) at interp.c:2699
  8. 7 0x00007ffff7b583d6 in _gst_send_message_internal (sendSelector=, sendArgs=0, receiver=0x2b694216ef90, method_class=)

   at interp-bc.inl:276

  1. 8 0x00007ffff7b615db in _gst_interpret (processOOP=0x2b6941e2d1d0) at vm.def:693
  2. 9 0x00007ffff7b66f38 in _gst_nvmsg_send (receiver=0x2b6941e7fb90, sendSelector=0x2b6941e34860, args=, sendArgs=4) at interp.c:2271
  3. 10 0x00007fffd2ad437c in invoke_smalltalk_closure (closure=0xa978e0, return_value=0x0, n_param_values=, param_values=,

   invocation_hint=0x0, marshal_data=0x7ffff7b054b0) at gst-gtk.c:593

  1. 11 0x00007ffff72155de in IA__g_closure_invoke (closure=0xa978e0, return_value=0x0, n_param_values=4, param_values=0xa9fd80, invocation_hint=0x7fffffffb550)

   at /build/buildd/glib2.0-2.24.1/gobject/gclosure.c:767

  1. 12 0x00007ffff7229598 in signal_emit_unlocked_R (node=0x8b8010, detail=, instance=, emission_return=,

   instance_and_params=) at /build/buildd/glib2.0-2.24.1/gobject/gsignal.c:3248

  1. 13 0x00007ffff722aa76 in IA__g_signal_emit_valist (instance=0xa95020, signal_id=, detail=0, var_args=0x7fffffffb740)

   at /build/buildd/glib2.0-2.24.1/gobject/gsignal.c:2981

  1. 14 0x00007ffff722b033 in IA__g_signal_emit (instance=0xaba, signal_id=2746, detail=6) at /build/buildd/glib2.0-2.24.1/gobject/gsignal.c:3038
  2. 15 0x00007ffff7b7f0dc in ffi_call_unix64 () at src/x86/unix64.S:75
  3. 16 0x00007ffff7b7ee64 in ffi_call (cif=, fn=, rvalue=, avalue=0x7fffffffb9d0) at src/x86/ffi64.c:430
  4. 17 0x00007ffff7b3848b in _gst_invoke_croutine (cFuncOOP=0x2b6941e00730, receiver=0x2b6941e85870, args=) at cint.c:879
  5. 18 0x00007ffff7b4f0cb in VMpr_CFuncDescriptor_call (id=, numArgs=1) at prims.def:5963
  6. 19 0x00007ffff7b4b747 in execute_primitive_operation (primitive=229, numArgs=1) at interp.c:2699
  7. 20 0x00007ffff7b583d6 in _gst_send_message_internal (sendSelector=, sendArgs=1, receiver=0x2b6941e00730, method_class=)

   at interp-bc.inl:276

  1. 21 0x00007ffff7b62481 in _gst_interpret (processOOP=0x2b694216f6d0) at vm.def:713
  2. 22 0x00007ffff7b66f38 in _gst_nvmsg_send (receiver=0x2b694216eea0, sendSelector=0x0, args=, sendArgs=3) at interp.c:2271
  3. 23 0x00007ffff7b392a3 in closure_msg_send (cif=, result=, args=0x7fffffffbf00, userdata=) at cint.c:1379
  4. 24 0x00007ffff7b7ea49 in ffi_closure_unix64_inner (closure=, rvalue=, reg_args=0x202, argp=0x7fffffffc0b0 "\200\003\"\001")

   at src/x86/ffi64.c:566

  1. 25 0x00007ffff7b7f208 in ffi_closure_unix64 () at src/x86/unix64.S:230
  2. 26 0x00007fffd25e8654 in gtk_invoke_key_snoopers (event=0xb89b10) at /build/buildd/gtk+2.0-2.20.1/gtk/gtkmain.c:1959
  3. 27 IA__gtk_main_do_event (event=0xb89b10) at /build/buildd/gtk+2.0-2.20.1/gtk/gtkmain.c:1615
  4. 28 0x00007fffd225c86c in gdk_event_dispatch (source=, callback=, user_data=)

   at /build/buildd/gtk+2.0-2.20.1/gdk/x11/gdkevents-x11.c:2372

  1. 29 0x00007ffff6b5b8c2 in g_main_dispatch (context=0x6cb0c0) at /build/buildd/glib2.0-2.24.1/glib/gmain.c:1960
  2. 30 IA__g_main_context_dispatch (context=0x6cb0c0) at /build/buildd/glib2.0-2.24.1/glib/gmain.c:2513
  3. 31 0x00007fffd2ad3b00 in main_context_iterate (context=0x6cb0c0) at gst-gtk.c:888
  4. 32 0x00007ffff7b7f0dc in ffi_call_unix64 () at src/x86/unix64.S:75
  5. 33 0x00007ffff7b7ee64 in ffi_call (cif=, fn=, rvalue=, avalue=0x7fffffffc320) at src/x86/ffi64.c:430
  6. 34 0x00007ffff7b3848b in _gst_invoke_croutine (cFuncOOP=0x2b6941e2e7e0, receiver=0x2b6941e651e0, args=) at cint.c:879
  7. 35 0x00007ffff7b4f2ab in VMpr_CFuncDescriptor_asyncCall (id=, numArgs=0) at prims.def:5909
  8. 36 0x00007ffff7b4b747 in execute_primitive_operation (primitive=228, numArgs=0) at interp.c:2699
  9. 37 0x00007ffff7b583d6 in _gst_send_message_internal (sendSelector=, sendArgs=0, receiver=0x2b6941e2e7e0, method_class=)

---Type to continue, or q to quit---

   at interp-bc.inl:276

  1. 38 0x00007ffff7b62a8e in _gst_interpret (processOOP=0x2b6941e4efc0) at vm.def:693
  2. 39 0x00007ffff7b66f38 in _gst_nvmsg_send (receiver=0x2b6941bf0000, sendSelector=0x2b6941e4ece0, args=, sendArgs=0) at interp.c:2271
  3. 40 0x00007ffff7b18f0f in _gst_execute_statements (temps=, statements=, undeclared=, quiet=true) at comp.c:691
  4. 41 0x00007ffff7b0922b in parse_eval_definition (p=) at gst-parse.c:594
  5. 42 0x00007ffff7b0c30e in parse_scoped_definition (p=0x7fffffffcb70, fail_at_eof=) at gst-parse.c:501
  6. 43 parse_doit (p=0x7fffffffcb70, fail_at_eof=) at gst-parse.c:462
  7. 44 0x00007ffff7b0c941 in parse_chunks (p=) at gst-parse.c:364
  8. 45 0x00007ffff7b0ccf8 in _gst_parse_chunks () at gst-parse.c:341
  9. 46 0x00007ffff7b0d226 in _gst_parse_stream (method=false) at lex.c:1186
  10. 47 0x00007ffff7b500cf in parse_stream_with_protection (method=) at interp.c:2768
  11. 48 0x00007ffff7b501d8 in VMpr_Stream_fileInLine (id=, numArgs=4) at prims.def:5348
  12. 49 0x00007ffff7b4b747 in execute_primitive_operation (primitive=225, numArgs=4) at interp.c:2699
  13. 50 0x00007ffff7b583d6 in _gst_send_message_internal (sendSelector=, sendArgs=4, receiver=0x2b6941e4e510, method_class=)

   at interp-bc.inl:276

  1. 51 0x00007ffff7b5c246 in _gst_interpret (processOOP=0x2b6941e88ec0) at vm.def:693
  2. 52 0x00007ffff7b66f38 in _gst_nvmsg_send (receiver=0x2b6941bf0000, sendSelector=0x2b6941e88e40, args=, sendArgs=0) at interp.c:2271
  3. 53 0x00007ffff7b18f0f in _gst_execute_statements (temps=, statements=, undeclared=, quiet=true) at comp.c:691
  4. 54 0x00007ffff7b0922b in parse_eval_definition (p=) at gst-parse.c:594
  5. 55 0x00007ffff7b0c30e in parse_scoped_definition (p=0x7fffffffd520, fail_at_eof=) at gst-parse.c:501
  6. 56 parse_doit (p=0x7fffffffd520, fail_at_eof=) at gst-parse.c:462
  7. 57 0x00007ffff7b0c941 in parse_chunks (p=) at gst-parse.c:364
  8. 58 0x00007ffff7b0ccf8 in _gst_parse_chunks () at gst-parse.c:341
  9. 59 0x00007ffff7b0d226 in _gst_parse_stream (method=false) at lex.c:1186
  10. 60 0x00007ffff7b500cf in parse_stream_with_protection (method=) at interp.c:2768
  11. 61 0x00007ffff7b501d8 in VMpr_Stream_fileInLine (id=, numArgs=4) at prims.def:5348
  12. 62 0x00007ffff7b4b747 in execute_primitive_operation (primitive=225, numArgs=4) at interp.c:2699
  13. 63 0x00007ffff7b583d6 in _gst_send_message_internal (sendSelector=, sendArgs=4, receiver=0x2b6941e88d30, method_class=)

   at interp-bc.inl:276

  1. 64 0x00007ffff7b5c246 in _gst_interpret (processOOP=0x2b6941e85250) at vm.def:693
  2. 65 0x00007ffff7b66f38 in _gst_nvmsg_send (receiver=0x2b6941bf0000, sendSelector=0x2b6941e851d0, args=, sendArgs=0) at interp.c:2271
  3. 66 0x00007ffff7b18f0f in _gst_execute_statements (temps=, statements=, undeclared=, quiet=true) at comp.c:691
  4. 67 0x00007ffff7b0bedc in parse_doit (p=0x7fffffffddd0, fail_at_eof=) at gst-parse.c:472
  5. 68 0x00007ffff7b0c941 in parse_chunks (p=) at gst-parse.c:364
  6. 69 0x00007ffff7b0ccf8 in _gst_parse_chunks () at gst-parse.c:341
  7. 70 0x00007ffff7b0d226 in _gst_parse_stream (method=false) at lex.c:1186
  8. 71 0x00007ffff7b3ae44 in _gst_process_file (fileName=, dir=) at input.c:846
  9. 72 0x0000000000401f55 in main (argc=, argv=0x7fffffffe1b8) at gst-tool.c:545

#2 submitted by Gwenael Casaccio on Thu, 10/07/2010 - 18:13

Shouldn't we redefine the finalize or the free method since we inherit
from CObject and it calls the free method ?

CCallable >> free [ ] should work.

It fixes the first part of the problem.

Now we've got on the console:

a Smalltalk Stream:2: Attempt to pass the BlockClosure class object as a void *
(ip 4)GMainContext>>#iterate
(ip 10)[] in Gtk class>>#main
(ip 6) BlockClosure>>#ensure:
(ip 36)Gtk class>>#main
(ip 10)UndefinedObject>>#executeStatements
(ip 0)

#3 submitted by Paolo Bonzini on Fri, 10/08/2010 - 17:18

It should work, see this in prims.def:

 if COMMON (is_a_kind_of (OOP_CLASS (oop1), _gst_c_callback_descriptor_class))
   {
     _gst_free_closure (oop1);
     SET_STACKTOP (_gst_nil_oop);
     PRIM_SUCCEEDED;
   }

 else if COMMON (RECEIVER_IS_A_KIND_OF (OOP_CLASS (oop1), _gst_c_object_class))
   {
     _gst_free_cobject (oop1); /* free allocated space */
     SET_STACKTOP (_gst_nil_oop);
     PRIM_SUCCEEDED;
   }

But you gave me the correct hint: look at 78e29a0c. I'll look at the other error now.

#4 submitted by Gwenael Casaccio on Fri, 07/29/2011 - 10:58
Status:active» invalid

This is my fault, the callback is free when the gc sweep it. I should keep a reference of it somewhere:

GTK.Gtk keySnooperInstall: (CCallbackDescriptor ...)

call the primitive with the callback, but the callback reference will be swept at the next garbage collection.
A solution is to register it in the keysnooper.

User login