I spent my lunch hacking a dirty remote shell in python.
signal.signal(signal.SIGCHLD, reaper) # ... while True: client, who = server.accept()
Blam ! When the server process receives SIGCHLD, accept() is interrupted. So I added a try/except around the accept() :
while True: try: client, who = server.accept() except OSError, e: if e.errno != errno.EINTR: sys.exit(e) else: continue
Re-blam. I didn't paid attention to the previous exception's type. It was socket.error. I though it was a subclass of OSError ... it's not. issubclass(socket.error, OSError) == False. pydoc socket :/
The correct except statement is :
while True: try: client, who = server.accept() except socket.error, e: if e.args[0] != errno.EINTR: sys.exit(e) else: continue
The socket.* error classes are just Exception. It would be nice to turn them into OSError :)
Wow, Drivel 2.0 is amazing :)
When you define your own GObject class, you have to define 2 casts macro (instance cast and class cast). So you write :
#define MY_TYPE (My_Type_get_type())
#define MY_TYPE(inst) (G_TYPE_CHECK_INSTANCE_CAST((inst), MY_TYPE, My_Type))
e.g :
#define GTK_TYPE_LABEL (gtk_label_get_type ())
#define GTK_LABEL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_LABEL, GtkLabel))
Now have a look at My_Type_get_type() declaration and definition. My_Type_get_type() always return the same GType. So if you write multiple cast, only one call to My_Type_get_type() is really necessary. But gcc is a good servant and does what you ask him : calls My_Type_get_type() whenever you call it. Think about this kind of loop :
for( ... ) {
GtkWidget* widget= ...;
gtk_box_pack_start(GTK_BOX(hbox), widget, ...);
}
To avoid such a waste, you have to tell gcc that all calls to My_Type_get_type() return the same GType.
GType My_Type_get_type (void) G_GNUC_CONST;
e.g:
GType gtk_label_get_type (void) G_GNUC_CONST;
Yes, it's that simple. Just add a G_GNUC_CONST attribute, and gcc will optimize all your to My_Type_get_type(), therefore all your MY_TYPE(inst).
Be smart, don't forget G_GNUC_CONST when you create your GObject class :)
Of course, glib and gtk+ already do this kind of optimization.
#include <stdbool.h> #include <stdio.h>#include <glib.h>
int main() { float f; gboolean gb; bool b;
f = 0.5f; gb = f; b = f;
printf("gboolean %d\n" "bool %d\n", (int)gb, (int)b);
return 0; }
Ouput :
gboolean 0 bool 1
0.5f is converted to int 0. But 0.5f is obsviously not zero and therefore should be evaluated as TRUE. So be carefull with gboolean.
NB: <stdbool.h>, bool, true and false are C99.
char buf[magic]; /* enough to hold "plop" */are still 0k. I'll try to be less lazy and always code :
char buf[sizeof "plop"];
U+00EE LATIN SMALL LETTER I WITH CIRCUMFLEX UTF-8 : 0xC3 0xAEIn French, circumflexes '^' on vowels often replace old French 's' :
I'll soon make a control-based desklets on it.
I'd like to get the C backend used by GNOME battstat applet (supports only ACPI/APM, but i steel haven't been able to contact its maintainer. I think I'll have to provide a full patch to get a chance to get PMU support in ...
LibGTop
I'm working hard on libgtop. Fixed a nasty bug on Linux/Sparc64.
I've been granted access to 5 Solaris (sparcs) machines in a German University, and started to fix Solaris support. I still haven't decided if this will go 2.8.1 or 2.9.0 ...
New HTML Parser: The long-awaited libxml2 based HTML parser code is live. It needs further work but already handles most markup better than the original parser.
Keep up with the latest Advogato features by reading the Advogato status blog.
If you're a C programmer with some spare time, take a look at the mod_virgule project page and help us with one of the tasks on the ToDo list!