#1991: simplify 'new_callback' op
--------------------+-------------------------------------------------------
 Reporter:  jimmy   |       Owner:       
     Type:  RFC     |      Status:  new  
 Priority:  normal  |   Milestone:       
Component:  none    |     Version:  3.0.0
 Severity:  medium  |    Keywords:       
     Lang:          |       Patch:       
 Platform:          |  
--------------------+-------------------------------------------------------
Description changed by jimmy:

Old description:

> Hello,
>     I would like to simplify 'new_callback' op. first please see
> https://github.com/parrot/parrot/blob/master/t/pmc/nci.t#L1545-#L1606-1551.
>     there are lines:
>
> {{{
>     .local pmc user_data
>     user_data = new ['Integer']
>     user_data = 42
>
>     # A Sub that can be given to the library
>     # this callback function will eventually by called by the library
>     .const 'Sub' cb = "_call_back"
>     .local pmc cb_wrapped
>     cb_wrapped = new_callback cb, user_data, "vtU"  # Z in pdd16
>     print "created a callback sub\n"
>
>     # now call the external sub, that takes a callback and user data
>     .local pmc libnci_test
>     libnci_test = loadlib "libnci_test"
>     .local pmc nci_cb_C1
>     nci_cb_C1 = dlfunc libnci_test, "nci_cb_C1", "vpP"
>     print "loaded a function that takes a callback\n"
>     nci_cb_C1( cb_wrapped, user_data )
>
> }}}
>

> passing the value of user_data into new_callback is useless and unused,
> because it's finally invoked and used by this code.
> nci_cb_C1( cb_wrapped, user_data ). So consider:
>
> {{{
>     .local pmc user_data
>     user_data = new ['Integer']
>
>     # A Sub that can be given to the library
>     # this callback function will eventually by called by the library
>     .const 'Sub' cb = "_call_back"
>     .local pmc cb_wrapped
>     user_data = 42
>     cb_wrapped = new_callback cb, user_data, "vtU"  # Z in pdd16
>     print "created a callback sub\n"
>
>     # now call the external sub, that takes a callback and user data
>     .local pmc libnci_test
>     libnci_test = loadlib "libnci_test"
>     .local pmc nci_cb_C1
>     nci_cb_C1 = dlfunc libnci_test, "nci_cb_C1", "vpP"
>     print "loaded a function that takes a callback\n"
>     user_data = 44   # user_data is changed here.
>     nci_cb_C1( cb_wrapped, user_data )
>
> }}}
>
> so passing user_data = 42 to new_callback is redundant, I would simplify
> it to this one:
>
> {{{
>     cb_wrapped = new_callback cb, "vtU"
> }}}

New description:

 Hello,
     I would like to simplify 'new_callback' op. first please see
 https://github.com/parrot/parrot/blob/master/t/pmc/nci.t#L1545-#L1606-1551.
     there are lines:

 {{{
     .local pmc user_data
     user_data = new ['Integer']
     user_data = 42

     # A Sub that can be given to the library
     # this callback function will eventually by called by the library
     .const 'Sub' cb = "_call_back"
     .local pmc cb_wrapped
     cb_wrapped = new_callback cb, user_data, "vtU"  # Z in pdd16
     print "created a callback sub\n"

     # now call the external sub, that takes a callback and user data
     .local pmc libnci_test
     libnci_test = loadlib "libnci_test"
     .local pmc nci_cb_C1
     nci_cb_C1 = dlfunc libnci_test, "nci_cb_C1", "vpP"
     print "loaded a function that takes a callback\n"
     nci_cb_C1( cb_wrapped, user_data )

 }}}


 passing the value of user_data into new_callback is useless and unused,
 because it's finally invoked and used by this code:

 {{{
 nci_cb_C1( cb_wrapped, user_data )
 }}}


 So consider:

 {{{
     .local pmc user_data
     user_data = new ['Integer']

     # A Sub that can be given to the library
     # this callback function will eventually by called by the library
     .const 'Sub' cb = "_call_back"
     .local pmc cb_wrapped
     user_data = 42
     cb_wrapped = new_callback cb, user_data, "vtU"  # Z in pdd16
     print "created a callback sub\n"

     # now call the external sub, that takes a callback and user data
     .local pmc libnci_test
     libnci_test = loadlib "libnci_test"
     .local pmc nci_cb_C1
     nci_cb_C1 = dlfunc libnci_test, "nci_cb_C1", "vpP"
     print "loaded a function that takes a callback\n"
     user_data = 44   # user_data is changed here.
     nci_cb_C1( cb_wrapped, user_data )

 }}}

 so passing user_data = 42 to new_callback is redundant, I would simplify
 it to this one:

 {{{
     cb_wrapped = new_callback cb, "vtU"
 }}}

--

-- 
Ticket URL: <https://trac.parrot.org/parrot/ticket/1991#comment:2>
Parrot <https://trac.parrot.org/parrot/>
Parrot Development
_______________________________________________
parrot-tickets mailing list
[email protected]
http://lists.parrot.org/mailman/listinfo/parrot-tickets

Reply via email to