toshiocp / gobject-tutorial Goto Github PK
View Code? Open in Web Editor NEWA tutorial about GObject for beginners
Home Page: https://toshiocp.github.io/Gobject-tutorial/
A tutorial about GObject for beginners
Home Page: https://toshiocp.github.io/Gobject-tutorial/
Hello! First and foremost thanks for the tutorial you've made, it's helping me to understand how to use the GObject library (and how it works).
I tried running the second example in section 2 locally, and ran into an SIGSEGV (Address boundary error).
#include <glib-object.h>
static void
show_ref_count (GObject *instance) {
if (G_IS_OBJECT (instance))
/* Users should not use ref_count member in their program. */
/* This is only for demonstration. */
g_print ("Reference count is %d.\n", instance->ref_count);
else
g_print ("Instance is not GObject.\n");
}
int
main (int argc, char **argv) {
GObject *instance;
instance = g_object_new (G_TYPE_OBJECT, NULL);
g_print ("Call g_object_new.\n");
show_ref_count (instance);
g_object_ref (instance);
g_print ("Call g_object_ref.\n");
show_ref_count (instance);
g_object_unref (instance);
g_print ("Call g_object_unref.\n");
show_ref_count (instance);
g_object_unref (instance);
g_print ("Call g_object_unref.\n");
show_ref_count (instance);
return 0;
}
I've used gdb
and the problem is at the last line show_ref_count (instance)
after the instance has been freed. It doesn't even get into the function show_ref_count
nor the G_IS_OBJECT
call, it fails before at g_type_check_instance_is_fundamentally_a
which I would guess happens when the instance pointer is copied into a function? ๐ค I'm not sure how that happens.
I don't know either if it's any problem with my local environment. In your page you mention that there are examples in the misc
folder, but I couldn't find those here.
I'm using an Arch Linux and compiling via gcc
with the following command:
gcc -g example.c -o example $(pkg-config --cflags --libs gobject-2.0)
If it is the case that my environment is correct and this error is reproducible, how does one check that an GObject *
instance is null without calling any function using it? ๐ค
https://github.com/ToshioCP/Gobject-tutorial/blob/main/gfm/sec6.md?plain=1#L39
When an instance is TNumber type, it is an instance of TInt or TDouble as well.
should be
When an instance is of TInt or TDouble type, it is an instance of TNumber as well.
btw. I appreciate your work! IMHO, It's way better organized than gobject's official guide.
https://github.com/ToshioCP/Gobject-tutorial/blob/main/gfm/sec4.md?plain=1#L104
https://github.com/ToshioCP/Gobject-tutorial/blob/main/gfm/sec4.md?plain=1#L110
void dev_by_zero_cb (TDouble *d, gpointer user_data) { ... ... ...};
and
void dev_by_zero_cb (TDouble *d) { ... ... ...};
should be
void div_by_zero_cb (TDouble *d, gpointer user_data) { ... ... ...};
and
void div_by_zero_cb (TDouble *d) { ... ... ...};
The documentation seems to only talk about how to use GObject and not what it is used for. It is a simple thing that demands research from casual readers trying to find footing. Two sentences should be sufficient.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.