| 2330 | } |
| 2331 | |
| 2332 | void ObjectInstance::release_native_object() { |
| 2333 | static GType gdksurface_type = 0; |
| 2334 | |
| 2335 | discard_wrapper(); |
| 2336 | |
| 2337 | if (m_gobj_finalized) { |
| 2338 | g_critical( |
| 2339 | "Object %p of type %s has been finalized while it was still " |
| 2340 | "owned by gjs, this is due to invalid memory management.", |
| 2341 | m_ptr.get(), g_type_name(gtype())); |
| 2342 | m_ptr.release(); |
| 2343 | return; |
| 2344 | } |
| 2345 | |
| 2346 | if (m_ptr) |
| 2347 | gjs_debug_lifecycle(GJS_DEBUG_GOBJECT, "Releasing native object %s %p", |
| 2348 | g_type_name(gtype()), m_ptr.get()); |
| 2349 | |
| 2350 | if (m_gobj_disposed) |
| 2351 | ignore_gobject_finalization(); |
| 2352 | |
| 2353 | if (m_uses_toggle_ref && !m_gobj_disposed) { |
| 2354 | g_object_remove_toggle_ref(m_ptr.release(), wrapped_gobj_toggle_notify, |
| 2355 | this); |
| 2356 | return; |
| 2357 | } |
| 2358 | |
| 2359 | // Unref the object. Handle any special cases for destruction here |
| 2360 | if (m_ptr->ref_count == 1) { |
| 2361 | // Quickest way to check for GdkSurface if Gdk has been loaded? |
| 2362 | // surface_type may be 0 if Gdk not loaded. The type may be a private |
| 2363 | // type and not have introspection info. |
| 2364 | if (!gdksurface_type) |
| 2365 | gdksurface_type = g_type_from_name("GdkSurface"); |
| 2366 | if (gdksurface_type && g_type_is_a(gtype(), gdksurface_type)) { |
| 2367 | GObject* ptr = m_ptr.release(); |
| 2368 | |
| 2369 | // Workaround for https://gitlab.gnome.org/GNOME/gtk/-/issues/6289 |
| 2370 | GI::Repository repo; |
| 2371 | GI::AutoObjectInfo surface_info{ |
| 2372 | repo.find_by_gtype<GI::InfoTag::OBJECT>(gdksurface_type) |
| 2373 | .value()}; |
| 2374 | GI::AutoFunctionInfo destroy_func{ |
| 2375 | surface_info.method("destroy").value()}; |
| 2376 | GIArgument destroy_args; |
| 2377 | gjs_arg_set(&destroy_args, ptr); |
| 2378 | GIArgument unused_return; |
| 2379 | |
| 2380 | auto result = |
| 2381 | destroy_func.invoke({{destroy_args}}, {}, &unused_return); |
| 2382 | if (result.isErr()) |
| 2383 | g_critical("Error destroying GdkSurface %p: %s", ptr, |
| 2384 | result.inspectErr()->message); |
| 2385 | } |
| 2386 | } |
| 2387 | |
| 2388 | m_ptr = nullptr; |
| 2389 | } |
nothing calls this directly
no test coverage detected