Current addictions

english — Tags: , — @ 23:11
  1. Software development
  2. Survival Horror games, Playstation-based
  3. Online buying (including auctions!)

Tomorrow is Cecy’s birthday, a very good friend of mine, and yes I’ll there.

What’s new?

english — Tags: , , — @ 22:38

I’m finishing the porting from QNX to Linux, have been doing lot of testing and fixing several bugs, in other words have being busy. By the way, always know Bugzilla is good but it really rocks!

In the meanwhile, am starting to read Design Patterns in C# by Steven John Metsker, it’s an interesting book, based on the book written by Gamma et al, focused in the .NET framework, contains UML diagrams, nice book really.

And yes I upgraded to Ubuntu Edgy and haven’t had any problem yet, better default GTK+ theme, no more brown colors.

Ubuntu Edgy

english — Tags: , — @ 23:16

I’ve recently updated my Ubuntu desktop, after downloading at least 500MB I’m running it, and yes, works pretty nice.

Ubuntu Edgy. GNOME 2.15.92

In my opinion its visual best, better visual.

Exceptions

english — Tags: , — @ 22:37

Since C++ includes exceptions improves applications’ lifetime while running, “catching” known errors always helps, but what about the pretty older (but nicer) C?? The following simulates Java’s try-catch-finally. It’s based on the code written by Francisco A. Márquez, on his book.

File exception.h

#ifndef __EXCEPTION_H__
#define __EXCEPTION_H__
#include [signal .h] //Replace with "lower-than" "greather-than"
#include [setjmp .h]

typedef int exception_t;

extern exception_t
ARITHMETIC, /* SIGFPE */
HANGUP, /* SIGHUP */
ILLEGAL_INSTRUCTION, /* SIGILL */
SEGMENT_VIOLATION, /* SIGSEGV */
TERMINATION, /* SIGTERM */
UNKNOWN;

extern jmp_buf __jmpbuf;

/*
* try {
* insert-code-here
* } catch (Exception) {
* deal-with-the-exception
* } finally {
* do-something
* }
* */
#define try {exception_t current_exception;\
sigset_t oset;\
struct sigaction oact;\
void exception_lock_signal (sigset_t *oset, struct sigaction *oact);\
void exception_unlock_signal (sigset_t *oset, struct sigaction *oact);\
exception_lock_signal (&oset, &oact);\
if ((current_exception = (exception_t) setjmp (__jmpbuf)) == 0)
#define catch(exception) else if (current_exception == (int) &exception)
#define finally exception_unlock_signal (&oset, &oact);}
#define throw(exception) longjmp (__jmpbuf, (int) &exception);

#endif

File exception.c

#include [errno .h] //Replace with "lower-than" "greather-than"
#include [stdio .h]
#include "exception.h"

exception_t
ARITHMETIC,
HANGUP,
ILLEGAL_INSTRUCTION,
SEGMENT_VIOLATION,
TERMINATION,
UNKNOWN;

jmp_buf __jmpbuf;

void exception_error (int err, char *str)
{
printf ("EXCEPTION ERROR: (%i) %s\n", err, str);
}

void exception_manager (int signal)
{
switch (signal) {
case SIGFPE:
throw (ARITHMETIC);
break;
case SIGHUP:
throw (HANGUP);
break;
case SIGILL:
throw (ILLEGAL_INSTRUCTION);
break;
case SIGSEGV:
throw (SEGMENT_VIOLATION);
break;
case SIGTERM:
throw (TERMINATION);
break;
default:
throw (UNKNOWN);
}
}

void exception_lock_signal (sigset_t *oset, struct sigaction *oact)
{
int error = 0;
sigset_t set;
struct sigaction act;

sigemptyset (&set);
sigaddset (&set, SIGFPE);
sigaddset (&set, SIGHUP);
sigaddset (&set, SIGILL);
sigaddset (&set, SIGSEGV);
sigaddset (&set, SIGTERM);
if ((error = sigprocmask (SIG_UNBLOCK, &set, oset)) == -1)
exception_error (errno, "sigprocmask");
act.sa_handler = exception_manager;
sigfillset (&act.sa_mask);
act.sa_flags = SA_RESETHAND;
if ((error = sigaction (SIGFPE, &act, oact)) == -1)
exception_error (errno, "sigaction SIGFPE");
if ((error = sigaction (SIGHUP, &act, oact)) == -1)
exception_error (errno, "sigaction SIGHUP");
if ((error = sigaction (SIGILL, &act, oact)) == -1)
exception_error (errno, "sigaction SIGILL");
if ((error = sigaction (SIGSEGV, &act, oact)) == -1)
exception_error (errno, "sigaction SIGSEGV");
if ((error = sigaction (SIGTERM, &act, oact)) == -1)
exception_error (errno, "sigaction SIGTERM");
}

void exception_unlock_signal (sigset_t *oset, struct sigaction *oact)
{
int error = 0;

if ((error = sigprocmask (SIG_SETMASK, oset, NULL)) == -1)
exception_error (error, "sigprockmask SIG_SETMASK");
if ((error = sigaction (SIGFPE, oact, NULL)) == -1)
exception_error (error, "sigaction SIGFPE");
if ((error = sigaction (SIGHUP, oact, NULL)) == -1)
exception_error (error, "sigaction SIGHUP");
if ((error = sigaction (SIGILL, oact, NULL)) == -1)
exception_error (error, "sigaction SIGILL");
if ((error = sigaction (SIGSEGV, oact, NULL)) == -1)
exception_error (error, "sigaction SIGSEGV");
if ((error = sigaction (SIGTERM, oact, NULL)) == -1)
exception_error (error, "sigaction SIGTERM");

}

And yes… there is also the example code:

#include [stdio .h] //Replace with "lower-than" "greather-than"
#include "exception.h"

int main ()
{
exception_t Error_de_Lectura;
int x;
try {
printf ("Protected scope. BEGIN\n");
strcpy (NULL, "Nice!");
printf ("Protected scope. END\n");
} catch (Error_de_Lectura) {
printf ("Reading error\n");
} catch (ARITHMETIC) {
printf ("Arithmetic error\n");
throw (Error_de_Lectura);
} catch (ILLEGAL_INSTRUCTION) {
printf ("Instruccion ilegal");
} catch (SEGMENT_VIOLATION) {
printf ("Segmentation fault!.\n");
x = 0 /0;
} finally {
printf ("Finally reached\n");
}
return 0;
}

Awesome, isn’t it?.

Recently

english — Tags: , — @ 21:26

I’ve recently doing several things, first, at work, I’ve finally ported most of the SCADA from QNX to Linux by replacing all the Resource Managers to Ring Buffer, wrote an implementation based on the producer-consumer problem, an implementation to an already solved problem.

Then, in the Free Software world, I’ll travel to Puerto Vallarta, because of FSL2006, went past year and will do travel again (hope so, due to work), this time to show how to develop mono-based applications. I haven’t had enough time to prepare all the material, including the manual and so on but I’ve allready have the presentation only need to update it.

Oh man… I have a lot to do…!!

This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License.
(c) 2004-2010 Mario Carrion | powered by WordPress with Barecity