Misplaced Pages

GObject

Article snapshot taken from Wikipedia with creative commons attribution-sharealike license. Give it a read and then ask your questions in the chat. We can research this topic together.

The GLib Object System , or GObject , is a free software library providing a portable object system and transparent cross-language interoperability. GObject is designed for use both directly in C programs to provide object-oriented C-based APIs and through bindings to other languages to provide transparent cross-language interoperability, e.g. PyGObject .

#639360

34-455: Depending only on GLib and libc , GObject is a cornerstone of GNOME and is used throughout GTK , Pango , ATK , and most higher-level GNOME libraries like GStreamer and applications. Prior to GTK+ 2.0, code similar to GObject was part of the GTK codebase. (The name “GObject” was not yet in use — the common baseclass was called GtkObject .) At the release of GTK+ 2.0, the object system

68-510: A shared library that provides a GObject class—usually some kind of widget , in the case of Glade—and then obtain a list of all properties of the class, complete with type information and documentation strings. Since GObject provides a mostly complete object system for C, it can be seen as an alternative to C-derived languages such as C++ and Objective-C . (Though both also offer many other features beyond just their respective object systems.) An easily observed difference between C++ and GObject

102-493: A class in the GObject framework is complex, requiring large amounts of boilerplate code, such as manual definitions of type casting macros and obscure type registration incantations. Also, since a C structure cannot have access modifiers like “public”, “protected”, or “private”, workarounds must be used to provide encapsulation . One approach is to include a pointer to the private data — conventionally called _priv — in

136-591: A language that is designed primarily to work with GObject and which converts to C, is likely to make working with GObject or writing GObject based libraries nicer. Although they are not really first-class objects (there are no actual metatypes in GType), metaobjects like classes and interfaces are created by GObject applications at runtime, and provide good support for introspection . The introspective capabilities are used by language bindings and user interface design applications like Glade to allow doing things like loading

170-452: A library and as such does not introduce any new syntax or compiler intelligence. For example, when writing GObject-based C code, it is frequently necessary to perform explicit upcasting . Hence, “C with GObject”, also called "glib-flavored C", considered as a language separate from plain C, is a strict superset of plain C — like Objective C, but unlike C++. On platforms where there is no standard ABI that works across all C++ compilers (which

204-411: A runtime description of all objects allowing glue code to facilitate multiple language bindings. The type system can handle any singly inherited class structure, in addition to non-classed types such as opaque pointers , strings , and variously sized integers and floating point numbers . The type system knows how to copy, assign, and destroy values belonging to any of the registered types. This

238-485: A separate software bundle. GLib was released as a separate library so other developers, those not using the GUI-related parts of GTK+, could use the non-GUI parts of the library without the overhead of depending on the full GUI library. Since GLib is a cross-platform library, applications using it to interface with the operating system are usually portable across different operating systems without major changes. Glib

272-799: A string and a unique integer identifier), keyed data lists, relations, and tuples . Caches provide memory management. GLib implements functions that provide threads , thread programming and related facilities such as primitive variable access, mutexes , asynchronous queues , secure memory pools , message passing and logging, hook functions (callback registering) and timers . GLib also includes message passing facilities such as byte order conversion and I/O channels. Some other features of GLib include: The GLib package consisted of five libraries, but they were all merged into one library, since then named simply GLib , and are no longer sustained as standalone libraries. The original libraries were: Of these, three continue to reside in distinct subdirectories of

306-401: Is a contract between two parties, where the terms and conditions of the contract are set by one of the parties, and the other party has little or no ability to negotiate more favorable terms and is thus placed in a "take it or leave it" position. Boilerplate language may also exist in pre-created form letters . The person sending the form letter then usually only needs to add his or her name at

340-613: Is not usually the case, since either the Itanium ABI or the Microsoft ABI are usually followed), a library compiled with one C++ compiler is not always able to call a library compiled with a different one. If such compatibility is required, the C++ methods must be exported as plain C functions, partly defeating the purpose of the C++ object system. The problem occurs in part because different C++ compilers use different kinds of name mangling to ensure

374-640: Is particularly salient when the programmer must include a lot of code for minimal functionality. A related phenomenon, bookkeeping code, is code that is not part of the business logic, but is interleaved with it to keep data structures updated or able to handle secondary aspects of the program. A boilerplate statement or response generally refers to a message used with minimal effort for multiple different situations. Examples include official statements from government officials such as " Our thoughts and prayers are with those affected " or messages left by companies' voicemail such as "Thank you for holding . Your call

SECTION 10

#1732858927640

408-477: Is that GObject (like Java) does not support multiple inheritance . GObject's use of GLib 's g_malloc() memory allocation function will cause the program to exit unconditionally upon memory exhaustion, unlike the C library's malloc (), C++'s new , and other common memory allocators which allow a program to cope with or even fully recover from out-of-memory situations without simply crashing. This tends to work against including GObject in software where resilience in

442-418: Is trivial for types like integers, but many complex objects are reference-counted , while some are complex but not reference-counted. When the type system “copies” a reference-counted object, it will typically just increase its reference count, whereas when copying a complex, non-reference-counted object (such as a string), it will typically create an actual copy by allocating memory . This basic functionality

476-479: Is undergoing active development. For a current overview see https://gitlab.gnome.org/GNOME/glib/-/blob/main/NEWS . The table below documents major patch notes from 1998 to 2022. Other libraries provide low-level functions and implementations of data structures, including: Boilerplate (text)#Boilerplate code Boilerplate text , or simply boilerplate , is any written text ( copy ) that can be reused in new contexts or applications without significant changes to

510-486: Is used for implementing GValue , a type of generic container that can hold values of any type known by the type system. Such containers are particularly useful when interacting with dynamically typed language environments in which all native values reside in such type-tagged containers. Types that do not have any associated classes are called non-classed . These types, together with all types that correspond to some form of root class , are known as fundamental types :

544-612: Is used in many successful free software projects, such as the GNOME desktop, the GTK toolkit and the GIMP image manipulation program. Though many GObject applications are written entirely in C, the GObject system maps well into the native object systems of many other languages, like C++ , Java , Ruby , Python , Common Lisp , and .NET / Mono . As a result, it is usually relatively painless to create language bindings for well-written libraries that use

578-550: Is usually compiled into its own shared library file, the source code for GObject resides in the GLib source tree and is distributed along with GLib. For this reason, GObject uses the GLib version numbers and is typically packaged together with GLib (for example, Debian puts GObject in its libglib2.0 package family). At the most basic level of the GObject framework lies a generic and dynamic type system called GType. The GType system holds

612-448: Is willing to use the incantation G_TYPE_INSTANCE_GET_PRIVATE every time the private data is needed. To address some of these complexities, several higher-level languages exist that source-to-source compiles to GObject in C. The Vala programming language uses a C# -style syntax and is pre-processed into vanilla C code. The GObject Builder, or GOB2 , offers a template syntax reminiscent of Java . The combination of C and GObject

646-448: The GObject framework. Writing GObject code in C in the first place, however, is relatively verbose. The library takes a good deal of time to learn, and programmers with experience in high-level object-oriented languages often find it somewhat tedious to work with GObject in C. For example, creating a subclass (even just a subclass of GObject ) can require writing and/or copying large amounts of boilerplate code . However, using Vala ,

680-455: The end of the pre-written greeting and body. Typically, the sender of such a letter needs to personalize it minimally, often by just adding their name or specific details to a pre-written greeting and body, making these templates highly practical for mass communication or repetitive correspondence. In computer programming, boilerplate is the sections of code that have to be included in many places with little or no alteration. Such boilerplate code

714-401: The face of limited memory is important, or where very many or very large objects are commonly handled. The g_try_new() can be used when a memory allocation is more likely to fail (for a large object for example), but this cannot grant that the allocation will not fail elsewhere in the code. Another important difference is that while C++ and Objective-C are separate languages, GObject is strictly

SECTION 20

#1732858927640

748-402: The global uniqueness of their exported names. Hence, despite being object-oriented, a GObject-based library written in C will always use the same external symbol names regardless of which compiler is used. Perhaps the most profound difference is GObject's emphasis on signals (called events in other languages). This emphasis derives from the fact that GObject was specifically designed to meet

782-411: The instance structure. The private structure can be declared in the public header file, but defined only in the implementation file, with the effect that the private data is opaque to users, but transparent to the implementor. If the private structure is registered with GType, it will be automatically allocated by the object system. Indeed, it is not even necessary to include the _priv pointer, if one

816-432: The needs of a GUI toolkit. Whilst there are signal libraries for most object-oriented languages out there, in the case of GObject it is built into the object system. Because of this, a typical GObject application will tend to use signals to a much larger extent than a non-GObject application would, making GObject components much more encapsulated and reusable than the ones using plain C++ or Java. If using glibmm / gtkmm ,

850-462: The official C++ wrappers to Glib/GTK respectively, the sibling project libsigc++ allows easy use of underlying GObject signals using standard C++. Of course, other implementations of signals are available on almost all platforms, although sometimes an extra library is needed, such as Boost.Signals2 for C++. GLib GLib is a bundle of three (formerly five) low-level system libraries written in C and developed mainly by GNOME . GLib's code

884-554: The original. The term is used about statements, contracts, and source code , and is often used in the media pejoratively to refer to clichéd or unoriginal writing. "Boiler plate" originally referred to the rolled steel used to make boilers to heat water. Metal printing plates ( type metal ) used in hot metal typesetting of prepared text such as advertisements or syndicated columns were distributed to small, local newspapers , and became known as 'boilerplates' by analogy. One large supplier to newspapers of this kind of boilerplate

918-425: The other hand, most classed types are instantiable, but some, such as interface types, are not. The types that are derived from the built-in GObject fundamental types fall roughly into four categories: The GObject messaging system consists of two complementary parts: closures and signals . Each GObject class is implemented by at least two structures: the class structure and the instance structure . Defining

952-499: The source tree, and so can be thought of as discrete components: GLib, GObject, and GIO. These can be thought of as a software stack: GObject relies on GLib, and GIO provides higher-level functionality that uses both. GLib began as part of the GTK+ project, now named GTK. However, before releasing GTK+ version 2, the project's developers decided to separate code from GTK+ that was not for graphical user interfaces (GUIs), thus creating GLib as

986-399: The type system are called instantiable . An important characteristic of these types is that the first bytes of any instance always contain a pointer to the class structure (a form of virtual table ) associated to the type of the instance. For this reason, any instantiable type must be classed. Contrapositively, any non-classed type (such as integer or string ) must be non-instantiable. On

1020-543: The types from which all other types are derived. These make up a relatively closed set, but although the average user is not expected to create their own fundamental types, the possibility does exist and has been exploited to create custom class hierarchies — i.e., class hierarchies not based on the GObject class. As of GLib 2.9.2, the non-classed built-in fundamental types are: The classed built-in fundamental types are: Types that can be instantiated automatically by

1054-472: The uniqueness of all exported symbols. (This is necessary because, for example, two different classes may have identically named member functions, one function name may be overloaded multiple times, or identically named functions may appear in different namespaces , but in object code these overlaps are not allowed.) In contrast, since C does not support any form of overloading or namespacing, authors of C libraries will typically use explicit prefixes to ensure

GObject - Misplaced Pages Continue

1088-505: Was extracted into a separate library due to its general utility. In the process, most non- GUI -specific parts of the GtkObject class were moved up into GObject , the new common baseclass. Having existed as a separate library since March 11, 2002 (the release date of GTK+ 2.0), the GObject library is now used by many non-GUI programs such as command-line and server applications. Though GObject has its own separate set of documentation and

1122-510: Was separated from GTK , so it can be used by software other than GNOME and has been developed in parallel ever since. The name "GLib" originates from the project's start as a GTK C utility library. GLib provides advanced data structures, such as memory chunks, doubly and singly linked lists , hash tables , dynamic strings and string utilities, such as a lexical scanner, string chunks (groups of strings), dynamic arrays , balanced binary trees , N-ary trees , quarks (a two-way association of

1156-506: Was the Western Newspaper Union, which supplied "ready-to-print stories" that "contained national or international news" to papers with smaller geographic footprints, which could include advertisements pre-printed next to the conventional content. In contract law, the term "boilerplate language" or " boilerplate clause " describes the parts of a contract that are considered standard. A standard form contract or boilerplate contract

#639360