[perl-Glib-Object-Introspection] Pass on NULL user data in C invocations if appropriate



commit d2e0b80c1e97579862c09fd7d7dc376c8c2c6941
Author: Torsten Schönfeld <kaffeetisch gmx de>
Date:   Mon Dec 2 22:24:52 2013 +0100

    Pass on NULL user data in C invocations if appropriate
    
    If the user did not specify any callback and user data, and if there is no slot
    for a C destroy notify function pointer, then pass on NULL for the C user data.
    There is no point in passing on anything else, and some libraries (e.g., vte)
    even require that the C user data be NULL if the C function pointer is NULL.

 gperl-i11n-marshal-callback.c |   13 +++++++++++++
 1 files changed, 13 insertions(+), 0 deletions(-)
---
diff --git a/gperl-i11n-marshal-callback.c b/gperl-i11n-marshal-callback.c
index 0967818..ab05630 100644
--- a/gperl-i11n-marshal-callback.c
+++ b/gperl-i11n-marshal-callback.c
@@ -71,6 +71,19 @@ sv_to_callback_data (SV * sv,
                        dwarn ("      user data for Perl callback %p\n",
                               callback_info);
                        attach_perl_callback_data (callback_info, sv);
+                       /* If the user did not specify any code and data and if
+                        * there is no destroy notify function, then there is
+                        * no need for us to pass on our callback info struct
+                        * as C user data.  Some libraries (e.g., vte) even
+                        * assert that the C user data be NULL if the C
+                        * function pointer is NULL. */
+                       if (!gperl_sv_is_defined (callback_info->code) &&
+                           !gperl_sv_is_defined (callback_info->data) &&
+                           -1 == callback_info->destroy_pos)
+                       {
+                               dwarn ("        handing over NULL");
+                               return NULL;
+                       }
                        return callback_info;
                }
        }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]