gem-graph-client/docs/GTK-docs/gnome-dev-documentation/developer.gnome.org/documentation/tutorials/deprecations.html

498 lines
33 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!doctype html>
<html class="no-js">
<head><meta charset="utf-8"/>
<meta name="viewport" content="width=device-width,initial-scale=1"/>
<meta name="color-scheme" content="light dark"><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" />
<link rel="index" title="Index" href="../genindex.html" /><link rel="search" title="Search" href="../search.html" /><link rel="next" title="Actions" href="actions.html" /><link rel="prev" title="Themed Icons" href="themed-icons.html" />
<meta name="generator" content="sphinx-4.3.0, furo 2022.06.21"/>
<title>Dealing With Deprecations - GNOME Developer Documentation</title>
<link rel="stylesheet" type="text/css" href="../_static/pygments.css" />
<link rel="stylesheet" type="text/css" href="../_static/styles/furo.css?digest=40978830699223671f4072448e654b5958f38b89" />
<link rel="stylesheet" type="text/css" href="../_static/tabs.css" />
<link rel="stylesheet" type="text/css" href="../_static/styles/furo-extensions.css?digest=30d1aed668e5c3a91c3e3bf6a60b675221979f0e" />
<link rel="stylesheet" type="text/css" href="../_static/gnome.css" />
<style>
body {
--color-code-background: #f8f8f8;
--color-code-foreground: black;
--color-brand-primary: #4a86cf;
--color-brand-content: #4a86cf;
}
@media not print {
body[data-theme="dark"] {
--color-code-background: #202020;
--color-code-foreground: #d0d0d0;
}
@media (prefers-color-scheme: dark) {
body:not([data-theme="light"]) {
--color-code-background: #202020;
--color-code-foreground: #d0d0d0;
}
}
}
</style></head>
<body>
<svg xmlns="http://www.w3.org/2000/svg" style="display: none;">
<symbol id="svg-toc" viewBox="0 0 24 24">
<title>Contents</title>
<svg stroke="currentColor" fill="currentColor" stroke-width="0" viewBox="0 0 1024 1024">
<path d="M408 442h480c4.4 0 8-3.6 8-8v-56c0-4.4-3.6-8-8-8H408c-4.4 0-8 3.6-8 8v56c0 4.4 3.6 8 8 8zm-8 204c0 4.4 3.6 8 8 8h480c4.4 0 8-3.6 8-8v-56c0-4.4-3.6-8-8-8H408c-4.4 0-8 3.6-8 8v56zm504-486H120c-4.4 0-8 3.6-8 8v56c0 4.4 3.6 8 8 8h784c4.4 0 8-3.6 8-8v-56c0-4.4-3.6-8-8-8zm0 632H120c-4.4 0-8 3.6-8 8v56c0 4.4 3.6 8 8 8h784c4.4 0 8-3.6 8-8v-56c0-4.4-3.6-8-8-8zM115.4 518.9L271.7 642c5.8 4.6 14.4.5 14.4-6.9V388.9c0-7.4-8.5-11.5-14.4-6.9L115.4 505.1a8.74 8.74 0 0 0 0 13.8z"/>
</svg>
</symbol>
<symbol id="svg-menu" viewBox="0 0 24 24">
<title>Menu</title>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor"
stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather-menu">
<line x1="3" y1="12" x2="21" y2="12"></line>
<line x1="3" y1="6" x2="21" y2="6"></line>
<line x1="3" y1="18" x2="21" y2="18"></line>
</svg>
</symbol>
<symbol id="svg-arrow-right" viewBox="0 0 24 24">
<title>Expand</title>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor"
stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather-chevron-right">
<polyline points="9 18 15 12 9 6"></polyline>
</svg>
</symbol>
<symbol id="svg-sun" viewBox="0 0 24 24">
<title>Light mode</title>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor"
stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" class="feather-sun">
<circle cx="12" cy="12" r="5"></circle>
<line x1="12" y1="1" x2="12" y2="3"></line>
<line x1="12" y1="21" x2="12" y2="23"></line>
<line x1="4.22" y1="4.22" x2="5.64" y2="5.64"></line>
<line x1="18.36" y1="18.36" x2="19.78" y2="19.78"></line>
<line x1="1" y1="12" x2="3" y2="12"></line>
<line x1="21" y1="12" x2="23" y2="12"></line>
<line x1="4.22" y1="19.78" x2="5.64" y2="18.36"></line>
<line x1="18.36" y1="5.64" x2="19.78" y2="4.22"></line>
</svg>
</symbol>
<symbol id="svg-moon" viewBox="0 0 24 24">
<title>Dark mode</title>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor"
stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" class="icon-tabler-moon">
<path stroke="none" d="M0 0h24v24H0z" fill="none" />
<path d="M12 3c.132 0 .263 0 .393 0a7.5 7.5 0 0 0 7.92 12.446a9 9 0 1 1 -8.313 -12.454z" />
</svg>
</symbol>
<symbol id="svg-sun-half" viewBox="0 0 24 24">
<title>Auto light/dark mode</title>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor"
stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" class="icon-tabler-shadow">
<path stroke="none" d="M0 0h24v24H0z" fill="none"/>
<circle cx="12" cy="12" r="9" />
<path d="M13 12h5" />
<path d="M13 15h4" />
<path d="M13 18h1" />
<path d="M13 9h4" />
<path d="M13 6h1" />
</svg>
</symbol>
</svg>
<input type="checkbox" class="sidebar-toggle" name="__navigation" id="__navigation">
<input type="checkbox" class="sidebar-toggle" name="__toc" id="__toc">
<label class="overlay sidebar-overlay" for="__navigation"></label>
<label class="overlay toc-overlay" for="__toc"></label>
<div class="page">
<header class="mobile-header">
<div class="header-left">
<label class="nav-overlay-icon" for="__navigation">
<i class="icon"><svg><use href="#svg-menu"></use></svg></i>
</label>
</div>
<div class="header-center">
<a href="../index.html"><div class="brand">GNOME Developer Documentation</div></a>
</div>
<div class="header-right">
<label class="toc-overlay-icon toc-header-icon" for="__toc">
<i class="icon"><svg><use href="#svg-toc"></use></svg></i>
</label>
</div>
</header>
<aside class="sidebar-drawer">
<div class="sidebar-container">
<div class="sidebar-sticky"><a class="sidebar-brand" href="../index.html">
<span class="sidebar-brand-text">GNOME Developer Documentation</span>
</a><form class="sidebar-search-container" method="get" action="../search.html" role="search">
<input class="sidebar-search" placeholder=Search name="q" aria-label="Search">
<input type="hidden" name="check_keywords" value="yes">
<input type="hidden" name="area" value="default">
</form>
<div id="searchbox"></div><div class="sidebar-scroll"><div class="sidebar-tree">
<p class="caption" role="heading"><span class="caption-text">Contents</span></p>
<ul class="current">
<li class="toctree-l1 has-children"><a class="reference internal" href="../introduction.html">Platform Introduction</a><input class="toctree-checkbox" id="toctree-checkbox-1" name="toctree-checkbox-1" role="switch" type="checkbox"/><label for="toctree-checkbox-1"><div class="visually-hidden">Toggle child pages in navigation</div><i class="icon"><svg><use href="#svg-arrow-right"></use></svg></i></label><ul>
<li class="toctree-l2 has-children"><a class="reference internal" href="../introduction/components.html">Platform Components</a><input class="toctree-checkbox" id="toctree-checkbox-2" name="toctree-checkbox-2" role="switch" type="checkbox"/><label for="toctree-checkbox-2"><div class="visually-hidden">Toggle child pages in navigation</div><i class="icon"><svg><use href="#svg-arrow-right"></use></svg></i></label><ul>
<li class="toctree-l3"><a class="reference internal" href="../introduction/overview/libraries.html">Libraries</a></li>
<li class="toctree-l3"><a class="reference internal" href="../introduction/overview/services.html">Services</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="../introduction/languages.html">Programming Languages</a></li>
<li class="toctree-l2"><a class="reference internal" href="../introduction/builder.html">GNOME Builder</a></li>
<li class="toctree-l2"><a class="reference internal" href="../introduction/flatpak.html">Flatpak</a></li>
</ul>
</li>
<li class="toctree-l1 has-children"><a class="reference internal" href="../guidelines.html">Guidelines</a><input class="toctree-checkbox" id="toctree-checkbox-3" name="toctree-checkbox-3" role="switch" type="checkbox"/><label for="toctree-checkbox-3"><div class="visually-hidden">Toggle child pages in navigation</div><i class="icon"><svg><use href="#svg-arrow-right"></use></svg></i></label><ul>
<li class="toctree-l2 has-children"><a class="reference internal" href="../guidelines/programming.html">Programming Guidelines</a><input class="toctree-checkbox" id="toctree-checkbox-4" name="toctree-checkbox-4" role="switch" type="checkbox"/><label for="toctree-checkbox-4"><div class="visually-hidden">Toggle child pages in navigation</div><i class="icon"><svg><use href="#svg-arrow-right"></use></svg></i></label><ul>
<li class="toctree-l3"><a class="reference internal" href="../guidelines/programming/coding-style.html">C Coding Style</a></li>
<li class="toctree-l3"><a class="reference internal" href="../guidelines/programming/memory-management.html">Managing Memory</a></li>
<li class="toctree-l3"><a class="reference internal" href="../guidelines/programming/writing-good-code.html">The Importance of Writing Good Code</a></li>
<li class="toctree-l3"><a class="reference internal" href="../guidelines/programming/optimizing.html">Optimizing GNOME Applications</a></li>
<li class="toctree-l3"><a class="reference internal" href="../guidelines/programming/namespacing.html">Namespacing</a></li>
<li class="toctree-l3"><a class="reference internal" href="../guidelines/programming/introspection.html">Introspection</a></li>
</ul>
</li>
<li class="toctree-l2 has-children"><a class="reference internal" href="../guidelines/accessibility.html">Accessibility</a><input class="toctree-checkbox" id="toctree-checkbox-5" name="toctree-checkbox-5" role="switch" type="checkbox"/><label for="toctree-checkbox-5"><div class="visually-hidden">Toggle child pages in navigation</div><i class="icon"><svg><use href="#svg-arrow-right"></use></svg></i></label><ul>
<li class="toctree-l3"><a class="reference internal" href="../guidelines/accessibility/coding-guidelines.html">Coding Guidelines for Supporting Accessibility</a></li>
<li class="toctree-l3"><a class="reference internal" href="../guidelines/accessibility/custom-widgets.html">Making Custom Components Accessible</a></li>
</ul>
</li>
<li class="toctree-l2 has-children"><a class="reference internal" href="../guidelines/localization.html">Localization</a><input class="toctree-checkbox" id="toctree-checkbox-6" name="toctree-checkbox-6" role="switch" type="checkbox"/><label for="toctree-checkbox-6"><div class="visually-hidden">Toggle child pages in navigation</div><i class="icon"><svg><use href="#svg-arrow-right"></use></svg></i></label><ul>
<li class="toctree-l3"><a class="reference internal" href="../guidelines/localization/practices.html">Best Practices for Localization</a></li>
</ul>
</li>
<li class="toctree-l2 has-children"><a class="reference internal" href="../guidelines/maintainer.html">Maintainer Guidelines</a><input class="toctree-checkbox" id="toctree-checkbox-7" name="toctree-checkbox-7" role="switch" type="checkbox"/><label for="toctree-checkbox-7"><div class="visually-hidden">Toggle child pages in navigation</div><i class="icon"><svg><use href="#svg-arrow-right"></use></svg></i></label><ul>
<li class="toctree-l3"><a class="reference internal" href="../guidelines/maintainer/api-stability.html">API Stability</a></li>
<li class="toctree-l3"><a class="reference internal" href="../guidelines/maintainer/parallel-installability.html">Parallel Installability</a></li>
<li class="toctree-l3"><a class="reference internal" href="../guidelines/maintainer/integrating.html">Integrating with GNOME</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="../guidelines/devel-docs.html">Developer Documentation Style Guidelines</a></li>
</ul>
</li>
<li class="toctree-l1 current has-children"><a class="reference internal" href="../tutorials.html">Tutorials</a><input checked="" class="toctree-checkbox" id="toctree-checkbox-8" name="toctree-checkbox-8" role="switch" type="checkbox"/><label for="toctree-checkbox-8"><div class="visually-hidden">Toggle child pages in navigation</div><i class="icon"><svg><use href="#svg-arrow-right"></use></svg></i></label><ul class="current">
<li class="toctree-l2 has-children"><a class="reference internal" href="beginners.html">Beginners Tutorials</a><input class="toctree-checkbox" id="toctree-checkbox-9" name="toctree-checkbox-9" role="switch" type="checkbox"/><label for="toctree-checkbox-9"><div class="visually-hidden">Toggle child pages in navigation</div><i class="icon"><svg><use href="#svg-arrow-right"></use></svg></i></label><ul>
<li class="toctree-l3 has-children"><a class="reference internal" href="beginners/getting_started.html">Getting Started</a><input class="toctree-checkbox" id="toctree-checkbox-10" name="toctree-checkbox-10" role="switch" type="checkbox"/><label for="toctree-checkbox-10"><div class="visually-hidden">Toggle child pages in navigation</div><i class="icon"><svg><use href="#svg-arrow-right"></use></svg></i></label><ul>
<li class="toctree-l4"><a class="reference internal" href="beginners/getting_started/content_view.html">Adding A Content View</a></li>
<li class="toctree-l4"><a class="reference internal" href="beginners/getting_started/opening_files.html">Loading Content From A File</a></li>
<li class="toctree-l4"><a class="reference internal" href="beginners/getting_started/cursor_position.html">Showing The Cursor Position</a></li>
<li class="toctree-l4"><a class="reference internal" href="beginners/getting_started/saving_files.html">Saving The Content To A File</a></li>
<li class="toctree-l4"><a class="reference internal" href="beginners/getting_started/saving_state.html">Saving The Application State</a></li>
<li class="toctree-l4"><a class="reference internal" href="beginners/getting_started/adding_toasts.html">Notifying The User With Toasts</a></li>
<li class="toctree-l4"><a class="reference internal" href="beginners/getting_started/dark_mode.html">Forcing The Dark Color Scheme</a></li>
</ul>
</li>
<li class="toctree-l3 has-children"><a class="reference internal" href="beginners/components.html">UI components</a><input class="toctree-checkbox" id="toctree-checkbox-11" name="toctree-checkbox-11" role="switch" type="checkbox"/><label for="toctree-checkbox-11"><div class="visually-hidden">Toggle child pages in navigation</div><i class="icon"><svg><use href="#svg-arrow-right"></use></svg></i></label><ul>
<li class="toctree-l4"><a class="reference internal" href="beginners/components/window.html">Windows</a></li>
<li class="toctree-l4"><a class="reference internal" href="beginners/components/image.html">Images</a></li>
<li class="toctree-l4"><a class="reference internal" href="beginners/components/label.html">Labels</a></li>
<li class="toctree-l4"><a class="reference internal" href="beginners/components/button.html">Buttons</a></li>
<li class="toctree-l4"><a class="reference internal" href="beginners/components/box.html">Boxes</a></li>
<li class="toctree-l4"><a class="reference internal" href="beginners/components/stack.html">Stacks</a></li>
<li class="toctree-l4"><a class="reference internal" href="beginners/components/leaflet.html">Leaflets</a></li>
<li class="toctree-l4"><a class="reference internal" href="beginners/components/toggle.html">Toggles</a></li>
<li class="toctree-l4"><a class="reference internal" href="beginners/components/check_box.html">Check Boxes</a></li>
<li class="toctree-l4"><a class="reference internal" href="beginners/components/radio_button.html">Radio Buttons</a></li>
<li class="toctree-l4"><a class="reference internal" href="beginners/components/spin_button.html">Spin Buttons</a></li>
<li class="toctree-l4"><a class="reference internal" href="beginners/components/link_button.html">Link Buttons</a></li>
<li class="toctree-l4"><a class="reference internal" href="beginners/components/switch.html">Switches</a></li>
<li class="toctree-l4"><a class="reference internal" href="beginners/components/menu_button.html">Menu Buttons</a></li>
<li class="toctree-l4"><a class="reference internal" href="beginners/components/entry.html">Entries</a></li>
<li class="toctree-l4"><a class="reference internal" href="beginners/components/password_entry.html">Password Entries</a></li>
<li class="toctree-l4"><a class="reference internal" href="beginners/components/message_dialog.html">Messages</a></li>
<li class="toctree-l4"><a class="reference internal" href="beginners/components/file_dialog.html">File Dialogs</a></li>
<li class="toctree-l4"><a class="reference internal" href="beginners/components/spinner.html">Spinners</a></li>
<li class="toctree-l4"><a class="reference internal" href="beginners/components/level_bar.html">Level Bars</a></li>
</ul>
</li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="application-id.html">Application ID</a></li>
<li class="toctree-l2"><a class="reference internal" href="application.html">Using GtkApplication</a></li>
<li class="toctree-l2"><a class="reference internal" href="save-state.html">Saving and Loading Window State</a></li>
<li class="toctree-l2"><a class="reference internal" href="notifications.html">Using Notifications</a></li>
<li class="toctree-l2"><a class="reference internal" href="themed-icons.html">Themed Icons</a></li>
<li class="toctree-l2 current current-page"><a class="current reference internal" href="#">Dealing With Deprecations</a></li>
<li class="toctree-l2"><a class="reference internal" href="actions.html">Actions</a></li>
<li class="toctree-l2"><a class="reference internal" href="menus.html">Menus</a></li>
<li class="toctree-l2"><a class="reference internal" href="search-provider.html">Writing a Search Provider</a></li>
<li class="toctree-l2"><a class="reference internal" href="pre-and-post-conditions.html">Pre- and Post-Conditions</a></li>
<li class="toctree-l2"><a class="reference internal" href="main-contexts.html">Main Contexts</a></li>
<li class="toctree-l2"><a class="reference internal" href="lists.html">Using GLib Lists</a></li>
<li class="toctree-l2"><a class="reference internal" href="threading.html">Threading</a></li>
<li class="toctree-l2"><a class="reference internal" href="asynchronous-programming.html">Asynchronous Programming</a></li>
<li class="toctree-l2"><a class="reference internal" href="drag-and-drop.html">Drag and Drop</a></li>
<li class="toctree-l2"><a class="reference internal" href="widget-templates.html">Widget Templates</a></li>
</ul>
</li>
</ul>
</div>
</div>
</div>
</div>
</aside>
<main class="main">
<div class="content">
<article role="main">
<label class="toc-overlay-icon toc-content-icon" for="__toc">
<i class="icon"><svg><use href="#svg-toc"></use></svg></i>
</label>
<section id="dealing-with-deprecations">
<h1>Dealing With Deprecations<a class="headerlink" href="#dealing-with-deprecations" title="Permalink to this headline">#</a></h1>
<p>Deprecations are commonly used to allow APIs to evolve over time, by phasing out
no-longer-fashionable API functions and replacing them with newer, cooler
replacements. This page explains how libraries in the GNOME stack do
deprecations, and what mechanisms they provide for an application
developer—you—to deal with them.</p>
<p>One important thing to keep in mind is that deprecated does not mean broken,
or unusable. There is no need to rush into replacing every deprecated function
by its replacement right away. The next major release of the library in question
(which is the point at which deprecated API may be dropped) may be years away.
Until that happens, it is perfectly fine to keep using the functions.</p>
<section id="basics">
<h2>Basics<a class="headerlink" href="#basics" title="Permalink to this headline">#</a></h2>
<p>How does one recognize that a function is deprecated? Since a few years, the
GNOME libraries annotates deprecations in their headers, like this:</p>
<div class="highlight-c notranslate"><div class="highlight"><pre><span></span><span class="n">GLIB_DEPRECATED_IN_2_26</span><span class="w"></span>
<span class="kt">void</span><span class="w"> </span><span class="n">g_completion_clear_items</span><span class="w"> </span><span class="p">(</span><span class="n">GCompletion</span><span class="o">*</span><span class="w"> </span><span class="n">cmp</span><span class="p">);</span><span class="w"></span>
<span class="n">GLIB_DEPRECATED_IN_2_40_FOR</span><span class="p">(</span><span class="n">g_settings_schema_key_get_range</span><span class="p">)</span><span class="w"></span>
<span class="n">GVariant</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="n">g_settings_get_range</span><span class="w"> </span><span class="p">(</span><span class="n">GSettings</span><span class="w"> </span><span class="o">*</span><span class="n">settings</span><span class="p">,</span><span class="w"></span>
<span class="w"> </span><span class="k">const</span><span class="w"> </span><span class="n">gchar</span><span class="w"> </span><span class="o">*</span><span class="n">key</span><span class="p">);</span><span class="w"></span>
<span class="n">GDK_DEPRECATED_IN_3_10</span><span class="w"></span>
<span class="kt">void</span><span class="w"> </span><span class="n">gtk_window_reshow_with_initial_size</span><span class="w"> </span><span class="p">(</span><span class="n">GtkWindow</span><span class="w"> </span><span class="o">*</span><span class="n">window</span><span class="p">);</span><span class="w"></span>
</pre></div>
</div>
<p>These annotations are defined as macros in the GLib headers, which expand to
function attributes that cause the C compiler to warn when these functions are
used.</p>
<p>In addition, the doc comments for deprecated functions contain a <code class="docutils literal notranslate"><span class="pre">Deprecated:</span></code>
tag:</p>
<div class="highlight-c notranslate"><div class="highlight"><pre><span></span><span class="cm">/**</span>
<span class="cm"> * g_completion_clear_items:</span>
<span class="cm"> * @cmp: the #GCompletion.</span>
<span class="cm"> *</span>
<span class="cm"> * Removes all items from the #GCompletion. The items are not freed, so if the</span>
<span class="cm"> * memory was dynamically allocated, it should be freed after calling this</span>
<span class="cm"> * function.</span>
<span class="cm"> *</span>
<span class="cm"> * Deprecated:2.26: Rarely used API</span>
<span class="cm"> */</span><span class="w"></span>
<span class="cm">/**</span>
<span class="cm"> * g_settings_get_range:</span>
<span class="cm"> * @settings: a #GSettings</span>
<span class="cm"> * @key: the key to query the range of</span>
<span class="cm"> *</span>
<span class="cm"> * Queries the range of a key.</span>
<span class="cm"> *</span>
<span class="cm"> * Since: 2.28</span>
<span class="cm"> *</span>
<span class="cm"> * Deprecated: 2.40: Use g_settings_schema_key_get_range() instead.</span>
<span class="cm"> */</span><span class="w"></span>
<span class="cm">/**</span>
<span class="cm"> * gtk_window_reshow_with_initial_size:</span>
<span class="cm"> * @window: a #GtkWindow</span>
<span class="cm"> *</span>
<span class="cm"> * Hides @window, then reshows it, resetting the</span>
<span class="cm"> * default size and position of the window. Used</span>
<span class="cm"> * by GUI builders only.</span>
<span class="cm"> *</span>
<span class="cm"> * Deprecated: 3.10: GUI builders can call gtk_widget_hide(),</span>
<span class="cm"> * gtk_widget_unrealize() and then gtk_widget_show() on @window</span>
<span class="cm"> * themselves, if they still need this functionality.</span>
<span class="cm"> */</span><span class="w"></span>
</pre></div>
</div>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>If you are a library maintainer: it is important that the Deprecated tag
contains not just the version in which the symbol was deprecated, but also
an explanation of how to replace the symbol with non-deprecated API, if
a replacement is possible.</p>
</div>
</section>
<section id="deprecation-warnings">
<h2>Deprecation warnings<a class="headerlink" href="#deprecation-warnings" title="Permalink to this headline">#</a></h2>
<p>Ultimatively, the <code class="docutils literal notranslate"><span class="pre">GDK_DEPRECATED_IN_3_10</span></code> macro expands to a compiler
attribute — like <code class="docutils literal notranslate"><span class="pre">__attribute__((__deprecated__))</span></code>, in GCC — which causes a
reasonably modern compiler to emit warnings when you compile your program; for
instance:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>$ make testheaderbar
CC testheaderbar.o
testheaderbar.c: In function main:
testheaderbar.c:192:3: warning: gtk_window_reshow_with_initial_size is deprecated (declared at ../gtk/gtkwindow.h:419) [-Wdeprecated-declarations]
gtk_window_reshow_with_initial_size (GTK_WINDOW (window));
^
CCLD testheaderbar
</pre></div>
</div>
<p>Note that this is just a warning: the program was still successfully built.</p>
<div class="admonition tip">
<p class="admonition-title">Tip</p>
<p>When you decide to port your code away from deprecated symbols, you can ask
the compiler to turn deprecation warnings into errors; for instance, with
GCC, you can add <code class="docutils literal notranslate"><span class="pre">-Werror=deprecated-declarations</span></code> to your compiler flags.</p>
</div>
</section>
<section id="ignoring-all-deprecation-warnings">
<h2>Ignoring all deprecation warnings<a class="headerlink" href="#ignoring-all-deprecation-warnings" title="Permalink to this headline">#</a></h2>
<p>If you want to ignore deprecation warnings you can either tell your compiler to
not emit warnings—for instance, with GCC, you can add <code class="docutils literal notranslate"><span class="pre">-Wno-deprecated-declarations</span></code>
to your compiler flags. Or you can disable deprecation warnings for the
libraries that youre using—for instance, by adding to your <code class="docutils literal notranslate"><span class="pre">meson.build</span></code> file:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">add_project_arguments</span><span class="p">([</span>
<span class="s1">&#39;-DGLIB_DISABLE_DEPRECATION_WARNINGS&#39;</span><span class="p">,</span>
<span class="s1">&#39;-DGTK_DISABLE_DEPRECATION_WARNINGS&#39;</span><span class="p">,</span>
<span class="p">],</span>
<span class="n">language</span><span class="p">:</span> <span class="s1">&#39;c&#39;</span><span class="p">,</span>
<span class="p">)</span>
</pre></div>
</div>
<p>Every library that provides deprecation annotations should also provide a way to
disable them.</p>
</section>
<section id="selectively-ignoring-deprecation-warnings">
<h2>Selectively ignoring deprecation warnings<a class="headerlink" href="#selectively-ignoring-deprecation-warnings" title="Permalink to this headline">#</a></h2>
<p>Sometimes it is impractical to avoid certain deprecated functions, even though
your code is otherwise deprecation-free. In this case, you probably dont want
to disable all deprecation warnings, and instead just selectively mark the code
sections in which the deprecated functions are used:</p>
<div class="highlight-c notranslate"><div class="highlight"><pre><span></span><span class="n">G_GNUC_BEGIN_IGNORE_DEPRECATIONS</span><span class="w"></span>
<span class="nf">gtk_window_reshow_with_initial_size</span><span class="w"> </span><span class="p">(</span><span class="n">window</span><span class="p">);</span><span class="w"></span>
<span class="n">G_GNUC_END_IGNORE_DEPRECATIONS</span><span class="w"></span>
</pre></div>
</div>
</section>
<section id="targeting-specific-library-versions">
<h2>Targeting specific library versions<a class="headerlink" href="#targeting-specific-library-versions" title="Permalink to this headline">#</a></h2>
<p>If your application was developed against a certain version of a library, say
GLib 2.56, and you want to ensure that it continues to work on systems with this
version of GLib, as well as newer versions, there are two things you need to
worry about.</p>
<p>Newer versions of GLib may deprecate API that you are using. There is no reason
for you to stop using it, since it was not deprecated in 2.56 (and the
replacements will probably not be available in 2.56), but you also want to build
your application with newer versions of GLib without warnings.</p>
<p>Even if your development system has a newer version of GLib, you want avoid
using GLib API that was introduced after 2.56, to keep your application working
on systems with GLib 2.56.</p>
<p>The deprecations and API additions in the GNOME stack are versioned, which lets
you achieve these goals by defining the range of versions of the APIs that your
application is expected to work with. This is done with a pair of macros, which
are typically defined in your <code class="docutils literal notranslate"><span class="pre">meson.build</span></code> file:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">add_project_arguments</span><span class="p">([</span>
<span class="s1">&#39;-DGLIB_VERSION_MIN_REQUIRED=GLIB_VERSION_2_56&#39;</span><span class="p">,</span>
<span class="s1">&#39;-DGLIB_VERSION_MAX_ALLOWED=GLIB_VERSION_2_56&#39;</span><span class="p">,</span>
<span class="p">],</span>
<span class="n">language</span><span class="p">:</span> <span class="s1">&#39;c&#39;</span><span class="p">,</span>
<span class="p">)</span>
</pre></div>
</div>
<p>Each library has their own macros. For GLib, they are
<code class="docutils literal notranslate"><span class="pre">GLIB_VERSION_MIN_REQUIRED</span></code> and <code class="docutils literal notranslate"><span class="pre">GLIB_VERSION_MAX_ALLOWED</span></code>. For GTK, they
are <code class="docutils literal notranslate"><span class="pre">GDK_VERSION_MIN_REQUIRED</span></code> and <code class="docutils literal notranslate"><span class="pre">GDK_VERSION_MAX_ALLOWED</span></code>.</p>
<p>The definition for these macros must encode the major and minor version in a
binary format. You can either use predefined values such as <code class="docutils literal notranslate"><span class="pre">GLIB_VERSION_2_56</span></code>,
<code class="docutils literal notranslate"><span class="pre">GDK_VERSION_3_10</span></code>, or use the <code class="docutils literal notranslate"><span class="pre">G_ENCODE_VERSION</span></code> macro like this:</p>
<div class="highlight-c notranslate"><div class="highlight"><pre><span></span><span class="cp">#define GLIB_VERSION_MIN_REQUIRED G_ENCODE_VERSION(2,56)</span>
</pre></div>
</div>
<div class="admonition important">
<p class="admonition-title">Important</p>
<p>Both the <code class="docutils literal notranslate"><span class="pre">MIN_REQUIRED</span></code> and <code class="docutils literal notranslate"><span class="pre">MAX_ALLOWED</span></code> macros must be defined
<strong>before</strong> including the header for the corresponding library.</p>
</div>
</section>
<section id="additional-references">
<h2>Additional references<a class="headerlink" href="#additional-references" title="Permalink to this headline">#</a></h2>
<ul class="simple">
<li><p><a class="reference external" href="https://docs.gtk.org/glib/compiling.html">Compiling GLib applications</a></p></li>
<li><p><a class="reference external" href="https://docs.gtk.org/gtk4/compiling.html">Compiling GTK applications</a></p></li>
</ul>
</section>
</section>
</article>
<footer>
<div class="related-pages">
<a class="next-page" href="actions.html">
<div class="page-info">
<div class="context">
<span>Next</span>
</div>
<div class="title">Actions</div>
</div>
<svg><use href="#svg-arrow-right"></use></svg>
</a>
<a class="prev-page" href="themed-icons.html">
<svg><use href="#svg-arrow-right"></use></svg>
<div class="page-info">
<div class="context">
<span>Previous</span>
</div>
<div class="title">Themed Icons</div>
</div>
</a>
</div>
</footer>
</div>
<aside class="toc-drawer">
<div class="toc-sticky toc-scroll">
<div class="toc-title-container">
<span class="toc-title">
Contents
</span>
</div>
<div class="toc-tree-container">
<div class="toc-tree">
<ul>
<li><a class="reference internal" href="#">Dealing With Deprecations</a><ul>
<li><a class="reference internal" href="#basics">Basics</a></li>
<li><a class="reference internal" href="#deprecation-warnings">Deprecation warnings</a></li>
<li><a class="reference internal" href="#ignoring-all-deprecation-warnings">Ignoring all deprecation warnings</a></li>
<li><a class="reference internal" href="#selectively-ignoring-deprecation-warnings">Selectively ignoring deprecation warnings</a></li>
<li><a class="reference internal" href="#targeting-specific-library-versions">Targeting specific library versions</a></li>
<li><a class="reference internal" href="#additional-references">Additional references</a></li>
</ul>
</li>
</ul>
</div>
</div>
</div>
</aside>
</main>
</div><script data-url_root="../" id="documentation_options" src="../_static/documentation_options.js"></script>
<script src="../_static/jquery.js"></script>
<script src="../_static/underscore.js"></script>
<script src="../_static/doctools.js"></script>
<script src="../_static/scripts/furo.js"></script>
</body>
</html>