errorhandling finished for now, as proposed
This commit is contained in:
parent
d2c13807bb
commit
d36a38a56e
7 changed files with 167 additions and 6 deletions
|
|
@ -18,6 +18,7 @@
|
|||
bin_PROGRAMS =
|
||||
lib_LTLIBRARIES =
|
||||
noinst_PROGRAMS =
|
||||
check_PROGRAMS =
|
||||
noinst_LIBRARIES =
|
||||
noinst_LTLIBRARIES =
|
||||
noinst_HEADERS =
|
||||
|
|
|
|||
|
|
@ -20,5 +20,5 @@ noinst_LIBRARIES += libcin3.a
|
|||
|
||||
libcin3_a_CFLAGS = $(CFLAGS) -std=gnu99 -Wall -Werror
|
||||
|
||||
libcin3_a_SOURCES = $(libcin3_a_srcdir)/plugin.c
|
||||
noinst_HEADERS += $(libcin3_a_srcdir)/plugin.h
|
||||
libcin3_a_SOURCES = $(libcin3_a_srcdir)/plugin.c $(libcin3_a_srcdir)/error.c
|
||||
noinst_HEADERS += $(libcin3_a_srcdir)/plugin.h $(libcin3_a_srcdir)/error.h
|
||||
|
|
|
|||
56
src/lib/error.c
Normal file
56
src/lib/error.c
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
/*
|
||||
error.c - Cinelerra Error handling
|
||||
|
||||
Copyright (C) CinelerraCV
|
||||
2007, Christian Thaeter <ct@pipapo.org>
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License as
|
||||
published by the Free Software Foundation; either version 2 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
#include <pthread.h>
|
||||
|
||||
/* Thread local storage */
|
||||
static pthread_key_t cinelerra_error_tls;
|
||||
static pthread_once_t cinelerra_error_initialized = PTHREAD_ONCE_INIT;
|
||||
|
||||
static void
|
||||
cinelerra_error_tls_init (void)
|
||||
{
|
||||
pthread_key_create (&cinelerra_error_tls, NULL);
|
||||
}
|
||||
|
||||
const char*
|
||||
cinelerra_error_set (const char * nerr)
|
||||
{
|
||||
pthread_once (&cinelerra_error_initialized, cinelerra_error_tls_init);
|
||||
|
||||
const char* err = pthread_getspecific (cinelerra_error_tls);
|
||||
if (!err)
|
||||
pthread_setspecific (cinelerra_error_tls, nerr);
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
|
||||
const char*
|
||||
cinelerra_error ()
|
||||
{
|
||||
pthread_once (&cinelerra_error_initialized, cinelerra_error_tls_init);
|
||||
|
||||
const char* err = pthread_getspecific (cinelerra_error_tls);
|
||||
if (err)
|
||||
pthread_setspecific (cinelerra_error_tls, NULL);
|
||||
return err;
|
||||
}
|
||||
|
|
@ -26,9 +26,17 @@
|
|||
|
||||
#define CINELERRA_DIE(message) do { NOBUG_ERROR(NOBUG_ON, message); abort(); } while(0)
|
||||
|
||||
#define CINELERRA_ERROR_DECLARE(err) extern const cinelerra_error err
|
||||
#define CINELERRA_ERROR_DEFINE(err, msg) const cinelerra_error err = #err ":" msg
|
||||
#define CINELERRA_ERROR_DECLARE(err) \
|
||||
extern const char* CINELERRA_ERROR_##err
|
||||
|
||||
#define CINELERRA_ERROR_DEFINE(err, msg) \
|
||||
const char* CINELERRA_ERROR_##err = "CINELERRA_ERROR_" #err ":" msg
|
||||
|
||||
const char*
|
||||
cinelerra_error_set (const char * err);
|
||||
|
||||
const char*
|
||||
cinelerra_error ();
|
||||
|
||||
typedef const char* cinelerra_error;
|
||||
|
||||
#endif /* CINELERRA_ERROR_H */
|
||||
|
|
|
|||
27
tests/10errorhandling.tests
Normal file
27
tests/10errorhandling.tests
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
|
||||
TESTING "Error handling" ./errortest
|
||||
|
||||
TEST "no error" <<END
|
||||
return: 0
|
||||
END
|
||||
|
||||
TEST "set error" set <<END
|
||||
return: 0
|
||||
END
|
||||
|
||||
TEST "query no error" get_no <<END
|
||||
out: (nil)
|
||||
return: 0
|
||||
END
|
||||
|
||||
TEST "query error" get <<END
|
||||
out: CINELERRA_ERROR_TEST:test error
|
||||
return: 0
|
||||
END
|
||||
|
||||
TEST "error cleared" get2 <<END
|
||||
out: CINELERRA_ERROR_TEST:test error
|
||||
out: (nil)
|
||||
return: 0
|
||||
END
|
||||
|
||||
|
|
@ -18,6 +18,10 @@
|
|||
|
||||
tests_srcdir = $(top_srcdir)/tests
|
||||
|
||||
noinst_PROGRAMS +=
|
||||
check_PROGRAMS += errortest
|
||||
|
||||
errortest_SOURCES = $(tests_srcdir)/errortest.c
|
||||
errortest_CPPFLAGS = $(AM_CPPFLAGS) -std=gnu99 -Wall -Werror -I$(top_srcdir)/src/lib/
|
||||
errortest_LDADD = $(builddir)/libcin3.a -lnobugmt -lpthread -ldl
|
||||
|
||||
TESTS = $(tests_srcdir)/test.sh
|
||||
|
|
|
|||
65
tests/errortest.c
Normal file
65
tests/errortest.c
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
/*
|
||||
errortest.c - test error handling
|
||||
|
||||
Copyright (C) CinelerraCV
|
||||
2007, Christian Thaeter <ct@pipapo.org>
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License as
|
||||
published by the Free Software Foundation; either version 2 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
#include <error.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
CINELERRA_ERROR_DEFINE(TEST, "test error");
|
||||
|
||||
int
|
||||
main (int argc, char** argv)
|
||||
{
|
||||
if (argc == 1)
|
||||
return 0;
|
||||
|
||||
if (!strcmp(argv[1], "set"))
|
||||
{
|
||||
cinelerra_error_set (CINELERRA_ERROR_TEST);
|
||||
}
|
||||
|
||||
if (!strcmp(argv[1], "get_no"))
|
||||
{
|
||||
const char* err;
|
||||
err = cinelerra_error ();
|
||||
printf ("%p\n", err);
|
||||
}
|
||||
|
||||
if (!strcmp(argv[1], "get"))
|
||||
{
|
||||
cinelerra_error_set (CINELERRA_ERROR_TEST);
|
||||
const char* err;
|
||||
err = cinelerra_error ();
|
||||
printf ("%s\n", err);
|
||||
}
|
||||
|
||||
if (!strcmp(argv[1], "get2"))
|
||||
{
|
||||
cinelerra_error_set (CINELERRA_ERROR_TEST);
|
||||
const char* err;
|
||||
err = cinelerra_error ();
|
||||
printf ("%s\n", err);
|
||||
err = cinelerra_error ();
|
||||
printf ("%p\n", err);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
Loading…
Reference in a new issue