Merge branch 'master' into bindings/python
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Fri, 5 Jul 2013 23:26:57 +0000 (19:26 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Fri, 5 Jul 2013 23:26:57 +0000 (19:26 -0400)
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
108 files changed:
.gitignore
ChangeLog
bootstrap
configure.ac
converter/Makefile.am
converter/babeltrace-log.c
converter/babeltrace.c
doc/babeltrace.1
formats/Makefile.am
formats/bt-dummy/bt-dummy.c
formats/ctf-metadata/Makefile.am [new file with mode: 0644]
formats/ctf-metadata/ctf-metadata.c [new file with mode: 0644]
formats/ctf-text/Makefile.am
formats/ctf-text/ctf-text.c
formats/ctf-text/types/array.c
formats/ctf-text/types/enum.c
formats/ctf-text/types/float.c
formats/ctf-text/types/integer.c
formats/ctf-text/types/sequence.c
formats/ctf-text/types/string.c
formats/ctf-text/types/struct.c
formats/ctf-text/types/variant.c
formats/ctf/Makefile.am
formats/ctf/callbacks.c
formats/ctf/ctf.c
formats/ctf/events-private.h
formats/ctf/events.c
formats/ctf/iterator.c
formats/ctf/memstream.h [deleted file]
formats/ctf/metadata/Makefile.am
formats/ctf/metadata/ctf-ast.h
formats/ctf/metadata/ctf-lexer.l
formats/ctf/metadata/ctf-parser.y
formats/ctf/metadata/ctf-scanner-symbols.h [new file with mode: 0644]
formats/ctf/metadata/ctf-scanner.h
formats/ctf/metadata/ctf-visitor-generate-io-struct.c
formats/ctf/metadata/ctf-visitor-parent-links.c
formats/ctf/metadata/ctf-visitor-xml.c
formats/ctf/metadata/objstack.c [new file with mode: 0644]
formats/ctf/metadata/objstack.h [new file with mode: 0644]
formats/ctf/types/array.c
formats/ctf/types/enum.c
formats/ctf/types/float.c
formats/ctf/types/integer.c
formats/ctf/types/sequence.c
formats/ctf/types/string.c
formats/ctf/types/struct.c
formats/ctf/types/variant.c
include/Makefile.am
include/babeltrace/babeltrace-internal.h
include/babeltrace/compat/memstream.h [new file with mode: 0644]
include/babeltrace/compat/utc.h [new file with mode: 0644]
include/babeltrace/compat/uuid.h [new file with mode: 0644]
include/babeltrace/context.h
include/babeltrace/ctf-ir/metadata.h
include/babeltrace/ctf-text/types.h
include/babeltrace/ctf/callbacks-internal.h
include/babeltrace/ctf/callbacks.h
include/babeltrace/ctf/events-internal.h
include/babeltrace/ctf/events.h
include/babeltrace/ctf/types.h
include/babeltrace/format-internal.h [new file with mode: 0644]
include/babeltrace/format.h
include/babeltrace/prio_heap.h
include/babeltrace/trace-collection.h
include/babeltrace/trace-handle-internal.h
include/babeltrace/types.h
include/babeltrace/uuid.h [deleted file]
lib/context.c
lib/iterator.c
lib/prio_heap/prio_heap.c
lib/registry.c
lib/trace-collection.c
lib/trace-handle.c
tests/Makefile.am
tests/ctf-traces/fail/fail2/metadata [new file with mode: 0644]
tests/ctf-traces/fail/integer-range/metadata [new file with mode: 0644]
tests/ctf-traces/fail/lttng-modules-2.0-pre1/channel0_0 [deleted file]
tests/ctf-traces/fail/lttng-modules-2.0-pre1/channel0_1 [deleted file]
tests/ctf-traces/fail/lttng-modules-2.0-pre1/channel0_2 [deleted file]
tests/ctf-traces/fail/lttng-modules-2.0-pre1/channel0_3 [deleted file]
tests/ctf-traces/fail/lttng-modules-2.0-pre1/channel0_4 [deleted file]
tests/ctf-traces/fail/lttng-modules-2.0-pre1/channel0_5 [deleted file]
tests/ctf-traces/fail/lttng-modules-2.0-pre1/channel0_6 [deleted file]
tests/ctf-traces/fail/lttng-modules-2.0-pre1/channel0_7 [deleted file]
tests/ctf-traces/fail/packet-based-metadata/datastream [deleted file]
tests/ctf-traces/fail/smalltrace/dummystream-fail [new file with mode: 0644]
tests/ctf-traces/fail/smalltrace/metadata [new file with mode: 0644]
tests/ctf-traces/succeed/smalltrace/dummystream [new file with mode: 0644]
tests/ctf-traces/succeed/smalltrace/metadata [new file with mode: 0644]
tests/ctf-traces/succeed/succeed3/dummystream [new file with mode: 0644]
tests/ctf-traces/succeed/succeed3/metadata [new file with mode: 0644]
tests/ctf-traces/succeed/succeed4/metadata [new file with mode: 0644]
tests/lib/Makefile.am
tests/lib/runall.sh
tests/lib/test-bitfield.c [new file with mode: 0644]
tests/lib/test-seeks.c
tests/runall.sh
tests/test-bitfield.c [deleted file]
types/array.c
types/enum.c
types/float.c
types/integer.c
types/sequence.c
types/string.c
types/struct.c
types/types.c
types/variant.c

index e4562869ae1de93909c82cf64dc475491c112e4a..c60c0e4b00092d6df13395aba313e85cce08953e 100644 (file)
@@ -1,5 +1,5 @@
-/tests/test-bitfield
 *~
+/tests/lib/test-bitfield
 /tests/lib/test-seeks
 *.o
 *.a
@@ -36,3 +36,4 @@ stamp-h1
 bindings/python/babeltrace.i
 bindings/python/babeltrace.py
 bindings/python/babeltrace_wrap.c
+babeltrace.pc
index a62ebebfc6a4c9f57080fa90eef634231c38c513..8b2e8fbdc03ef8c9d61fffb924729cc1fb7c66e2 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,128 @@
+2013-06-18 Babeltrace 1.1.1
+       * Compare traces by stream path as secondary key
+       * Fix: use index, not cur_index, for SEEK_SET validation
+       * Fix: ctf-text irregular output with disabled field names
+       * Support old compilers
+       * Remove useless variable assignment
+       * Fix: Remove extra quote after an include directive
+       * Don't dereference before NULL check
+       * eliminate dead code
+       * fix babeltrace-log error checking
+       * Fix resource leak on error path
+       * Fix: handle error checking should compare against NULL
+       * Remove unused array in bt_context_add_traces_recursive
+       * Fix: Suppress a compiler warning (always-false condition)
+       * Cleanup: remove trailing whitespaces
+       * Move memstream.h and uuid.h to include/babeltrace/compat directory
+       * Fix: handling of empty streams
+       * Add new option --clock-offset-ns
+       * Fix: add missing error return when create_event_definitions fails
+       * Fix: ctf-text should link on libbabeltrace-ctf
+       * Move clock to bt_trace_descriptor
+       * Remove unused stream_heap
+       * Move trace collection pointer to bt_trace_descriptor
+       * Move bt_handle to bt_trace_descriptor
+       * Move bt_context to bt_trace_descriptor
+       * Privatize struct bt_trace descriptor, move trace path
+       * Add backward ref from bt_stream_pos to bt_trace_descriptor
+       * Fix kFreeBSD build
+       * Fix: babeltrace-log timestamps should be in nsec
+       * Use objstack for AST allocation
+       * Remove unused gc field
+       * Use objstack to store nodes
+       * Use objstack for strings
+       * Implement objstack for parser
+       * Fix: octal and hex string handling
+       * Simplify error node
+       * Lexer cleanup
+       * Fix: invalid integer suffix parsing
+       * Test cleanup
+       * Test cleanup
+       * Test cleanup
+       * Fix: bootstrap should call libtoolize
+       * Fix bootstrap script
+       * Use uint64_t for packet_map_len
+       * Add smalltrace succeed/fail test cases
+       * Support packets and trace files smaller than page size
+       * Move ctf-metadata plugin into its own shared object
+       * Implement ctf-metadata output plugin
+       * Handle make_node errors with TLS dummy node
+       * Remove nested expressions
+       * Eliminate dead code
+       * Fix: trace_collection_add() add after check
+       * Handle integers in lexer rather than grammar
+       * Implement perror printf
+       * Support escape characters in metadata strings
+       * Add error node to AST
+       * Introduce macro to enforce matching enum to string for node types
+       * Fix: add semantic check in grammar
+       * Implement likely/unlikely ifdefs
+       * Fix unary constant use after error
+       * Use new print macros in ctf-parser.y
+       * Print error on invalid token
+       * Implement macros for error printout
+       * Add line number to parser nodes
+       * Fix: handle errors gracefully
+       * Fix: memleak on error path
+       * Add missing NULL pointer check
+       * Show token in CTF parser error
+       * Remove unused lineno from struct ctf_scanner
+       * Show line numbers in CTF parser errors
+       * Ignore Windows-style EOL character in metadata
+       * Replace AM_PROG_MKDIR obsolete macro with AC_PROG_MKDIR_P
+
+2013-03-23 Babeltrace 1.1.0
+       * Reinsert "at end of stream" message for discarded events
+       * Improvement: Message from babeltrace concerning discarded events needs i
+       * Cleanup: typo fix
+       * Cleanup: add end of line at end of verbose message
+       * Fix: misleading message from babeltrace --verbose
+       * Fix: babeltrace --fields all  overrides --no-delta
+       * Add verbosity to stream id error message
+       * Fix: Ensure the specified input format is CTF
+       * Fix: Undefined behavior of double free on strlist in get_names_args
+       * Fix: ctf-text: don't close stdout
+       * Fix: warning message for unexpected trace byte order
+       * Namespace the struct declaration
+       * Namespace the struct definition
+       * Namespace the struct format
+       * Namespace the struct mmap_stream
+       * Namespace the struct trace_descriptor
+       * Namespace struct stream_pos
+       * Namespace compliance for dependencies function
+       * Cleanup error messages
+       * Fix: babeltrace: make '-w' actually work
+       * Convert the unit tests to the TAP format
+       * Spelling cleanups within comments
+       * Move the bitfield test to tests/lib/
+       * Fix: Added a null pointer check to bt_ctf_field_name
+       * Add babeltrace.pc to gitignore
+       * namespacing: place flex/bison symbols under bt_yy namespace
+       * namespace the lookup_integer function
+       * namespace the definition functions
+       * namespace the variant functions
+       * namespace the declaration functions
+       * namespace the collection functions
+       * namespace the heap functions
+       * namespace the struct functions
+       * namespace the string functions
+       * namespace the sequence functions
+       * namespace the int functions
+       * namespace the enum functions
+       * namespace definition_ref and definition_unref
+       * namespace declaration_ref and declaration_unref
+       * namespace the array functions
+       * namespace the scope_path functions
+       * Hide internal functions of libbabeltrace-ctf
+       * Hide internal functions of ctf-text
+       * BT_HIDDEN macro
+       * Namespace the lookup_enum function
+
+2012-01-24 Babeltrace 1.0.3
+       * Fix: Double free when calling bt_context_remove_trace()
+       * Add missing runall.sh to dist packaging
+       * Fix: alignment of compound types containing array field
+
 2012-01-11 Babeltrace 1.0.2
        * Fix: add tests/lib missing files to Makefile.am
 
index f6926cac5e8b2bd374f35f6554d7fd91877861b9..1dd41c0d30988586a123c99718668f4bdfbf97f5 100755 (executable)
--- a/bootstrap
+++ b/bootstrap
@@ -4,9 +4,6 @@ set -x
 if [ ! -e config ]; then
        mkdir config
 fi
-aclocal -I m4
-libtoolize --force --copy
-autoheader
-automake --add-missing --copy
-autoconf
 
+libtoolize --force --copy
+autoreconf -i
index aab61999ecf32229c65b4ae23dbabda58bb31066..4563c35c575ae216ac83f63b8b717fff079fa128 100644 (file)
@@ -1,7 +1,7 @@
 #                                               -*- Autoconf -*-
 # Process this file with autoconf to produce a configure script.
 
-AC_INIT([babeltrace],[1.0.2],[mathieu dot desnoyers at efficios dot com])
+AC_INIT([babeltrace],[1.1.1],[mathieu dot desnoyers at efficios dot com])
 AC_CONFIG_AUX_DIR([config])
 AC_CANONICAL_TARGET
 AC_CANONICAL_HOST
@@ -10,14 +10,14 @@ m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
 
 AC_CONFIG_MACRO_DIR([m4])
 
-AM_PROG_MKDIR_P
+AC_PROG_MKDIR_P
 
 AC_CONFIG_HEADERS([config.h])
 
 AC_SYS_LARGEFILE
 
 # Checks for programs.
-AC_PROG_CC
+AC_PROG_CC_STDC
 AC_PROG_MAKE_SET
 LT_INIT
 AC_PROG_YACC
@@ -133,6 +133,7 @@ AC_CONFIG_FILES([
        formats/ctf/types/Makefile
        formats/ctf-text/Makefile
        formats/ctf-text/types/Makefile
+       formats/ctf-metadata/Makefile
        formats/bt-dummy/Makefile
        formats/ctf/metadata/Makefile
        converter/Makefile
index 482aec348a922fadf4002a63ce44f31fffb294e0..de70313e3273463dc8085d6980d9be187dc66a53 100644 (file)
@@ -14,6 +14,7 @@ babeltrace_LDADD = \
        $(top_builddir)/lib/libbabeltrace.la \
        $(top_builddir)/formats/ctf/libbabeltrace-ctf.la \
        $(top_builddir)/formats/ctf-text/libbabeltrace-ctf-text.la \
+       $(top_builddir)/formats/ctf-metadata/libbabeltrace-ctf-metadata.la \
        $(top_builddir)/formats/bt-dummy/libbabeltrace-dummy.la
 
 babeltrace_log_SOURCES = babeltrace-log.c
index 214871192b2e3034d90a16c5b99c0d8a1babea55..b6d798f797d0f86094b69c3e507dbf045ebed60f 100644 (file)
 
 #include <babeltrace/babeltrace-internal.h>
 #include <babeltrace/ctf/types.h>
-#include <babeltrace/uuid.h>
+#include <babeltrace/compat/uuid.h>
+#include <babeltrace/compat/utc.h>
 #include <babeltrace/endian.h>
 
+#define NSEC_PER_USEC 1000UL
+#define NSEC_PER_MSEC 1000000UL
+#define NSEC_PER_SEC 1000000000ULL
 #define USEC_PER_SEC 1000000UL
 
 int babeltrace_debug, babeltrace_verbose;
@@ -123,7 +127,7 @@ void write_packet_header(struct ctf_stream_pos *pos, unsigned char *uuid)
        ctf_align_pos(&dummy, sizeof(uint32_t) * CHAR_BIT);
        ctf_move_pos(&dummy, sizeof(uint32_t) * CHAR_BIT);
        assert(!ctf_pos_packet(&dummy));
-       
+
        ctf_align_pos(pos, sizeof(uint32_t) * CHAR_BIT);
        *(uint32_t *) ctf_get_pos_addr(pos) = 0xC1FC1FC1;
        ctf_move_pos(pos, sizeof(uint32_t) * CHAR_BIT);
@@ -149,7 +153,7 @@ void write_packet_context(struct ctf_stream_pos *pos)
        ctf_align_pos(&dummy, sizeof(uint64_t) * CHAR_BIT);
        ctf_move_pos(&dummy, sizeof(uint64_t) * CHAR_BIT);
        assert(!ctf_pos_packet(&dummy));
-       
+
        ctf_align_pos(pos, sizeof(uint64_t) * CHAR_BIT);
        *(uint64_t *) ctf_get_pos_addr(pos) = ~0ULL;    /* Not known yet */
        pos->content_size_loc = (uint64_t *) ctf_get_pos_addr(pos);
@@ -160,7 +164,7 @@ void write_packet_context(struct ctf_stream_pos *pos)
        ctf_align_pos(&dummy, sizeof(uint64_t) * CHAR_BIT);
        ctf_move_pos(&dummy, sizeof(uint64_t) * CHAR_BIT);
        assert(!ctf_pos_packet(&dummy));
-       
+
        ctf_align_pos(pos, sizeof(uint64_t) * CHAR_BIT);
        *(uint64_t *) ctf_get_pos_addr(pos) = pos->packet_size;
        ctf_move_pos(pos, sizeof(uint64_t) * CHAR_BIT);
@@ -171,18 +175,46 @@ void write_event_header(struct ctf_stream_pos *pos, char *line,
                        char **tline, size_t len, size_t *tlen,
                        uint64_t *ts)
 {
-       unsigned long sec, usec;
-
        if (!s_timestamp)
                return;
 
        /* Only need to be executed on first pass (dummy) */
-       if (pos->dummy) {
-               int ret;
+       if (pos->dummy) {
+               int has_timestamp = 0;
+               unsigned long sec, usec, msec;
+               unsigned int year, mon, mday, hour, min;
 
                /* Extract time from input line */
-               ret = sscanf(line, "[%lu.%lu] ", &sec, &usec);
-               if (ret == 2) {
+               if (sscanf(line, "[%lu.%lu] ", &sec, &usec) == 2) {
+                       *ts = (uint64_t) sec * USEC_PER_SEC + (uint64_t) usec;
+                       /*
+                        * Default CTF clock has 1GHz frequency. Convert
+                        * from usec to nsec.
+                        */
+                       *ts *= NSEC_PER_USEC;
+                       has_timestamp = 1;
+               } else if (sscanf(line, "[%u-%u-%u %u:%u:%lu.%lu] ",
+                               &year, &mon, &mday, &hour, &min,
+                               &sec, &msec) == 7) {
+                       time_t ep_sec;
+                       struct tm ti;
+
+                       memset(&ti, 0, sizeof(ti));
+                       ti.tm_year = year - 1900;       /* from 1900 */
+                       ti.tm_mon = mon - 1;            /* 0 to 11 */
+                       ti.tm_mday = mday;
+                       ti.tm_hour = hour;
+                       ti.tm_min = min;
+                       ti.tm_sec = sec;
+
+                       ep_sec = babeltrace_timegm(&ti);
+                       if (ep_sec != (time_t) -1) {
+                               *ts = (uint64_t) ep_sec * NSEC_PER_SEC
+                                       + (uint64_t) msec * NSEC_PER_MSEC;
+                       }
+                       has_timestamp = 1;
+               }
+               if (has_timestamp) {
                        *tline = strchr(line, ']');
                        assert(*tline);
                        (*tline)++;
@@ -190,7 +222,6 @@ void write_event_header(struct ctf_stream_pos *pos, char *line,
                                (*tline)++;
                        }
                        *tlen = len + line - *tline;
-                       *ts = (uint64_t) sec * USEC_PER_SEC + (uint64_t) usec;
                }
        }
        /* timestamp */
@@ -247,7 +278,7 @@ void trace_text(FILE *input, int output)
        int ret;
 
        memset(&pos, 0, sizeof(pos));
-       ret = ctf_init_pos(&pos, output, O_RDWR);
+       ret = ctf_init_pos(&pos, NULL, output, O_RDWR);
        if (ret) {
                fprintf(stderr, "Error in ctf_init_pos\n");
                return;
@@ -284,6 +315,7 @@ void usage(FILE *fp)
        fprintf(fp, "  OUTPUT                         Output trace path\n");
        fprintf(fp, "\n");
        fprintf(fp, "  -t                             With timestamps (format: [sec.usec] string\\n)\n");
+       fprintf(fp, "                                                 (format: [YYYY-MM-DD HH:MM:SS.MS] string\\n)\n");
        fprintf(fp, "\n");
 }
 
@@ -353,7 +385,7 @@ int main(int argc, char **argv)
 
        metadata_fd = openat(dir_fd, "metadata", O_RDWR|O_CREAT,
                             S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP);
-       if (fd < 0) {
+       if (metadata_fd < 0) {
                perror("openat");
                goto error_closedatastream;
        }
index fe7d39fa49b5b13d1fc7185c9f36e0a9c714ac8d..d5a7040cdb33b4bc4085a2c31cb8efcd8a3b8c6a 100644 (file)
@@ -31,6 +31,7 @@
 #include <babeltrace/babeltrace.h>
 #include <babeltrace/format.h>
 #include <babeltrace/context.h>
+#include <babeltrace/context-internal.h>
 #include <babeltrace/ctf/types.h>
 #include <babeltrace/ctf/events.h>
 /* TODO: fix object model for format-agnostic callbacks */
@@ -68,7 +69,7 @@ static char *opt_input_format, *opt_output_format;
 static GPtrArray *opt_input_paths;
 static char *opt_output_path;
 
-static struct format *fmt_read;
+static struct bt_format *fmt_read;
 
 static
 void strlower(char *str)
@@ -92,6 +93,7 @@ enum {
        OPT_FIELDS,
        OPT_NO_DELTA,
        OPT_CLOCK_OFFSET,
+       OPT_CLOCK_OFFSET_NS,
        OPT_CLOCK_CYCLES,
        OPT_CLOCK_SECONDS,
        OPT_CLOCK_DATE,
@@ -109,7 +111,7 @@ enum {
  */
 static struct poptOption long_options[] = {
        /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
-       { "output", 'w', POPT_ARG_STRING, NULL, OPT_NONE, NULL, NULL },
+       { "output", 'w', POPT_ARG_STRING, NULL, OPT_OUTPUT_PATH, NULL, NULL },
        { "input-format", 'i', POPT_ARG_STRING, NULL, OPT_INPUT_FORMAT, NULL, NULL },
        { "output-format", 'o', POPT_ARG_STRING, NULL, OPT_OUTPUT_FORMAT, NULL, NULL },
        { "help", 'h', POPT_ARG_NONE, NULL, OPT_HELP, NULL, NULL },
@@ -120,6 +122,7 @@ static struct poptOption long_options[] = {
        { "fields", 'f', POPT_ARG_STRING, NULL, OPT_FIELDS, NULL, NULL },
        { "no-delta", 0, POPT_ARG_NONE, NULL, OPT_NO_DELTA, NULL, NULL },
        { "clock-offset", 0, POPT_ARG_STRING, NULL, OPT_CLOCK_OFFSET, NULL, NULL },
+       { "clock-offset-ns", 0, POPT_ARG_STRING, NULL, OPT_CLOCK_OFFSET_NS, NULL, NULL },
        { "clock-cycles", 0, POPT_ARG_NONE, NULL, OPT_CLOCK_CYCLES, NULL, NULL },
        { "clock-seconds", 0, POPT_ARG_NONE, NULL, OPT_CLOCK_SECONDS, NULL, NULL },
        { "clock-date", 0, POPT_ARG_NONE, NULL, OPT_CLOCK_DATE, NULL, NULL },
@@ -163,6 +166,7 @@ static void usage(FILE *fp)
        fprintf(fp, "                                     (default: trace:hostname,trace:procname,trace:vpid)\n");
        fprintf(fp, "      --clock-cycles             Timestamp in cycles\n");
        fprintf(fp, "      --clock-offset seconds     Clock offset in seconds\n");
+       fprintf(fp, "      --clock-offset-ns ns       Clock offset in nanoseconds\n");
        fprintf(fp, "      --clock-seconds            Print the timestamps as [sec.ns]\n");
        fprintf(fp, "                                 (default is: [hh:mm:ss.ns])\n");
        fprintf(fp, "      --clock-date               Print clock date\n");
@@ -204,7 +208,6 @@ static int get_names_args(poptContext *pc)
                        opt_payload_field_names = 0;
                } else {
                        fprintf(stderr, "[error] unknown field name type %s\n", str);
-                       free(strlist);
                        ret = -EINVAL;
                        goto end;
                }
@@ -357,6 +360,29 @@ static int parse_options(int argc, char **argv)
                case OPT_CLOCK_SECONDS:
                        opt_clock_seconds = 1;
                        break;
+               case OPT_CLOCK_OFFSET_NS:
+               {
+                       char *str;
+                       char *endptr;
+
+                       str = (char *) poptGetOptArg(pc);
+                       if (!str) {
+                               fprintf(stderr, "[error] Missing --clock-offset-ns argument\n");
+                               ret = -EINVAL;
+                               goto end;
+                       }
+                       errno = 0;
+                       opt_clock_offset_ns = strtoull(str, &endptr, 0);
+                       if (*endptr != '\0' || str == endptr || errno != 0) {
+                               fprintf(stderr, "[error] Incorrect --clock-offset-ns argument: %s\n", str);
+                               ret = -EINVAL;
+                               free(str);
+                               goto end;
+                       }
+                       free(str);
+                       break;
+               }
+
                case OPT_CLOCK_DATE:
                        opt_clock_date = 1;
                        break;
@@ -425,15 +451,20 @@ static int traverse_trace_dir(const char *fpath, const struct stat *sb,
                /* No meta data, just return */
                return 0;
        } else {
+               int err_close = 0;
+
                closeret = close(metafd);
                if (closeret < 0) {
                        perror("close");
-                       return -1;      /* failure */
+                       err_close = 1;
                }
                closeret = close(dirfd);
                if (closeret < 0) {
                        perror("close");
-                       return -1;      /* failure */
+                       err_close = 1;
+               }
+               if (err_close) {
+                       return -1;
                }
 
                /* Add path to the global list */
@@ -461,18 +492,14 @@ static int traverse_trace_dir(const char *fpath, const struct stat *sb,
  */
 int bt_context_add_traces_recursive(struct bt_context *ctx, const char *path,
                const char *format_str,
-               void (*packet_seek)(struct stream_pos *pos,
+               void (*packet_seek)(struct bt_stream_pos *pos,
                        size_t offset, int whence))
 {
-
-       GArray *trace_ids;
-       int ret = 0;
+       int ret = 0, trace_ids = 0;
 
        /* Should lock traversed_paths mutex here if used in multithread */
 
        traversed_paths = g_ptr_array_new();
-       trace_ids = g_array_new(FALSE, TRUE, sizeof(int));
-
        ret = nftw(path, traverse_trace_dir, 10, 0);
 
        /* Process the array if ntfw did not return a fatal error */
@@ -494,7 +521,7 @@ int bt_context_add_traces_recursive(struct bt_context *ctx, const char *path,
                                /* Allow to skip erroneous traces. */
                                ret = 1;        /* partial error */
                        } else {
-                               g_array_append_val(trace_ids, trace_id);
+                               trace_ids++;
                        }
                        g_string_free(trace_path, TRUE);
                }
@@ -508,15 +535,75 @@ int bt_context_add_traces_recursive(struct bt_context *ctx, const char *path,
        /*
         * Return an error if no trace can be opened.
         */
-       if (trace_ids->len == 0) {
+       if (trace_ids == 0) {
                fprintf(stderr, "[error] Cannot open any trace for reading.\n\n");
                ret = -ENOENT;          /* failure */
        }
-       g_array_free(trace_ids, TRUE);
        return ret;
 }
 
-int convert_trace(struct trace_descriptor *td_write,
+static
+int trace_pre_handler(struct bt_trace_descriptor *td_write,
+                 struct bt_context *ctx)
+{
+       struct ctf_text_stream_pos *sout;
+       struct trace_collection *tc;
+       int ret, i;
+
+       sout = container_of(td_write, struct ctf_text_stream_pos,
+                       trace_descriptor);
+
+       if (!sout->parent.pre_trace_cb)
+               return 0;
+
+       tc = ctx->tc;
+       for (i = 0; i < tc->array->len; i++) {
+               struct bt_trace_descriptor *td =
+                       g_ptr_array_index(tc->array, i);
+
+               ret = sout->parent.pre_trace_cb(&sout->parent, td);
+               if (ret) {
+                       fprintf(stderr, "[error] Writing to trace pre handler failed.\n");
+                       goto end;
+               }
+       }
+       ret = 0;
+end:
+       return ret;
+}
+
+static
+int trace_post_handler(struct bt_trace_descriptor *td_write,
+                 struct bt_context *ctx)
+{
+       struct ctf_text_stream_pos *sout;
+       struct trace_collection *tc;
+       int ret, i;
+
+       sout = container_of(td_write, struct ctf_text_stream_pos,
+                       trace_descriptor);
+
+       if (!sout->parent.post_trace_cb)
+               return 0;
+
+       tc = ctx->tc;
+       for (i = 0; i < tc->array->len; i++) {
+               struct bt_trace_descriptor *td =
+                       g_ptr_array_index(tc->array, i);
+
+               ret = sout->parent.post_trace_cb(&sout->parent, td);
+               if (ret) {
+                       fprintf(stderr, "[error] Writing to trace post handler failed.\n");
+                       goto end;
+               }
+       }
+       ret = 0;
+end:
+       return ret;
+}
+
+static
+int convert_trace(struct bt_trace_descriptor *td_write,
                  struct bt_context *ctx)
 {
        struct bt_ctf_iter *iter;
@@ -528,6 +615,9 @@ int convert_trace(struct trace_descriptor *td_write,
        sout = container_of(td_write, struct ctf_text_stream_pos,
                        trace_descriptor);
 
+       if (!sout->parent.event_cb)
+               return 0;
+
        begin_pos.type = BT_SEEK_BEGIN;
        iter = bt_ctf_iter_create(ctx, &begin_pos, NULL);
        if (!iter) {
@@ -555,8 +645,8 @@ error_iter:
 int main(int argc, char **argv)
 {
        int ret, partial_error = 0, open_success = 0;
-       struct format *fmt_write;
-       struct trace_descriptor *td_write;
+       struct bt_format *fmt_write;
+       struct bt_trace_descriptor *td_write;
        struct bt_context *ctx;
        int i;
 
@@ -587,7 +677,7 @@ int main(int argc, char **argv)
        }
        printf_verbose("Converting from format: %s\n",
                opt_input_format ? : "ctf <default>");
-       printf_verbose("Converting to directory: %s\n",
+       printf_verbose("Converting to target: %s\n",
                opt_output_path ? : "<stdout>");
        printf_verbose("Converting to format: %s\n",
                opt_output_format ? : "text <default>");
@@ -607,7 +697,7 @@ int main(int argc, char **argv)
                }
        }
        fmt_read = bt_lookup_format(g_quark_from_static_string(opt_input_format));
-       if (!fmt_read) {
+       if (!fmt_read || fmt_read->name != g_quark_from_static_string("ctf")) {
                fprintf(stderr, "[error] Format \"%s\" is not supported.\n\n",
                        opt_input_format);
                partial_error = 1;
@@ -661,12 +751,24 @@ int main(int argc, char **argv)
        if (partial_error)
                sleep(PARTIAL_ERROR_SLEEP);
 
+       ret = trace_pre_handler(td_write, ctx);
+       if (ret) {
+               fprintf(stderr, "Error in trace pre handle.\n\n");
+               goto error_copy_trace;
+       }
+
        ret = convert_trace(td_write, ctx);
        if (ret) {
                fprintf(stderr, "Error printing trace.\n\n");
                goto error_copy_trace;
        }
 
+       ret = trace_post_handler(td_write, ctx);
+       if (ret) {
+               fprintf(stderr, "Error in trace post handle.\n\n");
+               goto error_copy_trace;
+       }
+
        fmt_write->close_trace(td_write);
 
        bt_context_put(ctx);
index 319629909a34ce462e93531c7c403c2bfd10d1d4..78e9055a57812a945472d941df33fbe02b90bbb1 100644 (file)
@@ -29,7 +29,7 @@ Input trace FILE(s) or directory(ies)
 Output trace path (default: stdout)
 .TP
 .BR "-i, --input-format FORMAT"
-Input trace format (default: ctf)
+Input trace format (default: ctf). CTF is currently the only supported input format.
 .TP
 .BR "-o, --output-format FORMAT"
 Output trace format (default: text)
index ee3a6eda66e05da967f1a34908cb04592050d0d9..62ae1452c2e83c3a900c1c1bab8b6cf2065aac93 100644 (file)
@@ -1,3 +1,3 @@
 AM_CFLAGS = $(PACKAGE_CFLAGS) -I$(top_srcdir)/include
 
-SUBDIRS = . ctf ctf-text bt-dummy
+SUBDIRS = . ctf ctf-text ctf-metadata bt-dummy
index b55dd696daee73847954e0df0c95be42125a072f..6192e88807570602fe31813f8a3303fa8c8858e4 100644 (file)
 #include <stdlib.h>
 
 static
-int bt_dummy_write_event(struct stream_pos *ppos, struct ctf_stream_definition *stream)
+int bt_dummy_write_event(struct bt_stream_pos *ppos, struct ctf_stream_definition *stream)
 {
        return 0;
 }
 
 static
-struct trace_descriptor *bt_dummy_open_trace(const char *path, int flags,
-               void (*packet_seek)(struct stream_pos *pos, size_t index,
+struct bt_trace_descriptor *bt_dummy_open_trace(const char *path, int flags,
+               void (*packet_seek)(struct bt_stream_pos *pos, size_t index,
                        int whence), FILE *metadata_fp)
 {
        struct ctf_text_stream_pos *pos;
@@ -54,11 +54,12 @@ struct trace_descriptor *bt_dummy_open_trace(const char *path, int flags,
        pos = g_new0(struct ctf_text_stream_pos, 1);
        pos->parent.rw_table = NULL;
        pos->parent.event_cb = bt_dummy_write_event;
+       pos->parent.trace = &pos->trace_descriptor;
        return &pos->trace_descriptor;
 }
 
 static
-int bt_dummy_close_trace(struct trace_descriptor *td)
+int bt_dummy_close_trace(struct bt_trace_descriptor *td)
 {
        struct ctf_text_stream_pos *pos =
                container_of(td, struct ctf_text_stream_pos,
@@ -68,7 +69,7 @@ int bt_dummy_close_trace(struct trace_descriptor *td)
 }
 
 static
-struct format bt_dummy_format = {
+struct bt_format bt_dummy_format = {
        .open_trace = bt_dummy_open_trace,
        .close_trace = bt_dummy_close_trace,
 };
diff --git a/formats/ctf-metadata/Makefile.am b/formats/ctf-metadata/Makefile.am
new file mode 100644 (file)
index 0000000..61d08e8
--- /dev/null
@@ -0,0 +1,12 @@
+AM_CFLAGS = $(PACKAGE_CFLAGS) -I$(top_srcdir)/include
+
+lib_LTLIBRARIES = libbabeltrace-ctf-metadata.la
+
+libbabeltrace_ctf_metadata_la_SOURCES = \
+       ctf-metadata.c
+
+libbabeltrace_ctf_metadata_la_LDFLAGS = \
+       -Wl,--no-as-needed
+
+libbabeltrace_ctf_metadata_la_LIBADD = \
+       $(top_builddir)/lib/libbabeltrace.la
diff --git a/formats/ctf-metadata/ctf-metadata.c b/formats/ctf-metadata/ctf-metadata.c
new file mode 100644 (file)
index 0000000..a5a74c3
--- /dev/null
@@ -0,0 +1,144 @@
+/*
+ * BabelTrace - Common Trace Format (CTF)
+ *
+ * CTF Metadata Dump.
+ *
+ * Copyright 2010-2011 EfficiOS Inc. and Linux Foundation
+ *
+ * Author: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#include <babeltrace/format.h>
+#include <babeltrace/ctf-text/types.h>
+#include <babeltrace/babeltrace-internal.h>
+#include <babeltrace/ctf/events-internal.h>
+#include <inttypes.h>
+#include <sys/mman.h>
+#include <errno.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <dirent.h>
+#include <glib.h>
+#include <unistd.h>
+#include <stdlib.h>
+
+static
+struct bt_trace_descriptor *ctf_metadata_open_trace(const char *path, int flags,
+               void (*packet_seek)(struct bt_stream_pos *pos, size_t index,
+                       int whence), FILE *metadata_fp);
+static
+int ctf_metadata_close_trace(struct bt_trace_descriptor *descriptor);
+
+static
+struct bt_format ctf_metadata_format = {
+       .open_trace = ctf_metadata_open_trace,
+       .close_trace = ctf_metadata_close_trace,
+};
+
+static
+int ctf_metadata_trace_pre_handler(struct bt_stream_pos *ppos,
+                       struct bt_trace_descriptor *td)
+{
+       struct ctf_text_stream_pos *pos =
+               container_of(ppos, struct ctf_text_stream_pos, parent);
+       struct ctf_trace *trace;
+
+       trace = container_of(td, struct ctf_trace, parent);
+       if (!trace->metadata_string)
+               return -EINVAL;
+       if (trace->metadata_packetized) {
+               fprintf(pos->fp, "/* CTF %u.%u */\n",
+                       BT_CTF_MAJOR, BT_CTF_MINOR);
+       }
+       fprintf(pos->fp, "%s", trace->metadata_string);
+       return 0;
+}
+
+static
+struct bt_trace_descriptor *ctf_metadata_open_trace(const char *path, int flags,
+               void (*packet_seek)(struct bt_stream_pos *pos, size_t index,
+                       int whence), FILE *metadata_fp)
+{
+       struct ctf_text_stream_pos *pos;
+       FILE *fp;
+
+       pos = g_new0(struct ctf_text_stream_pos, 1);
+
+       pos->last_real_timestamp = -1ULL;
+       pos->last_cycles_timestamp = -1ULL;
+       switch (flags & O_ACCMODE) {
+       case O_RDWR:
+               if (!path)
+                       fp = stdout;
+               else
+                       fp = fopen(path, "w");
+               if (!fp)
+                       goto error;
+               pos->fp = fp;
+               pos->parent.pre_trace_cb = ctf_metadata_trace_pre_handler;
+               pos->parent.trace = &pos->trace_descriptor;
+               pos->print_names = 0;
+               break;
+       case O_RDONLY:
+       default:
+               fprintf(stderr, "[error] Incorrect open flags.\n");
+               goto error;
+       }
+
+       return &pos->trace_descriptor;
+error:
+       g_free(pos);
+       return NULL;
+}
+
+static
+int ctf_metadata_close_trace(struct bt_trace_descriptor *td)
+{
+       int ret;
+       struct ctf_text_stream_pos *pos =
+               container_of(td, struct ctf_text_stream_pos, trace_descriptor);
+       if (pos->fp != stdout) {
+               ret = fclose(pos->fp);
+               if (ret) {
+                       perror("Error on fclose");
+                       return -1;
+               }
+       }
+       g_free(pos);
+       return 0;
+}
+
+static
+void __attribute__((constructor)) ctf_metadata_init(void)
+{
+       int ret;
+
+       ctf_metadata_format.name = g_quark_from_static_string("ctf-metadata");
+       ret = bt_register_format(&ctf_metadata_format);
+       assert(!ret);
+}
+
+static
+void __attribute__((destructor)) ctf_metadata_exit(void)
+{
+       bt_unregister_format(&ctf_metadata_format);
+}
index 4d84d928a3704c0b1370bf890db5daff4bfd4b84..a7036c966c9685ee5f8d9d1cf73e2a3dcdf35dd2 100644 (file)
@@ -12,4 +12,5 @@ libbabeltrace_ctf_text_la_LDFLAGS = \
        types/libctf-text-types.la
 
 libbabeltrace_ctf_text_la_LIBADD = \
-       $(top_builddir)/lib/libbabeltrace.la
+       $(top_builddir)/lib/libbabeltrace.la \
+       $(top_builddir)/formats/ctf/libbabeltrace-ctf.la
index d344c1c0ce7d193532165bec1cd02456a9cdb57c..48ce31b8691081319e7ee35762d87c8a47b579be 100644 (file)
@@ -87,11 +87,11 @@ enum bt_loglevel {
 };
 
 static
-struct trace_descriptor *ctf_text_open_trace(const char *path, int flags,
-               void (*packet_seek)(struct stream_pos *pos, size_t index,
+struct bt_trace_descriptor *ctf_text_open_trace(const char *path, int flags,
+               void (*packet_seek)(struct bt_stream_pos *pos, size_t index,
                        int whence), FILE *metadata_fp);
 static
-int ctf_text_close_trace(struct trace_descriptor *descriptor);
+int ctf_text_close_trace(struct bt_trace_descriptor *descriptor);
 
 static
 rw_dispatch write_dispatch_table[] = {
@@ -106,7 +106,7 @@ rw_dispatch write_dispatch_table[] = {
 };
 
 static
-struct format ctf_text_format = {
+struct bt_format ctf_text_format = {
        .open_trace = ctf_text_open_trace,
        .close_trace = ctf_text_close_trace,
 };
@@ -135,7 +135,7 @@ struct ctf_callsite_dups *ctf_trace_callsite_lookup(struct ctf_trace *trace,
                        (gpointer) (unsigned long) callsite_name);
 }
 
-int print_field(struct definition *definition)
+int print_field(struct bt_definition *definition)
 {
        /* Print all fields in verbose mode */
        if (babeltrace_verbose)
@@ -232,7 +232,7 @@ const char *print_loglevel(int value)
 }
 
 static
-int ctf_text_write_event(struct stream_pos *ppos, struct ctf_stream_definition *stream)
+int ctf_text_write_event(struct bt_stream_pos *ppos, struct ctf_stream_definition *stream)
                         
 {
        struct ctf_text_stream_pos *pos =
@@ -265,23 +265,7 @@ int ctf_text_write_event(struct stream_pos *ppos, struct ctf_stream_definition *
        /* Print events discarded */
        if (stream->events_discarded) {
                fflush(pos->fp);
-               fprintf(stderr, "[warning] Tracer discarded %" PRIu64 " events between [",
-                       stream->events_discarded);
-               if (opt_clock_cycles) {
-                       ctf_print_timestamp(stderr, stream,
-                                       stream->prev_cycles_timestamp);
-                       fprintf(stderr, "] and [");
-                       ctf_print_timestamp(stderr, stream,
-                                       stream->prev_cycles_timestamp_end);
-               } else {
-                       ctf_print_timestamp(stderr, stream,
-                                       stream->prev_real_timestamp);
-                       fprintf(stderr, "] and [");
-                       ctf_print_timestamp(stderr, stream,
-                                       stream->prev_real_timestamp_end);
-               }
-               fprintf(stderr, "]. You should consider recording a new trace with larger buffers or with fewer events enabled.\n");
-               fflush(stderr);
+               ctf_print_discarded(stderr, stream, 0);
                stream->events_discarded = 0;
        }
 
@@ -304,7 +288,7 @@ int ctf_text_write_event(struct stream_pos *ppos, struct ctf_stream_definition *
                else
                        fprintf(pos->fp, " ");
        }
-       if ((opt_delta_field || opt_all_fields) && stream->has_timestamp) {
+       if (opt_delta_field && stream->has_timestamp) {
                uint64_t delta, delta_sec, delta_nsec;
 
                set_field_names_print(pos, ITEM_HEADER);
@@ -332,12 +316,12 @@ int ctf_text_write_event(struct stream_pos *ppos, struct ctf_stream_definition *
                pos->last_cycles_timestamp = stream->cycles_timestamp;
        }
 
-       if ((opt_trace_field || opt_all_fields) && stream_class->trace->path[0] != '\0') {
+       if ((opt_trace_field || opt_all_fields) && stream_class->trace->parent.path[0] != '\0') {
                set_field_names_print(pos, ITEM_HEADER);
                if (pos->print_names) {
                        fprintf(pos->fp, "trace = ");
                }
-               fprintf(pos->fp, "%s", stream_class->trace->path);
+               fprintf(pos->fp, "%s", stream_class->trace->parent.path);
                if (pos->print_names)
                        fprintf(pos->fp, ", ");
                else
@@ -555,8 +539,8 @@ error:
 }
 
 static
-struct trace_descriptor *ctf_text_open_trace(const char *path, int flags,
-               void (*packet_seek)(struct stream_pos *pos, size_t index,
+struct bt_trace_descriptor *ctf_text_open_trace(const char *path, int flags,
+               void (*packet_seek)(struct bt_stream_pos *pos, size_t index,
                        int whence), FILE *metadata_fp)
 {
        struct ctf_text_stream_pos *pos;
@@ -577,6 +561,7 @@ struct trace_descriptor *ctf_text_open_trace(const char *path, int flags,
                pos->fp = fp;
                pos->parent.rw_table = write_dispatch_table;
                pos->parent.event_cb = ctf_text_write_event;
+               pos->parent.trace = &pos->trace_descriptor;
                pos->print_names = 0;
                break;
        case O_RDONLY:
@@ -592,15 +577,17 @@ error:
 }
 
 static
-int ctf_text_close_trace(struct trace_descriptor *td)
+int ctf_text_close_trace(struct bt_trace_descriptor *td)
 {
        int ret;
        struct ctf_text_stream_pos *pos =
                container_of(td, struct ctf_text_stream_pos, trace_descriptor);
-       ret = fclose(pos->fp);
-       if (ret) {
-               perror("Error on fclose");
-               return -1;
+       if (pos->fp != stdout) {
+               ret = fclose(pos->fp);
+               if (ret) {
+                       perror("Error on fclose");
+                       return -1;
+               }
        }
        g_free(pos);
        return 0;
index 97b557f1498806b6f4b8e8e9bef1bfc26882360d..47eb1287a0f15dbac4604bc5bf5ecf21113839b1 100644 (file)
 #include <babeltrace/ctf-text/types.h>
 #include <stdio.h>
 
-int ctf_text_array_write(struct stream_pos *ppos, struct definition *definition)
+int ctf_text_array_write(struct bt_stream_pos *ppos, struct bt_definition *definition)
 {
        struct ctf_text_stream_pos *pos = ctf_text_pos(ppos);
        struct definition_array *array_definition =
                container_of(definition, struct definition_array, p);
        struct declaration_array *array_declaration =
                array_definition->declaration;
-       struct declaration *elem = array_declaration->elem;
+       struct bt_declaration *elem = array_declaration->elem;
        int field_nr_saved;
        int ret = 0;
 
@@ -63,7 +63,7 @@ int ctf_text_array_write(struct stream_pos *ppos, struct definition *definition)
                            && integer_declaration->p.alignment == CHAR_BIT)) {
                                pos->string = array_definition->string;
                                g_string_assign(array_definition->string, "");
-                               ret = array_rw(ppos, definition);
+                               ret = bt_array_rw(ppos, definition);
                                pos->string = NULL;
                        }
                        fprintf(pos->fp, "\"%s\"", array_definition->string->str);
@@ -77,7 +77,7 @@ int ctf_text_array_write(struct stream_pos *ppos, struct definition *definition)
        }
        field_nr_saved = pos->field_nr;
        pos->field_nr = 0;
-       ret = array_rw(ppos, definition);
+       ret = bt_array_rw(ppos, definition);
        if (!pos->dummy) {
                pos->depth--;
                fprintf(pos->fp, " ]");
index 9df8da84e40615058f2f1d3e061d76358af9ff56..647050029fd0a7ba0ffb2b224092f6e86757d5e4 100644 (file)
@@ -30,7 +30,7 @@
 #include <stdio.h>
 #include <stdint.h>
 
-int ctf_text_enum_write(struct stream_pos *ppos, struct definition *definition)
+int ctf_text_enum_write(struct bt_stream_pos *ppos, struct bt_definition *definition)
 {
        struct definition_enum *enum_definition =
                container_of(definition, struct definition_enum, p);
index 199b01337ada4622dba4170b4d3c43842f58f485..a4946f910eade757b0410e9bad358fca8ef6370f 100644 (file)
@@ -31,7 +31,7 @@
 #include <babeltrace/ctf-text/types.h>
 #include <stdio.h>
 
-int ctf_text_float_write(struct stream_pos *ppos, struct definition *definition)
+int ctf_text_float_write(struct bt_stream_pos *ppos, struct bt_definition *definition)
 {
        struct definition_float *float_definition =
                container_of(definition, struct definition_float, p);
index 0886b0628fffc6a5ffb8784f8fb610b401e41fd3..7363b524e6f1b9af5d896cd55630bcb3990b7c0c 100644 (file)
@@ -32,7 +32,7 @@
 #include <stdint.h>
 #include <babeltrace/bitfield.h>
 
-int ctf_text_integer_write(struct stream_pos *ppos, struct definition *definition)
+int ctf_text_integer_write(struct bt_stream_pos *ppos, struct bt_definition *definition)
 {
        struct definition_integer *integer_definition =
                container_of(definition, struct definition_integer, p);
index 20345ccee135815dff488a4d719207d1bae225c1..a9499b451ced7b3580d56899fed05a82508dc022 100644 (file)
 #include <babeltrace/ctf-text/types.h>
 #include <stdio.h>
 
-int ctf_text_sequence_write(struct stream_pos *ppos, struct definition *definition)
+int ctf_text_sequence_write(struct bt_stream_pos *ppos, struct bt_definition *definition)
 {
        struct ctf_text_stream_pos *pos = ctf_text_pos(ppos);
        struct definition_sequence *sequence_definition =
                container_of(definition, struct definition_sequence, p);
        struct declaration_sequence *sequence_declaration =
                sequence_definition->declaration;
-       struct declaration *elem = sequence_declaration->elem;
+       struct bt_declaration *elem = sequence_declaration->elem;
        int field_nr_saved;
        int ret = 0;
 
@@ -63,7 +63,7 @@ int ctf_text_sequence_write(struct stream_pos *ppos, struct definition *definiti
                            && integer_declaration->p.alignment == CHAR_BIT)) {
                                pos->string = sequence_definition->string;
                                g_string_assign(sequence_definition->string, "");
-                               ret = sequence_rw(ppos, definition);
+                               ret = bt_sequence_rw(ppos, definition);
                                pos->string = NULL;
                        }
                        fprintf(pos->fp, "\"%s\"", sequence_definition->string->str);
@@ -77,7 +77,7 @@ int ctf_text_sequence_write(struct stream_pos *ppos, struct definition *definiti
        }
        field_nr_saved = pos->field_nr;
        pos->field_nr = 0;
-       ret = sequence_rw(ppos, definition);
+       ret = bt_sequence_rw(ppos, definition);
        if (!pos->dummy) {
                pos->depth--;
                fprintf(pos->fp, " ]");
index 44aeb40d640cf9c76764e92107172e2dcf550f10..c397f0e2dfa720ebc150f0b96efd5fc2d3540c14 100644 (file)
@@ -31,8 +31,8 @@
 #include <limits.h>            /* C99 limits */
 #include <string.h>
 
-int ctf_text_string_write(struct stream_pos *ppos,
-                         struct definition *definition)
+int ctf_text_string_write(struct bt_stream_pos *ppos,
+                         struct bt_definition *definition)
 {
        struct definition_string *string_definition =
                container_of(definition, struct definition_string, p);
index 8a9344eb01dd765fd3d1b4a07e32f4656141c130..a2aee3a7bda69073db0b83254321d410043951f9 100644 (file)
 #include <babeltrace/ctf-text/types.h>
 #include <stdio.h>
 
-int ctf_text_struct_write(struct stream_pos *ppos, struct definition *definition)
+int ctf_text_struct_write(struct bt_stream_pos *ppos, struct bt_definition *definition)
 {
-       struct declaration *declaration = definition->declaration;
-       struct declaration_struct *struct_declaration =
-               container_of(declaration, struct declaration_struct, p);
        struct ctf_text_stream_pos *pos = ctf_text_pos(ppos);
-       uint64_t len = struct_declaration_len(struct_declaration);
        int field_nr_saved;
        int ret;
 
@@ -46,22 +42,20 @@ int ctf_text_struct_write(struct stream_pos *ppos, struct definition *definition
                if (pos->depth >= 0) {
                        if (pos->field_nr++ != 0)
                                fprintf(pos->fp, ",");
-                       if (pos->print_names || len > 1)
-                               fprintf(pos->fp, " ");
+                       fprintf(pos->fp, " ");
                        if (pos->print_names && definition->name != 0)
                                fprintf(pos->fp, "%s = ",
                                        rem_(g_quark_to_string(definition->name)));
-                       if (pos->print_names || len > 1)
-                               fprintf(pos->fp, "{");
+                       fprintf(pos->fp, "{");
                }
                pos->depth++;
        }
        field_nr_saved = pos->field_nr;
        pos->field_nr = 0;
-       ret = struct_rw(ppos, definition);
+       ret = bt_struct_rw(ppos, definition);
        if (!pos->dummy) {
                pos->depth--;
-               if (pos->depth >= 0 && (pos->print_names || len > 1)) {
+               if (pos->depth >= 0) {
                        fprintf(pos->fp, " }");
                }
        }
index 89d518a9455fefba77c1298d15b29cffed104560..3aeb6ec274dc599bca4338cb18fc5b09a9f2b1c3 100644 (file)
@@ -29,7 +29,7 @@
 #include <babeltrace/ctf-text/types.h>
 #include <stdio.h>
 
-int ctf_text_variant_write(struct stream_pos *ppos, struct definition *definition)
+int ctf_text_variant_write(struct bt_stream_pos *ppos, struct bt_definition *definition)
 {
        struct ctf_text_stream_pos *pos = ctf_text_pos(ppos);
        int field_nr_saved;
@@ -52,7 +52,7 @@ int ctf_text_variant_write(struct stream_pos *ppos, struct definition *definitio
        }
        field_nr_saved = pos->field_nr;
        pos->field_nr = 0;
-       ret = variant_rw(ppos, definition);
+       ret = bt_variant_rw(ppos, definition);
        if (!pos->dummy) {
                pos->depth--;
                if (pos->depth >= 0) {
index d803b69a2205340ee490b28ee8501bac5e143ca0..6dcc1bb3343cb19f8b6e1a3d1d26708e88fd1f22 100644 (file)
@@ -9,8 +9,7 @@ libbabeltrace_ctf_la_SOURCES = \
        events.c \
        iterator.c \
        callbacks.c \
-       events-private.h \
-       memstream.h
+       events-private.h
 
 # Request that the linker keeps all static libraries objects.
 libbabeltrace_ctf_la_LDFLAGS = \
index 71e3248868239fd806d6cceb2bdcce48e9e06886..8a8b3eed5f0d0f15a994cf4c84efcb1b172da70a 100644 (file)
@@ -38,7 +38,7 @@
 #include <inttypes.h>
 
 static
-struct bt_dependencies *_babeltrace_dependencies_create(const char *first,
+struct bt_dependencies *_bt_dependencies_create(const char *first,
                                                        va_list ap)
 {
        const char *iter;
@@ -56,13 +56,13 @@ struct bt_dependencies *_babeltrace_dependencies_create(const char *first,
        return dep;
 }
 
-struct bt_dependencies *babeltrace_dependencies_create(const char *first, ...)
+struct bt_dependencies *bt_dependencies_create(const char *first, ...)
 {
        va_list ap;
        struct bt_dependencies *deps;
 
        va_start(ap, first);
-       deps = _babeltrace_dependencies_create(first, ap);
+       deps = _bt_dependencies_create(first, ap);
        va_end(ap);
        return deps;
 }
@@ -89,7 +89,7 @@ int bt_ctf_iter_add_callback(struct bt_ctf_iter *iter,
        tc = iter->parent.ctx->tc;
        for (i = 0; i < tc->array->len; i++) {
                struct ctf_trace *tin;
-               struct trace_descriptor *td_read;
+               struct bt_trace_descriptor *td_read;
 
                td_read = g_ptr_array_index(tc->array, i);
                tin = container_of(td_read, struct ctf_trace, parent);
@@ -231,8 +231,6 @@ void process_callbacks(struct bt_ctf_iter *iter,
 
        for (i = 0; i < bt_chain->callback->len; i++) {
                cb = &g_array_index(bt_chain->callback, struct bt_callback, i);
-               if (!cb)
-                       goto end;
                ret = cb->callback(&ctf_data, cb->private_data);
                switch (ret) {
                case BT_CB_OK_STOP:
index 18a560132582ac9002535658734b51cb3abe68e8..947b439d24349d9055459e3339eec03fc27a2f35 100644 (file)
@@ -33,7 +33,7 @@
 #include <babeltrace/ctf/events-internal.h>
 #include <babeltrace/trace-handle-internal.h>
 #include <babeltrace/context-internal.h>
-#include <babeltrace/uuid.h>
+#include <babeltrace/compat/uuid.h>
 #include <babeltrace/endian.h>
 #include <inttypes.h>
 #include <stdio.h>
 #include "metadata/ctf-parser.h"
 #include "metadata/ctf-ast.h"
 #include "events-private.h"
-#include "memstream.h"
+#include <babeltrace/compat/memstream.h>
+
+#define LOG2_CHAR_BIT  3
+
+/*
+ * Length of first attempt at mapping a packet header, in bits.
+ */
+#define DEFAULT_HEADER_LEN     (getpagesize() * CHAR_BIT)
 
 /*
- * We currently simply map a page to read the packet header and packet
- * context to get the packet length and content length. (in bits)
+ * Lenght of packet to write, in bits.
  */
-#define MAX_PACKET_HEADER_LEN  (getpagesize() * CHAR_BIT)
 #define WRITE_PACKET_LEN       (getpagesize() * 8 * CHAR_BIT)
 
 #ifndef min
@@ -72,37 +77,38 @@ int opt_clock_cycles,
        opt_clock_gmt;
 
 uint64_t opt_clock_offset;
+uint64_t opt_clock_offset_ns;
 
 extern int yydebug;
 
 static
-struct trace_descriptor *ctf_open_trace(const char *path, int flags,
-               void (*packet_seek)(struct stream_pos *pos, size_t index,
+struct bt_trace_descriptor *ctf_open_trace(const char *path, int flags,
+               void (*packet_seek)(struct bt_stream_pos *pos, size_t index,
                        int whence),
                FILE *metadata_fp);
 static
-struct trace_descriptor *ctf_open_mmap_trace(
-               struct mmap_stream_list *mmap_list,
-               void (*packet_seek)(struct stream_pos *pos, size_t index,
+struct bt_trace_descriptor *ctf_open_mmap_trace(
+               struct bt_mmap_stream_list *mmap_list,
+               void (*packet_seek)(struct bt_stream_pos *pos, size_t index,
                        int whence),
                FILE *metadata_fp);
 static
-void ctf_set_context(struct trace_descriptor *descriptor,
+void ctf_set_context(struct bt_trace_descriptor *descriptor,
                struct bt_context *ctx);
 static
-void ctf_set_handle(struct trace_descriptor *descriptor,
+void ctf_set_handle(struct bt_trace_descriptor *descriptor,
                struct bt_trace_handle *handle);
 
 static
-int ctf_close_trace(struct trace_descriptor *descriptor);
+int ctf_close_trace(struct bt_trace_descriptor *descriptor);
 static
-uint64_t ctf_timestamp_begin(struct trace_descriptor *descriptor,
+uint64_t ctf_timestamp_begin(struct bt_trace_descriptor *descriptor,
                struct bt_trace_handle *handle, enum bt_clock_type type);
 static
-uint64_t ctf_timestamp_end(struct trace_descriptor *descriptor,
+uint64_t ctf_timestamp_end(struct bt_trace_descriptor *descriptor,
                struct bt_trace_handle *handle, enum bt_clock_type type);
 static
-int ctf_convert_index_timestamp(struct trace_descriptor *tdp);
+int ctf_convert_index_timestamp(struct bt_trace_descriptor *tdp);
 
 static
 rw_dispatch read_dispatch_table[] = {
@@ -129,7 +135,7 @@ rw_dispatch write_dispatch_table[] = {
 };
 
 static
-struct format ctf_format = {
+struct bt_format ctf_format = {
        .open_trace = ctf_open_trace,
        .open_mmap_trace = ctf_open_mmap_trace,
        .close_trace = ctf_close_trace,
@@ -141,7 +147,7 @@ struct format ctf_format = {
 };
 
 static
-uint64_t ctf_timestamp_begin(struct trace_descriptor *descriptor,
+uint64_t ctf_timestamp_begin(struct bt_trace_descriptor *descriptor,
                struct bt_trace_handle *handle, enum bt_clock_type type)
 {
        struct ctf_trace *tin;
@@ -202,7 +208,7 @@ error:
 }
 
 static
-uint64_t ctf_timestamp_end(struct trace_descriptor *descriptor,
+uint64_t ctf_timestamp_end(struct bt_trace_descriptor *descriptor,
                struct bt_trace_handle *handle, enum bt_clock_type type)
 {
        struct ctf_trace *tin;
@@ -307,6 +313,7 @@ void ctf_update_timestamp(struct ctf_stream_definition *stream,
  * Print timestamp, rescaling clock frequency to nanoseconds and
  * applying offsets as needed (unix time).
  */
+static
 void ctf_print_timestamp_real(FILE *fp,
                        struct ctf_stream_definition *stream,
                        uint64_t timestamp)
@@ -315,6 +322,9 @@ void ctf_print_timestamp_real(FILE *fp,
 
        ts_nsec = timestamp;
 
+       /* Add command-line offset in ns*/
+        ts_nsec += opt_clock_offset_ns;
+
        /* Add command-line offset */
        ts_sec += opt_clock_offset;
 
@@ -371,6 +381,7 @@ end:
 /*
  * Print timestamp, in cycles
  */
+static
 void ctf_print_timestamp_cycles(FILE *fp,
                struct ctf_stream_definition *stream,
                uint64_t timestamp)
@@ -390,7 +401,50 @@ void ctf_print_timestamp(FILE *fp,
 }
 
 static
-int ctf_read_event(struct stream_pos *ppos, struct ctf_stream_definition *stream)
+void print_uuid(FILE *fp, unsigned char *uuid)
+{
+       int i;
+
+       for (i = 0; i < BABELTRACE_UUID_LEN; i++)
+               fprintf(fp, "%x", (unsigned int) uuid[i]);
+}
+
+void ctf_print_discarded(FILE *fp, struct ctf_stream_definition *stream,
+               int end_stream)
+{
+       fprintf(fp, "[warning] Tracer discarded %" PRIu64 " events %sbetween [",
+               stream->events_discarded,
+               end_stream ? "at end of stream " : "");
+       if (opt_clock_cycles) {
+               ctf_print_timestamp(fp, stream,
+                               stream->prev_cycles_timestamp);
+               fprintf(fp, "] and [");
+               ctf_print_timestamp(fp, stream,
+                               stream->prev_cycles_timestamp_end);
+       } else {
+               ctf_print_timestamp(fp, stream,
+                               stream->prev_real_timestamp);
+               fprintf(fp, "] and [");
+               ctf_print_timestamp(fp, stream,
+                               stream->prev_real_timestamp_end);
+       }
+       fprintf(fp, "] in trace UUID ");
+       print_uuid(fp, stream->stream_class->trace->uuid);
+       if (stream->stream_class->trace->parent.path[0])
+               fprintf(fp, ", at path: \"%s\"",
+                       stream->stream_class->trace->parent.path);
+
+       fprintf(fp, ", within stream id %" PRIu64, stream->stream_id);
+       if (stream->path[0])
+               fprintf(fp, ", at relative path: \"%s\"", stream->path);
+       fprintf(fp, ". ");
+       fprintf(fp, "You should consider recording a new trace with larger "
+               "buffers or with fewer events enabled.\n");
+       fflush(fp);
+}
+
+static
+int ctf_read_event(struct bt_stream_pos *ppos, struct ctf_stream_definition *stream)
 {
        struct ctf_stream_pos *pos =
                container_of(ppos, struct ctf_stream_pos, parent);
@@ -419,27 +473,27 @@ int ctf_read_event(struct stream_pos *ppos, struct ctf_stream_definition *stream
        /* Read event header */
        if (likely(stream->stream_event_header)) {
                struct definition_integer *integer_definition;
-               struct definition *variant;
+               struct bt_definition *variant;
 
                ret = generic_rw(ppos, &stream->stream_event_header->p);
                if (unlikely(ret))
                        goto error;
                /* lookup event id */
-               integer_definition = lookup_integer(&stream->stream_event_header->p, "id", FALSE);
+               integer_definition = bt_lookup_integer(&stream->stream_event_header->p, "id", FALSE);
                if (integer_definition) {
                        id = integer_definition->value._unsigned;
                } else {
                        struct definition_enum *enum_definition;
 
-                       enum_definition = lookup_enum(&stream->stream_event_header->p, "id", FALSE);
+                       enum_definition = bt_lookup_enum(&stream->stream_event_header->p, "id", FALSE);
                        if (enum_definition) {
                                id = enum_definition->integer->value._unsigned;
                        }
                }
 
-               variant = lookup_variant(&stream->stream_event_header->p, "v");
+               variant = bt_lookup_variant(&stream->stream_event_header->p, "v");
                if (variant) {
-                       integer_definition = lookup_integer(variant, "id", FALSE);
+                       integer_definition = bt_lookup_integer(variant, "id", FALSE);
                        if (integer_definition) {
                                id = integer_definition->value._unsigned;
                        }
@@ -448,13 +502,13 @@ int ctf_read_event(struct stream_pos *ppos, struct ctf_stream_definition *stream
 
                /* lookup timestamp */
                stream->has_timestamp = 0;
-               integer_definition = lookup_integer(&stream->stream_event_header->p, "timestamp", FALSE);
+               integer_definition = bt_lookup_integer(&stream->stream_event_header->p, "timestamp", FALSE);
                if (integer_definition) {
                        ctf_update_timestamp(stream, integer_definition);
                        stream->has_timestamp = 1;
                } else {
                        if (variant) {
-                               integer_definition = lookup_integer(variant, "timestamp", FALSE);
+                               integer_definition = bt_lookup_integer(variant, "timestamp", FALSE);
                                if (integer_definition) {
                                        ctf_update_timestamp(stream, integer_definition);
                                        stream->has_timestamp = 1;
@@ -502,7 +556,7 @@ error:
 }
 
 static
-int ctf_write_event(struct stream_pos *pos, struct ctf_stream_definition *stream)
+int ctf_write_event(struct bt_stream_pos *pos, struct ctf_stream_definition *stream)
 {
        struct ctf_stream_declaration *stream_class = stream->stream_class;
        struct ctf_event_definition *event;
@@ -556,7 +610,8 @@ error:
        return ret;
 }
 
-int ctf_init_pos(struct ctf_stream_pos *pos, int fd, int open_flags)
+int ctf_init_pos(struct ctf_stream_pos *pos, struct bt_trace_descriptor *trace,
+               int fd, int open_flags)
 {
        pos->fd = fd;
        if (fd >= 0) {
@@ -574,12 +629,14 @@ int ctf_init_pos(struct ctf_stream_pos *pos, int fd, int open_flags)
                pos->flags = MAP_PRIVATE;
                pos->parent.rw_table = read_dispatch_table;
                pos->parent.event_cb = ctf_read_event;
+               pos->parent.trace = trace;
                break;
        case O_RDWR:
                pos->prot = PROT_WRITE; /* Write has priority */
                pos->flags = MAP_SHARED;
                pos->parent.rw_table = write_dispatch_table;
                pos->parent.event_cb = ctf_write_event;
+               pos->parent.trace = trace;
                if (fd >= 0)
                        ctf_packet_seek(&pos->parent, 0, SEEK_SET);     /* position for write */
                break;
@@ -613,9 +670,9 @@ int ctf_fini_pos(struct ctf_stream_pos *pos)
 
 /*
  * for SEEK_CUR: go to next packet.
- * for SEEK_POS: go to packet numer (index).
+ * for SEEK_SET: go to packet numer (index).
  */
-void ctf_packet_seek(struct stream_pos *stream_pos, size_t index, int whence)
+void ctf_packet_seek(struct bt_stream_pos *stream_pos, size_t index, int whence)
 {
        struct ctf_stream_pos *pos =
                container_of(stream_pos, struct ctf_stream_pos, parent);
@@ -625,6 +682,14 @@ void ctf_packet_seek(struct stream_pos *stream_pos, size_t index, int whence)
        off_t off;
        struct packet_index *packet_index;
 
+       switch (whence) {
+       case SEEK_CUR:
+       case SEEK_SET:  /* Fall-through */
+               break;  /* OK */
+       default:
+               assert(0);
+       }
+
        if (pos->prot == PROT_WRITE && pos->content_size_loc)
                *pos->content_size_loc = pos->offset;
 
@@ -672,6 +737,9 @@ void ctf_packet_seek(struct stream_pos *stream_pos, size_t index, int whence)
                        if (pos->offset == EOF) {
                                return;
                        }
+                       assert(pos->cur_index < pos->packet_cycles_index->len);
+                       assert(pos->cur_index < pos->packet_real_index->len);
+
                        /* For printing discarded event count */
                        packet_index = &g_array_index(pos->packet_cycles_index,
                                        struct packet_index, pos->cur_index);
@@ -709,6 +777,10 @@ void ctf_packet_seek(struct stream_pos *stream_pos, size_t index, int whence)
                        break;
                }
                case SEEK_SET:
+                       if (index >= pos->packet_cycles_index->len) {
+                               pos->offset = EOF;
+                               return;
+                       }
                        packet_index = &g_array_index(pos->packet_cycles_index,
                                        struct packet_index, index);
                        pos->last_events_discarded = packet_index->events_discarded;
@@ -723,43 +795,26 @@ void ctf_packet_seek(struct stream_pos *stream_pos, size_t index, int whence)
                }
                if (pos->cur_index >= pos->packet_real_index->len) {
                        /*
-                        * When a stream reaches the end of the
-                        * file, we need to show the number of
-                        * events discarded ourselves, because
-                        * there is no next event scheduled to
-                        * be printed in the output.
+                        * We need to check if we are in trace read or
+                        * called from packet indexing.  In this last
+                        * case, the collection is not there, so we
+                        * cannot print the timestamps.
                         */
-                       if (file_stream->parent.events_discarded) {
+                       if ((&file_stream->parent)->stream_class->trace->parent.collection) {
                                /*
-                                * We need to check if we are in trace
-                                * read or called from packet indexing.
-                                * In this last case, the collection is
-                                * not there, so we cannot print the
-                                * timestamps.
+                                * When a stream reaches the end of the
+                                * file, we need to show the number of
+                                * events discarded ourselves, because
+                                * there is no next event scheduled to
+                                * be printed in the output.
                                 */
-                               if ((&file_stream->parent)->stream_class->trace->collection) {
+                               if (file_stream->parent.events_discarded) {
                                        fflush(stdout);
-                                       fprintf(stderr, "[warning] Tracer discarded %" PRIu64 " events at end of stream between [",
-                                                       file_stream->parent.events_discarded);
-                                       if (opt_clock_cycles) {
-                                               ctf_print_timestamp(stderr,
-                                                               &file_stream->parent,
-                                                               file_stream->parent.prev_cycles_timestamp);
-                                               fprintf(stderr, "] and [");
-                                               ctf_print_timestamp(stderr, &file_stream->parent,
-                                                               file_stream->parent.prev_cycles_timestamp_end);
-                                       } else {
-                                               ctf_print_timestamp(stderr,
-                                                               &file_stream->parent,
-                                                               file_stream->parent.prev_real_timestamp);
-                                               fprintf(stderr, "] and [");
-                                               ctf_print_timestamp(stderr, &file_stream->parent,
-                                                               file_stream->parent.prev_real_timestamp_end);
-                                       }
-                                       fprintf(stderr, "]. You should consider recording a new trace with larger buffers or with fewer events enabled.\n");
-                                       fflush(stderr);
+                                       ctf_print_discarded(stderr,
+                                               &file_stream->parent,
+                                               1);
+                                       file_stream->parent.events_discarded = 0;
                                }
-                               file_stream->parent.events_discarded = 0;
                        }
                        pos->offset = EOF;
                        return;
@@ -959,7 +1014,7 @@ int ctf_open_trace_metadata_stream_read(struct ctf_trace *td, FILE **fp,
                                        char **buf)
 {
        FILE *in, *out;
-       size_t size;
+       size_t size, buflen;
        int ret;
 
        in = *fp;
@@ -1001,7 +1056,12 @@ int ctf_open_trace_metadata_stream_read(struct ctf_trace *td, FILE **fp,
                perror("Error in fclose");
        }
        /* open for reading */
-       *fp = babeltrace_fmemopen(*buf, strlen(*buf), "rb");
+       buflen = strlen(*buf);
+       if (!buflen) {
+               *fp = NULL;
+               return -ENOENT;
+       }
+       *fp = babeltrace_fmemopen(*buf, buflen, "rb");
        if (!*fp) {
                perror("Metadata fmemopen");
                return -errno;
@@ -1011,7 +1071,7 @@ int ctf_open_trace_metadata_stream_read(struct ctf_trace *td, FILE **fp,
 
 static
 int ctf_open_trace_metadata_read(struct ctf_trace *td,
-               void (*packet_seek)(struct stream_pos *pos, size_t index,
+               void (*packet_seek)(struct bt_stream_pos *pos, size_t index,
                        int whence), FILE *metadata_fp)
 {
        struct ctf_scanner *scanner;
@@ -1058,8 +1118,13 @@ int ctf_open_trace_metadata_read(struct ctf_trace *td,
 
        if (packet_metadata(td, fp)) {
                ret = ctf_open_trace_metadata_stream_read(td, &fp, &buf);
-               if (ret)
+               if (ret) {
+                       /* Warn about empty metadata */
+                       fprintf(stderr, "[warning] Empty metadata.\n");
                        goto end_packet_read;
+               }
+               td->metadata_string = buf;
+               td->metadata_packetized = 1;
        } else {
                unsigned int major, minor;
                ssize_t nr_items;
@@ -1118,7 +1183,6 @@ end_packet_read:
                        perror("Error on fclose");
                }
        }
-       free(buf);
 end_stream:
        if (metadata_stream->pos.fd >= 0) {
                closeret = close(metadata_stream->pos.fd);
@@ -1140,7 +1204,7 @@ struct ctf_event_definition *create_event_definitions(struct ctf_trace *td,
        struct ctf_event_definition *stream_event = g_new0(struct ctf_event_definition, 1);
 
        if (event->context_decl) {
-               struct definition *definition =
+               struct bt_definition *definition =
                        event->context_decl->p.definition_new(&event->context_decl->p,
                                stream->parent_def_scope, 0, 0, "event.context");
                if (!definition) {
@@ -1151,7 +1215,7 @@ struct ctf_event_definition *create_event_definitions(struct ctf_trace *td,
                stream->parent_def_scope = stream_event->event_context->p.scope;
        }
        if (event->fields_decl) {
-               struct definition *definition =
+               struct bt_definition *definition =
                        event->fields_decl->p.definition_new(&event->fields_decl->p,
                                stream->parent_def_scope, 0, 0, "event.fields");
                if (!definition) {
@@ -1166,9 +1230,11 @@ struct ctf_event_definition *create_event_definitions(struct ctf_trace *td,
 
 error:
        if (stream_event->event_fields)
-               definition_unref(&stream_event->event_fields->p);
+               bt_definition_unref(&stream_event->event_fields->p);
        if (stream_event->event_context)
-               definition_unref(&stream_event->event_context->p);
+               bt_definition_unref(&stream_event->event_context->p);
+       fprintf(stderr, "[error] Unable to create event definition for event \"%s\".\n",
+               g_quark_to_string(event->name));
        return NULL;
 }
 
@@ -1185,7 +1251,7 @@ int create_stream_definitions(struct ctf_trace *td, struct ctf_stream_definition
        stream_class = stream->stream_class;
 
        if (stream_class->packet_context_decl) {
-               struct definition *definition =
+               struct bt_definition *definition =
                        stream_class->packet_context_decl->p.definition_new(&stream_class->packet_context_decl->p,
                                stream->parent_def_scope, 0, 0, "stream.packet.context");
                if (!definition) {
@@ -1197,7 +1263,7 @@ int create_stream_definitions(struct ctf_trace *td, struct ctf_stream_definition
                stream->parent_def_scope = stream->stream_packet_context->p.scope;
        }
        if (stream_class->event_header_decl) {
-               struct definition *definition =
+               struct bt_definition *definition =
                        stream_class->event_header_decl->p.definition_new(&stream_class->event_header_decl->p,
                                stream->parent_def_scope, 0, 0, "stream.event.header");
                if (!definition) {
@@ -1209,7 +1275,7 @@ int create_stream_definitions(struct ctf_trace *td, struct ctf_stream_definition
                stream->parent_def_scope = stream->stream_event_header->p.scope;
        }
        if (stream_class->event_context_decl) {
-               struct definition *definition =
+               struct bt_definition *definition =
                        stream_class->event_context_decl->p.definition_new(&stream_class->event_context_decl->p,
                                stream->parent_def_scope, 0, 0, "stream.event.context");
                if (!definition) {
@@ -1229,8 +1295,10 @@ int create_stream_definitions(struct ctf_trace *td, struct ctf_stream_definition
                if (!event)
                        continue;
                stream_event = create_event_definitions(td, stream, event);
-               if (!stream_event)
+               if (!stream_event) {
+                       ret = -EINVAL;
                        goto error_event;
+               }
                g_ptr_array_index(stream->events_by_id, i) = stream_event;
        }
        return 0;
@@ -1244,242 +1312,332 @@ error_event:
        g_ptr_array_free(stream->events_by_id, TRUE);
 error:
        if (stream->stream_event_context)
-               definition_unref(&stream->stream_event_context->p);
+               bt_definition_unref(&stream->stream_event_context->p);
        if (stream->stream_event_header)
-               definition_unref(&stream->stream_event_header->p);
+               bt_definition_unref(&stream->stream_event_header->p);
        if (stream->stream_packet_context)
-               definition_unref(&stream->stream_packet_context->p);
+               bt_definition_unref(&stream->stream_packet_context->p);
+       fprintf(stderr, "[error] Unable to create stream (%" PRIu64 ") definitions: %s\n",
+               stream_class->stream_id, strerror(-ret));
        return ret;
 }
 
-
 static
-int create_stream_packet_index(struct ctf_trace *td,
-                              struct ctf_file_stream *file_stream)
+int stream_assign_class(struct ctf_trace *td,
+               struct ctf_file_stream *file_stream,
+               uint64_t stream_id)
 {
        struct ctf_stream_declaration *stream;
-       int len_index;
-       struct ctf_stream_pos *pos;
-       struct stat filestats;
-       struct packet_index packet_index;
-       int first_packet = 1;
        int ret;
 
-       pos = &file_stream->pos;
-
-       ret = fstat(pos->fd, &filestats);
-       if (ret < 0)
+       file_stream->parent.stream_id = stream_id;
+       if (stream_id >= td->streams->len) {
+               fprintf(stderr, "[error] Stream %" PRIu64 " is not declared in metadata.\n", stream_id);
+               return -EINVAL;
+       }
+       stream = g_ptr_array_index(td->streams, stream_id);
+       if (!stream) {
+               fprintf(stderr, "[error] Stream %" PRIu64 " is not declared in metadata.\n", stream_id);
+               return -EINVAL;
+       }
+       file_stream->parent.stream_class = stream;
+       ret = create_stream_definitions(td, &file_stream->parent);
+       if (ret)
                return ret;
+       return 0;
+}
 
-       if (filestats.st_size < MAX_PACKET_HEADER_LEN / CHAR_BIT)
-               return -EINVAL;
+static
+int create_stream_one_packet_index(struct ctf_stream_pos *pos,
+                       struct ctf_trace *td,
+                       struct ctf_file_stream *file_stream,
+                       size_t filesize)
+{
+       struct packet_index packet_index;
+       uint64_t stream_id = 0;
+       uint64_t packet_map_len = DEFAULT_HEADER_LEN, tmp_map_len;
+       int first_packet = 0;
+       int len_index;
+       int ret;
 
-       for (pos->mmap_offset = 0; pos->mmap_offset < filestats.st_size; ) {
-               uint64_t stream_id = 0;
+begin:
+       if (!pos->mmap_offset) {
+               first_packet = 1;
+       }
 
-               if (pos->base_mma) {
-                       /* unmap old base */
-                       ret = munmap_align(pos->base_mma);
-                       if (ret) {
-                               fprintf(stderr, "[error] Unable to unmap old base: %s.\n",
-                                       strerror(errno));
-                               return ret;
-                       }
-                       pos->base_mma = NULL;
+       if (filesize - pos->mmap_offset < (packet_map_len >> LOG2_CHAR_BIT)) {
+               packet_map_len = (filesize - pos->mmap_offset) << LOG2_CHAR_BIT;
+       }
+
+       if (pos->base_mma) {
+               /* unmap old base */
+               ret = munmap_align(pos->base_mma);
+               if (ret) {
+                       fprintf(stderr, "[error] Unable to unmap old base: %s.\n",
+                               strerror(errno));
+                       return ret;
                }
-               /* map new base. Need mapping length from header. */
-               pos->base_mma = mmap_align(MAX_PACKET_HEADER_LEN / CHAR_BIT, PROT_READ,
-                                MAP_PRIVATE, pos->fd, pos->mmap_offset);
-               assert(pos->base_mma != MAP_FAILED);
-               pos->content_size = MAX_PACKET_HEADER_LEN;      /* Unknown at this point */
-               pos->packet_size = MAX_PACKET_HEADER_LEN;       /* Unknown at this point */
-               pos->offset = 0;        /* Position of the packet header */
-
-               packet_index.offset = pos->mmap_offset;
-               packet_index.content_size = 0;
-               packet_index.packet_size = 0;
-               packet_index.timestamp_begin = 0;
-               packet_index.timestamp_end = 0;
-               packet_index.events_discarded = 0;
-               packet_index.events_discarded_len = 0;
-
-               /* read and check header, set stream id (and check) */
-               if (file_stream->parent.trace_packet_header) {
-                       /* Read packet header */
-                       ret = generic_rw(&pos->parent, &file_stream->parent.trace_packet_header->p);
-                       if (ret)
-                               return ret;
-                       len_index = struct_declaration_lookup_field_index(file_stream->parent.trace_packet_header->declaration, g_quark_from_static_string("magic"));
-                       if (len_index >= 0) {
-                               struct definition *field;
-                               uint64_t magic;
-
-                               field = struct_definition_get_field_from_index(file_stream->parent.trace_packet_header, len_index);
-                               magic = get_unsigned_int(field);
-                               if (magic != CTF_MAGIC) {
-                                       fprintf(stderr, "[error] Invalid magic number 0x%" PRIX64 " at packet %u (file offset %zd).\n",
-                                                       magic,
-                                                       file_stream->pos.packet_cycles_index->len,
-                                                       (ssize_t) pos->mmap_offset);
-                                       return -EINVAL;
-                               }
+               pos->base_mma = NULL;
+       }
+       /* map new base. Need mapping length from header. */
+       pos->base_mma = mmap_align(packet_map_len >> LOG2_CHAR_BIT, PROT_READ,
+                        MAP_PRIVATE, pos->fd, pos->mmap_offset);
+       assert(pos->base_mma != MAP_FAILED);
+       /*
+        * Use current mapping size as temporary content and packet
+        * size.
+        */
+       pos->content_size = packet_map_len;
+       pos->packet_size = packet_map_len;
+       pos->offset = 0;        /* Position of the packet header */
+
+       packet_index.offset = pos->mmap_offset;
+       packet_index.content_size = 0;
+       packet_index.packet_size = 0;
+       packet_index.timestamp_begin = 0;
+       packet_index.timestamp_end = 0;
+       packet_index.events_discarded = 0;
+       packet_index.events_discarded_len = 0;
+
+       /* read and check header, set stream id (and check) */
+       if (file_stream->parent.trace_packet_header) {
+               /* Read packet header */
+               ret = generic_rw(&pos->parent, &file_stream->parent.trace_packet_header->p);
+               if (ret) {
+                       if (ret == -EFAULT)
+                               goto retry;
+                       fprintf(stderr, "[error] Unable to read packet header: %s\n", strerror(-ret));
+                       return ret;
+               }
+               len_index = bt_struct_declaration_lookup_field_index(file_stream->parent.trace_packet_header->declaration, g_quark_from_static_string("magic"));
+               if (len_index >= 0) {
+                       struct bt_definition *field;
+                       uint64_t magic;
+
+                       field = bt_struct_definition_get_field_from_index(file_stream->parent.trace_packet_header, len_index);
+                       magic = bt_get_unsigned_int(field);
+                       if (magic != CTF_MAGIC) {
+                               fprintf(stderr, "[error] Invalid magic number 0x%" PRIX64 " at packet %u (file offset %zd).\n",
+                                               magic,
+                                               file_stream->pos.packet_cycles_index->len,
+                                               (ssize_t) pos->mmap_offset);
+                               return -EINVAL;
                        }
+               }
 
-                       /* check uuid */
-                       len_index = struct_declaration_lookup_field_index(file_stream->parent.trace_packet_header->declaration, g_quark_from_static_string("uuid"));
-                       if (len_index >= 0) {
-                               struct definition_array *defarray;
-                               struct definition *field;
-                               uint64_t i;
-                               uint8_t uuidval[BABELTRACE_UUID_LEN];
+               /* check uuid */
+               len_index = bt_struct_declaration_lookup_field_index(file_stream->parent.trace_packet_header->declaration, g_quark_from_static_string("uuid"));
+               if (len_index >= 0) {
+                       struct definition_array *defarray;
+                       struct bt_definition *field;
+                       uint64_t i;
+                       uint8_t uuidval[BABELTRACE_UUID_LEN];
 
-                               field = struct_definition_get_field_from_index(file_stream->parent.trace_packet_header, len_index);
-                               assert(field->declaration->id == CTF_TYPE_ARRAY);
-                               defarray = container_of(field, struct definition_array, p);
-                               assert(array_len(defarray) == BABELTRACE_UUID_LEN);
+                       field = bt_struct_definition_get_field_from_index(file_stream->parent.trace_packet_header, len_index);
+                       assert(field->declaration->id == CTF_TYPE_ARRAY);
+                       defarray = container_of(field, struct definition_array, p);
+                       assert(bt_array_len(defarray) == BABELTRACE_UUID_LEN);
 
-                               for (i = 0; i < BABELTRACE_UUID_LEN; i++) {
-                                       struct definition *elem;
+                       for (i = 0; i < BABELTRACE_UUID_LEN; i++) {
+                               struct bt_definition *elem;
 
-                                       elem = array_index(defarray, i);
-                                       uuidval[i] = get_unsigned_int(elem);
-                               }
-                               ret = babeltrace_uuid_compare(td->uuid, uuidval);
-                               if (ret) {
-                                       fprintf(stderr, "[error] Unique Universal Identifiers do not match.\n");
-                                       return -EINVAL;
-                               }
+                               elem = bt_array_index(defarray, i);
+                               uuidval[i] = bt_get_unsigned_int(elem);
+                       }
+                       ret = babeltrace_uuid_compare(td->uuid, uuidval);
+                       if (ret) {
+                               fprintf(stderr, "[error] Unique Universal Identifiers do not match.\n");
+                               return -EINVAL;
                        }
+               }
 
+               len_index = bt_struct_declaration_lookup_field_index(file_stream->parent.trace_packet_header->declaration, g_quark_from_static_string("stream_id"));
+               if (len_index >= 0) {
+                       struct bt_definition *field;
 
-                       len_index = struct_declaration_lookup_field_index(file_stream->parent.trace_packet_header->declaration, g_quark_from_static_string("stream_id"));
-                       if (len_index >= 0) {
-                               struct definition *field;
+                       field = bt_struct_definition_get_field_from_index(file_stream->parent.trace_packet_header, len_index);
+                       stream_id = bt_get_unsigned_int(field);
+               }
+       }
 
-                               field = struct_definition_get_field_from_index(file_stream->parent.trace_packet_header, len_index);
-                               stream_id = get_unsigned_int(field);
-                       }
+       if (!first_packet && file_stream->parent.stream_id != stream_id) {
+               fprintf(stderr, "[error] Stream ID is changing within a stream: expecting %" PRIu64 ", but packet has %" PRIu64 "\n",
+                       stream_id,
+                       file_stream->parent.stream_id);
+               return -EINVAL;
+       }
+       if (first_packet) {
+               ret = stream_assign_class(td, file_stream, stream_id);
+               if (ret)
+                       return ret;
+       }
+
+       if (file_stream->parent.stream_packet_context) {
+               /* Read packet context */
+               ret = generic_rw(&pos->parent, &file_stream->parent.stream_packet_context->p);
+               if (ret) {
+                       if (ret == -EFAULT)
+                               goto retry;
+                       fprintf(stderr, "[error] Unable to read packet context: %s\n", strerror(-ret));
+                       return ret;
                }
+               /* read content size from header */
+               len_index = bt_struct_declaration_lookup_field_index(file_stream->parent.stream_packet_context->declaration, g_quark_from_static_string("content_size"));
+               if (len_index >= 0) {
+                       struct bt_definition *field;
 
-               if (!first_packet && file_stream->parent.stream_id != stream_id) {
-                       fprintf(stderr, "[error] Stream ID is changing within a stream.\n");
-                       return -EINVAL;
+                       field = bt_struct_definition_get_field_from_index(file_stream->parent.stream_packet_context, len_index);
+                       packet_index.content_size = bt_get_unsigned_int(field);
+               } else {
+                       /* Use file size for packet size */
+                       packet_index.content_size = filesize * CHAR_BIT;
                }
-               if (first_packet) {
-                       file_stream->parent.stream_id = stream_id;
-                       if (stream_id >= td->streams->len) {
-                               fprintf(stderr, "[error] Stream %" PRIu64 " is not declared in metadata.\n", stream_id);
-                               return -EINVAL;
+
+               /* read packet size from header */
+               len_index = bt_struct_declaration_lookup_field_index(file_stream->parent.stream_packet_context->declaration, g_quark_from_static_string("packet_size"));
+               if (len_index >= 0) {
+                       struct bt_definition *field;
+
+                       field = bt_struct_definition_get_field_from_index(file_stream->parent.stream_packet_context, len_index);
+                       packet_index.packet_size = bt_get_unsigned_int(field);
+               } else {
+                       /* Use content size if non-zero, else file size */
+                       packet_index.packet_size = packet_index.content_size ? : filesize * CHAR_BIT;
+               }
+
+               /* read timestamp begin from header */
+               len_index = bt_struct_declaration_lookup_field_index(file_stream->parent.stream_packet_context->declaration, g_quark_from_static_string("timestamp_begin"));
+               if (len_index >= 0) {
+                       struct bt_definition *field;
+
+                       field = bt_struct_definition_get_field_from_index(file_stream->parent.stream_packet_context, len_index);
+                       packet_index.timestamp_begin = bt_get_unsigned_int(field);
+                       if (file_stream->parent.stream_class->trace->parent.collection) {
+                               packet_index.timestamp_begin =
+                                       ctf_get_real_timestamp(
+                                               &file_stream->parent,
+                                               packet_index.timestamp_begin);
                        }
-                       stream = g_ptr_array_index(td->streams, stream_id);
-                       if (!stream) {
-                               fprintf(stderr, "[error] Stream %" PRIu64 " is not declared in metadata.\n", stream_id);
-                               return -EINVAL;
+               }
+
+               /* read timestamp end from header */
+               len_index = bt_struct_declaration_lookup_field_index(file_stream->parent.stream_packet_context->declaration, g_quark_from_static_string("timestamp_end"));
+               if (len_index >= 0) {
+                       struct bt_definition *field;
+
+                       field = bt_struct_definition_get_field_from_index(file_stream->parent.stream_packet_context, len_index);
+                       packet_index.timestamp_end = bt_get_unsigned_int(field);
+                       if (file_stream->parent.stream_class->trace->parent.collection) {
+                               packet_index.timestamp_end =
+                                       ctf_get_real_timestamp(
+                                               &file_stream->parent,
+                                               packet_index.timestamp_end);
                        }
-                       file_stream->parent.stream_class = stream;
-                       ret = create_stream_definitions(td, &file_stream->parent);
-                       if (ret)
-                               return ret;
                }
-               first_packet = 0;
 
-               if (file_stream->parent.stream_packet_context) {
-                       /* Read packet context */
-                       ret = generic_rw(&pos->parent, &file_stream->parent.stream_packet_context->p);
-                       if (ret)
-                               return ret;
-                       /* read content size from header */
-                       len_index = struct_declaration_lookup_field_index(file_stream->parent.stream_packet_context->declaration, g_quark_from_static_string("content_size"));
-                       if (len_index >= 0) {
-                               struct definition *field;
+               /* read events discarded from header */
+               len_index = bt_struct_declaration_lookup_field_index(file_stream->parent.stream_packet_context->declaration, g_quark_from_static_string("events_discarded"));
+               if (len_index >= 0) {
+                       struct bt_definition *field;
 
-                               field = struct_definition_get_field_from_index(file_stream->parent.stream_packet_context, len_index);
-                               packet_index.content_size = get_unsigned_int(field);
-                       } else {
-                               /* Use file size for packet size */
-                               packet_index.content_size = filestats.st_size * CHAR_BIT;
-                       }
+                       field = bt_struct_definition_get_field_from_index(file_stream->parent.stream_packet_context, len_index);
+                       packet_index.events_discarded = bt_get_unsigned_int(field);
+                       packet_index.events_discarded_len = bt_get_int_len(field);
+               }
+       } else {
+               /* Use file size for packet size */
+               packet_index.content_size = filesize * CHAR_BIT;
+               /* Use content size if non-zero, else file size */
+               packet_index.packet_size = packet_index.content_size ? : filesize * CHAR_BIT;
+       }
 
-                       /* read packet size from header */
-                       len_index = struct_declaration_lookup_field_index(file_stream->parent.stream_packet_context->declaration, g_quark_from_static_string("packet_size"));
-                       if (len_index >= 0) {
-                               struct definition *field;
+       /* Validate content size and packet size values */
+       if (packet_index.content_size > packet_index.packet_size) {
+               fprintf(stderr, "[error] Content size (%" PRIu64 " bits) is larger than packet size (%" PRIu64 " bits).\n",
+                       packet_index.content_size, packet_index.packet_size);
+               return -EINVAL;
+       }
 
-                               field = struct_definition_get_field_from_index(file_stream->parent.stream_packet_context, len_index);
-                               packet_index.packet_size = get_unsigned_int(field);
-                       } else {
-                               /* Use content size if non-zero, else file size */
-                               packet_index.packet_size = packet_index.content_size ? : filestats.st_size * CHAR_BIT;
-                       }
+       if (packet_index.packet_size > ((uint64_t) filesize - packet_index.offset) * CHAR_BIT) {
+               fprintf(stderr, "[error] Packet size (%" PRIu64 " bits) is larger than remaining file size (%" PRIu64 " bits).\n",
+                       packet_index.packet_size, ((uint64_t) filesize - packet_index.offset) * CHAR_BIT);
+               return -EINVAL;
+       }
 
-                       /* read timestamp begin from header */
-                       len_index = struct_declaration_lookup_field_index(file_stream->parent.stream_packet_context->declaration, g_quark_from_static_string("timestamp_begin"));
-                       if (len_index >= 0) {
-                               struct definition *field;
-
-                               field = struct_definition_get_field_from_index(file_stream->parent.stream_packet_context, len_index);
-                               packet_index.timestamp_begin = get_unsigned_int(field);
-                               if (file_stream->parent.stream_class->trace->collection) {
-                                       packet_index.timestamp_begin =
-                                               ctf_get_real_timestamp(
-                                                       &file_stream->parent,
-                                                       packet_index.timestamp_begin);
-                               }
-                       }
+       /* Save position after header and context */
+       packet_index.data_offset = pos->offset;
 
-                       /* read timestamp end from header */
-                       len_index = struct_declaration_lookup_field_index(file_stream->parent.stream_packet_context->declaration, g_quark_from_static_string("timestamp_end"));
-                       if (len_index >= 0) {
-                               struct definition *field;
-
-                               field = struct_definition_get_field_from_index(file_stream->parent.stream_packet_context, len_index);
-                               packet_index.timestamp_end = get_unsigned_int(field);
-                               if (file_stream->parent.stream_class->trace->collection) {
-                                       packet_index.timestamp_end =
-                                               ctf_get_real_timestamp(
-                                                       &file_stream->parent,
-                                                       packet_index.timestamp_end);
-                               }
-                       }
+       /* add index to packet array */
+       g_array_append_val(file_stream->pos.packet_cycles_index, packet_index);
 
-                       /* read events discarded from header */
-                       len_index = struct_declaration_lookup_field_index(file_stream->parent.stream_packet_context->declaration, g_quark_from_static_string("events_discarded"));
-                       if (len_index >= 0) {
-                               struct definition *field;
+       pos->mmap_offset += packet_index.packet_size >> LOG2_CHAR_BIT;
 
-                               field = struct_definition_get_field_from_index(file_stream->parent.stream_packet_context, len_index);
-                               packet_index.events_discarded = get_unsigned_int(field);
-                               packet_index.events_discarded_len = get_int_len(field);
-                       }
-               } else {
-                       /* Use file size for packet size */
-                       packet_index.content_size = filestats.st_size * CHAR_BIT;
-                       /* Use content size if non-zero, else file size */
-                       packet_index.packet_size = packet_index.content_size ? : filestats.st_size * CHAR_BIT;
-               }
+       return 0;
 
-               /* Validate content size and packet size values */
-               if (packet_index.content_size > packet_index.packet_size) {
-                       fprintf(stderr, "[error] Content size (%" PRIu64 " bits) is larger than packet size (%" PRIu64 " bits).\n",
-                               packet_index.content_size, packet_index.packet_size);
-                       return -EINVAL;
-               }
+       /* Retry with larger mapping */
+retry:
+       if (packet_map_len == ((filesize - pos->mmap_offset) << LOG2_CHAR_BIT)) {
+               /*
+                * Reached EOF, but still expecting header/context data.
+                */
+               fprintf(stderr, "[error] Reached end of file, but still expecting header or context fields.\n");
+               return -EFAULT;
+       }
+       /* Double the mapping len, and retry */
+       tmp_map_len = packet_map_len << 1;
+       if (tmp_map_len >> 1 != packet_map_len) {
+               /* Overflow */
+               fprintf(stderr, "[error] Packet mapping length overflow\n");
+               return -EFAULT;
+       }
+       packet_map_len = tmp_map_len;
+       goto begin;
+}
 
-               if (packet_index.packet_size > ((uint64_t)filestats.st_size - packet_index.offset) * CHAR_BIT) {
-                       fprintf(stderr, "[error] Packet size (%" PRIu64 " bits) is larger than remaining file size (%" PRIu64 " bits).\n",
-                               packet_index.packet_size, ((uint64_t)filestats.st_size - packet_index.offset) * CHAR_BIT);
-                       return -EINVAL;
-               }
+static
+int create_stream_packet_index(struct ctf_trace *td,
+                       struct ctf_file_stream *file_stream)
+{
+       struct ctf_stream_pos *pos;
+       struct stat filestats;
+       int ret;
 
-               /* Save position after header and context */
-               packet_index.data_offset = pos->offset;
+       pos = &file_stream->pos;
 
-               /* add index to packet array */
-               g_array_append_val(file_stream->pos.packet_cycles_index, packet_index);
+       ret = fstat(pos->fd, &filestats);
+       if (ret < 0)
+               return ret;
 
-               pos->mmap_offset += packet_index.packet_size / CHAR_BIT;
+       /* Deal with empty files */
+       if (!filestats.st_size) {
+               if (file_stream->parent.trace_packet_header
+                               || file_stream->parent.stream_packet_context) {
+                       /*
+                        * We expect a trace packet header and/or stream packet
+                        * context. Since a trace needs to have at least one
+                        * packet, empty files are therefore not accepted.
+                        */
+                       fprintf(stderr, "[error] Encountered an empty file, but expecting a trace packet header.\n");
+                       return -EINVAL;
+               } else {
+                       /*
+                        * Without trace packet header nor stream packet
+                        * context, a one-packet trace can indeed be empty. This
+                        * is only valid if there is only one stream class: 0.
+                        */
+                       ret = stream_assign_class(td, file_stream, 0);
+                       if (ret)
+                               return ret;
+                       return 0;
+               }
        }
 
+       for (pos->mmap_offset = 0; pos->mmap_offset < filestats.st_size; ) {
+               ret = create_stream_one_packet_index(pos, td, file_stream,
+                       filestats.st_size);
+               if (ret)
+                       return ret;
+       }
        return 0;
 }
 
@@ -1489,7 +1647,7 @@ int create_trace_definitions(struct ctf_trace *td, struct ctf_stream_definition
        int ret;
 
        if (td->packet_header_decl) {
-               struct definition *definition =
+               struct bt_definition *definition =
                        td->packet_header_decl->p.definition_new(&td->packet_header_decl->p,
                                stream->parent_def_scope, 0, 0, "trace.packet.header");
                if (!definition) {
@@ -1504,6 +1662,7 @@ int create_trace_definitions(struct ctf_trace *td, struct ctf_stream_definition
        return 0;
 
 error:
+       fprintf(stderr, "[error] Unable to create trace definitions: %s\n", strerror(-ret));
        return ret;
 }
 
@@ -1513,7 +1672,7 @@ error:
  */
 static
 int ctf_open_file_stream_read(struct ctf_trace *td, const char *path, int flags,
-               void (*packet_seek)(struct stream_pos *pos, size_t index,
+               void (*packet_seek)(struct bt_stream_pos *pos, size_t index,
                        int whence))
 {
        int ret, fd, closeret;
@@ -1542,6 +1701,9 @@ int ctf_open_file_stream_read(struct ctf_trace *td, const char *path, int flags,
        file_stream = g_new0(struct ctf_file_stream, 1);
        file_stream->pos.last_offset = LAST_OFFSET_POISON;
 
+       strncpy(file_stream->parent.path, path, PATH_MAX);
+       file_stream->parent.path[PATH_MAX - 1] = '\0';
+
        if (packet_seek) {
                file_stream->pos.packet_seek = packet_seek;
        } else {
@@ -1550,7 +1712,7 @@ int ctf_open_file_stream_read(struct ctf_trace *td, const char *path, int flags,
                goto error_def;
        }
 
-       ret = ctf_init_pos(&file_stream->pos, fd, flags);
+       ret = ctf_init_pos(&file_stream->pos, &td->parent, fd, flags);
        if (ret)
                goto error_def;
        ret = create_trace_definitions(td, &file_stream->parent);
@@ -1559,10 +1721,12 @@ int ctf_open_file_stream_read(struct ctf_trace *td, const char *path, int flags,
        /*
         * For now, only a single clock per trace is supported.
         */
-       file_stream->parent.current_clock = td->single_clock;
+       file_stream->parent.current_clock = td->parent.single_clock;
        ret = create_stream_packet_index(td, file_stream);
-       if (ret)
+       if (ret) {
+               fprintf(stderr, "[error] Stream index creation error.\n");
                goto error_index;
+       }
        /* Add stream file to stream class */
        g_ptr_array_add(file_stream->parent.stream_class->streams,
                        &file_stream->parent);
@@ -1570,7 +1734,7 @@ int ctf_open_file_stream_read(struct ctf_trace *td, const char *path, int flags,
 
 error_index:
        if (file_stream->parent.trace_packet_header)
-               definition_unref(&file_stream->parent.trace_packet_header->p);
+               bt_definition_unref(&file_stream->parent.trace_packet_header->p);
 error_def:
        closeret = ctf_fini_pos(&file_stream->pos);
        if (closeret) {
@@ -1590,7 +1754,7 @@ error:
 static
 int ctf_open_trace_read(struct ctf_trace *td,
                const char *path, int flags,
-               void (*packet_seek)(struct stream_pos *pos, size_t index,
+               void (*packet_seek)(struct bt_stream_pos *pos, size_t index,
                        int whence), FILE *metadata_fp)
 {
        int ret, closeret;
@@ -1615,8 +1779,8 @@ int ctf_open_trace_read(struct ctf_trace *td,
                ret = -errno;
                goto error_dirfd;
        }
-       strncpy(td->path, path, sizeof(td->path));
-       td->path[sizeof(td->path) - 1] = '\0';
+       strncpy(td->parent.path, path, sizeof(td->parent.path));
+       td->parent.path[sizeof(td->parent.path) - 1] = '\0';
 
        /*
         * Keep the metadata file separate.
@@ -1685,8 +1849,8 @@ error:
  * since the index creation read it entirely.
  */
 static
-struct trace_descriptor *ctf_open_trace(const char *path, int flags,
-               void (*packet_seek)(struct stream_pos *pos, size_t index,
+struct bt_trace_descriptor *ctf_open_trace(const char *path, int flags,
+               void (*packet_seek)(struct bt_stream_pos *pos, size_t index,
                        int whence), FILE *metadata_fp)
 {
        struct ctf_trace *td;
@@ -1724,9 +1888,9 @@ error:
        return NULL;
 }
 
-
+static
 void ctf_init_mmap_pos(struct ctf_stream_pos *pos,
-               struct mmap_stream *mmap_info)
+               struct bt_mmap_stream *mmap_info)
 {
        pos->mmap_offset = 0;
        pos->packet_size = 0;
@@ -1775,8 +1939,8 @@ end:
 
 static
 int ctf_open_mmap_stream_read(struct ctf_trace *td,
-               struct mmap_stream *mmap_info,
-               void (*packet_seek)(struct stream_pos *pos, size_t index,
+               struct bt_mmap_stream *mmap_info,
+               void (*packet_seek)(struct bt_stream_pos *pos, size_t index,
                        int whence))
 {
        int ret;
@@ -1800,7 +1964,7 @@ int ctf_open_mmap_stream_read(struct ctf_trace *td,
        /*
         * For now, only a single clock per trace is supported.
         */
-       file_stream->parent.current_clock = td->single_clock;
+       file_stream->parent.current_clock = td->parent.single_clock;
 
        /* Add stream file to stream class */
        g_ptr_array_add(file_stream->parent.stream_class->streams,
@@ -1809,20 +1973,21 @@ int ctf_open_mmap_stream_read(struct ctf_trace *td,
 
 error_index:
        if (file_stream->parent.trace_packet_header)
-               definition_unref(&file_stream->parent.trace_packet_header->p);
+               bt_definition_unref(&file_stream->parent.trace_packet_header->p);
 error_def:
        g_free(file_stream);
        return ret;
 }
 
+static
 int ctf_open_mmap_trace_read(struct ctf_trace *td,
-               struct mmap_stream_list *mmap_list,
-               void (*packet_seek)(struct stream_pos *pos, size_t index,
+               struct bt_mmap_stream_list *mmap_list,
+               void (*packet_seek)(struct bt_stream_pos *pos, size_t index,
                        int whence),
                FILE *metadata_fp)
 {
        int ret;
-       struct mmap_stream *mmap_info;
+       struct bt_mmap_stream *mmap_info;
 
        ret = ctf_open_trace_metadata_read(td, ctf_packet_seek, metadata_fp);
        if (ret) {
@@ -1848,9 +2013,9 @@ error:
 }
 
 static
-struct trace_descriptor *ctf_open_mmap_trace(
-               struct mmap_stream_list *mmap_list,
-               void (*packet_seek)(struct stream_pos *pos, size_t index,
+struct bt_trace_descriptor *ctf_open_mmap_trace(
+               struct bt_mmap_stream_list *mmap_list,
+               void (*packet_seek)(struct bt_stream_pos *pos, size_t index,
                        int whence),
                FILE *metadata_fp)
 {
@@ -1880,7 +2045,7 @@ error:
 }
 
 static
-int ctf_convert_index_timestamp(struct trace_descriptor *tdp)
+int ctf_convert_index_timestamp(struct bt_trace_descriptor *tdp)
 {
        int i, j, k;
        struct ctf_trace *td = container_of(tdp, struct ctf_trace, parent);
@@ -1948,7 +2113,7 @@ int ctf_close_file_stream(struct ctf_file_stream *file_stream)
 }
 
 static
-int ctf_close_trace(struct trace_descriptor *tdp)
+int ctf_close_trace(struct bt_trace_descriptor *tdp)
 {
        struct ctf_trace *td = container_of(tdp, struct ctf_trace, parent);
        int ret;
@@ -1984,28 +2149,29 @@ int ctf_close_trace(struct trace_descriptor *tdp)
                perror("Error closedir");
                return ret;
        }
+       free(td->metadata_string);
        g_free(td);
        return 0;
 }
 
 static
-void ctf_set_context(struct trace_descriptor *descriptor,
+void ctf_set_context(struct bt_trace_descriptor *descriptor,
                struct bt_context *ctx)
 {
        struct ctf_trace *td = container_of(descriptor, struct ctf_trace,
                        parent);
 
-       td->ctx = ctx;
+       td->parent.ctx = ctx;
 }
 
 static
-void ctf_set_handle(struct trace_descriptor *descriptor,
+void ctf_set_handle(struct bt_trace_descriptor *descriptor,
                struct bt_trace_handle *handle)
 {
        struct ctf_trace *td = container_of(descriptor, struct ctf_trace,
                        parent);
 
-       td->handle = handle;
+       td->parent.handle = handle;
 }
 
 static
index 201b2b3692850dd739188a54c148063d3d5a31d2..4906c02aa9171ec6674b11b679ef74886e045e8f 100644 (file)
@@ -40,13 +40,13 @@ uint64_t ctf_get_real_timestamp(struct ctf_stream_definition *stream,
 {
        uint64_t ts_nsec;
        struct ctf_trace *trace = stream->stream_class->trace;
-       struct trace_collection *tc = trace->collection;
+       struct trace_collection *tc = trace->parent.collection;
        uint64_t tc_offset;
 
        if (tc->clock_use_offset_avg)
                tc_offset = tc->single_clock_offset_avg;
        else
-               tc_offset = trace->single_clock->offset;
+               tc_offset = trace->parent.single_clock->offset;
 
        ts_nsec = clock_cycles_to_ns(stream->current_clock, timestamp);
        ts_nsec += tc_offset;   /* Add offset */
index 182d0dedf68a43b440130eda4d28b7debc01d974..af376a4412b8c8b0c807cf432748302cda5301a8 100644 (file)
  */
 __thread int bt_ctf_last_field_error = 0;
 
-const struct definition *bt_ctf_get_top_level_scope(const struct bt_ctf_event *ctf_event,
+const struct bt_definition *bt_ctf_get_top_level_scope(const struct bt_ctf_event *ctf_event,
                enum bt_ctf_scope scope)
 {
-       const struct definition *tmp = NULL;
+       const struct bt_definition *tmp = NULL;
        const struct ctf_event_definition *event;
 
        if (!ctf_event)
@@ -96,17 +96,17 @@ error:
        return NULL;
 }
 
-const struct definition *bt_ctf_get_field(const struct bt_ctf_event *ctf_event,
-               const struct definition *scope,
+const struct bt_definition *bt_ctf_get_field(const struct bt_ctf_event *ctf_event,
+               const struct bt_definition *scope,
                const char *field)
 {
-       const struct definition *def;
+       const struct bt_definition *def;
        char *field_underscore;
 
        if (!ctf_event || !scope || !field)
                return NULL;
 
-       def = lookup_definition(scope, field);
+       def = bt_lookup_definition(scope, field);
        /*
         * optionally a field can have an underscore prefix, try
         * to lookup the field with this prefix if it failed
@@ -115,7 +115,7 @@ const struct definition *bt_ctf_get_field(const struct bt_ctf_event *ctf_event,
                field_underscore = g_new(char, strlen(field) + 2);
                field_underscore[0] = '_';
                strcpy(&field_underscore[1], field);
-               def = lookup_definition(scope, field_underscore);
+               def = bt_lookup_definition(scope, field_underscore);
                g_free(field_underscore);
        }
        if (bt_ctf_field_type(bt_ctf_get_decl_from_def(def)) == CTF_TYPE_VARIANT) {
@@ -127,11 +127,11 @@ const struct definition *bt_ctf_get_field(const struct bt_ctf_event *ctf_event,
        return def;
 }
 
-const struct definition *bt_ctf_get_index(const struct bt_ctf_event *ctf_event,
-               const struct definition *field,
+const struct bt_definition *bt_ctf_get_index(const struct bt_ctf_event *ctf_event,
+               const struct bt_definition *field,
                unsigned int index)
 {
-       struct definition *ret = NULL;
+       struct bt_definition *ret = NULL;
 
        if (!ctf_event || !field)
                return NULL;
@@ -140,12 +140,12 @@ const struct definition *bt_ctf_get_index(const struct bt_ctf_event *ctf_event,
                struct definition_array *array_definition;
                array_definition = container_of(field,
                                struct definition_array, p);
-               ret = array_index(array_definition, index);
+               ret = bt_array_index(array_definition, index);
        } else if (bt_ctf_field_type(bt_ctf_get_decl_from_def(field)) == CTF_TYPE_SEQUENCE) {
                struct definition_sequence *sequence_definition;
                sequence_definition = container_of(field,
                                struct definition_sequence, p);
-               ret = sequence_index(sequence_definition, index);
+               ret = bt_sequence_index(sequence_definition, index);
        }
        return ret;
 }
@@ -166,7 +166,7 @@ const char *bt_ctf_event_name(const struct bt_ctf_event *ctf_event)
        return g_quark_to_string(event_class->name);
 }
 
-const char *bt_ctf_field_name(const struct definition *def)
+const char *bt_ctf_field_name(const struct bt_definition *def)
 {
        if (!def || !def->name)
                return NULL;
@@ -174,7 +174,7 @@ const char *bt_ctf_field_name(const struct definition *def)
        return rem_(g_quark_to_string(def->name));
 }
 
-enum ctf_type_id bt_ctf_field_type(const struct declaration *decl)
+enum ctf_type_id bt_ctf_field_type(const struct bt_declaration *decl)
 {
        if (!decl)
                return CTF_TYPE_UNKNOWN;
@@ -183,8 +183,8 @@ enum ctf_type_id bt_ctf_field_type(const struct declaration *decl)
 }
 
 int bt_ctf_get_field_list(const struct bt_ctf_event *ctf_event,
-               const struct definition *scope,
-               struct definition const * const **list,
+               const struct bt_definition *scope,
+               struct bt_definition const * const **list,
                unsigned int *count)
 {
        if (!ctf_event || !scope || !list || !count)
@@ -204,7 +204,7 @@ int bt_ctf_get_field_list(const struct bt_ctf_event *ctf_event,
                if (!def_struct)
                        goto error;
                if (def_struct->fields->pdata) {
-                       *list = (struct definition const* const*) def_struct->fields->pdata;
+                       *list = (struct bt_definition const* const*) def_struct->fields->pdata;
                        *count = def_struct->fields->len;
                        goto end;
                } else {
@@ -222,7 +222,7 @@ int bt_ctf_get_field_list(const struct bt_ctf_event *ctf_event,
                if (!def_variant)
                        goto error;
                if (def_variant->fields->pdata) {
-                       *list = (struct definition const* const*) def_variant->fields->pdata;
+                       *list = (struct bt_definition const* const*) def_variant->fields->pdata;
                        *count = def_variant->fields->len;
                        goto end;
                } else {
@@ -238,7 +238,7 @@ int bt_ctf_get_field_list(const struct bt_ctf_event *ctf_event,
                if (!def_array)
                        goto error;
                if (def_array->elems->pdata) {
-                       *list = (struct definition const* const*) def_array->elems->pdata;
+                       *list = (struct bt_definition const* const*) def_array->elems->pdata;
                        *count = def_array->elems->len;
                        goto end;
                } else {
@@ -254,7 +254,7 @@ int bt_ctf_get_field_list(const struct bt_ctf_event *ctf_event,
                if (!def_sequence)
                        goto error;
                if (def_sequence->elems->pdata) {
-                       *list = (struct definition const* const*) def_sequence->elems->pdata;
+                       *list = (struct bt_definition const* const*) def_sequence->elems->pdata;
                        *count = def_sequence->elems->len;
                        goto end;
                } else {
@@ -289,8 +289,8 @@ struct bt_context *bt_ctf_event_get_context(const struct bt_ctf_event *ctf_event
        cfs = container_of(event->stream, const struct ctf_file_stream,
                        parent);
        trace = cfs->parent.stream_class->trace;
-       if (trace->ctx)
-               ret = trace->ctx;
+       if (trace->parent.ctx)
+               ret = trace->parent.ctx;
 
        return ret;
 }
@@ -309,8 +309,8 @@ int bt_ctf_event_get_handle_id(const struct bt_ctf_event *ctf_event)
        cfs = container_of(event->stream, const struct ctf_file_stream,
                        parent);
        trace = cfs->parent.stream_class->trace;
-       if (trace->handle)
-               ret = trace->handle->id;
+       if (trace->parent.handle)
+               ret = trace->parent.handle->id;
 
        return ret;
 }
@@ -358,7 +358,7 @@ int bt_ctf_field_get_error(void)
 }
 
 static const struct declaration_integer *
-get_declaration_integer(const struct declaration *decl)
+get_declaration_integer(const struct bt_declaration *decl)
 {
        if (!decl || bt_ctf_field_type(decl) != CTF_TYPE_INTEGER)
                return NULL;
@@ -366,7 +366,7 @@ get_declaration_integer(const struct declaration *decl)
 }
 
 static const struct declaration_string *
-get_declaration_string(const struct declaration *decl)
+get_declaration_string(const struct bt_declaration *decl)
 {
        if (!decl || bt_ctf_field_type(decl) != CTF_TYPE_STRING)
                return NULL;
@@ -374,7 +374,7 @@ get_declaration_string(const struct declaration *decl)
 }
 
 static const struct declaration_array *
-get_declaration_array(const struct declaration *decl)
+get_declaration_array(const struct bt_declaration *decl)
 {
        if (!decl || bt_ctf_field_type(decl) != CTF_TYPE_ARRAY)
                return NULL;
@@ -382,14 +382,14 @@ get_declaration_array(const struct declaration *decl)
 }
 
 static const struct declaration_sequence *
-get_declaration_sequence(const struct declaration *decl)
+get_declaration_sequence(const struct bt_declaration *decl)
 {
        if (!decl || bt_ctf_field_type(decl) != CTF_TYPE_SEQUENCE)
                return NULL;
        return container_of(decl, const struct declaration_sequence, p);
 }
 
-int bt_ctf_get_int_signedness(const struct declaration *decl)
+int bt_ctf_get_int_signedness(const struct bt_declaration *decl)
 {
        const struct declaration_integer *integer;
 
@@ -401,7 +401,7 @@ int bt_ctf_get_int_signedness(const struct declaration *decl)
        return integer->signedness;
 }
 
-int bt_ctf_get_int_base(const struct declaration *decl)
+int bt_ctf_get_int_base(const struct bt_declaration *decl)
 {
        const struct declaration_integer *integer;
 
@@ -413,7 +413,7 @@ int bt_ctf_get_int_base(const struct declaration *decl)
        return integer->base;
 }
 
-int bt_ctf_get_int_byte_order(const struct declaration *decl)
+int bt_ctf_get_int_byte_order(const struct bt_declaration *decl)
 {
        const struct declaration_integer *integer;
 
@@ -425,7 +425,7 @@ int bt_ctf_get_int_byte_order(const struct declaration *decl)
        return integer->byte_order;
 }
 
-ssize_t bt_ctf_get_int_len(const struct declaration *decl)
+ssize_t bt_ctf_get_int_len(const struct bt_declaration *decl)
 {
        const struct declaration_integer *integer;
 
@@ -437,7 +437,7 @@ ssize_t bt_ctf_get_int_len(const struct declaration *decl)
        return (ssize_t) integer->len;
 }
 
-const struct definition *bt_ctf_get_enum_int(const struct definition *field)
+const struct bt_definition *bt_ctf_get_enum_int(const struct bt_definition *field)
 {
        const struct definition_enum *def_enum;
 
@@ -449,7 +449,7 @@ const struct definition *bt_ctf_get_enum_int(const struct definition *field)
        return &def_enum->integer->p;
 }
 
-const char *bt_ctf_get_enum_str(const struct definition *field)
+const char *bt_ctf_get_enum_str(const struct bt_definition *field)
 {
        const struct definition_enum *def_enum;
        const struct declaration_enum *decl_enum;
@@ -462,12 +462,12 @@ const char *bt_ctf_get_enum_str(const struct definition *field)
        }
        def_enum = container_of(field, const struct definition_enum, p);
        decl_enum = def_enum->declaration;
-       if (get_int_signedness(&def_enum->integer->p)) {
-               array = enum_int_to_quark_set(decl_enum,
-                       get_signed_int(&def_enum->integer->p));
+       if (bt_get_int_signedness(&def_enum->integer->p)) {
+               array = bt_enum_int_to_quark_set(decl_enum,
+                       bt_get_signed_int(&def_enum->integer->p));
        } else {
-               array = enum_uint_to_quark_set(decl_enum,
-                       get_unsigned_int(&def_enum->integer->p));
+               array = bt_enum_uint_to_quark_set(decl_enum,
+                       bt_get_unsigned_int(&def_enum->integer->p));
        }
        if (!array) {
                bt_ctf_field_set_error(-ENOENT);
@@ -485,7 +485,7 @@ const char *bt_ctf_get_enum_str(const struct definition *field)
        return ret;
 }
 
-enum ctf_string_encoding bt_ctf_get_encoding(const struct declaration *decl)
+enum ctf_string_encoding bt_ctf_get_encoding(const struct bt_declaration *decl)
 {
        enum ctf_string_encoding ret = 0;
        enum ctf_type_id type;
@@ -540,7 +540,7 @@ error:
        return -1;
 }
 
-int bt_ctf_get_array_len(const struct declaration *decl)
+int bt_ctf_get_array_len(const struct bt_declaration *decl)
 {
        const struct declaration_array *array;
 
@@ -554,37 +554,37 @@ error:
        return -1;
 }
 
-uint64_t bt_ctf_get_uint64(const struct definition *field)
+uint64_t bt_ctf_get_uint64(const struct bt_definition *field)
 {
        uint64_t ret = 0;
 
        if (field && bt_ctf_field_type(bt_ctf_get_decl_from_def(field)) == CTF_TYPE_INTEGER)
-               ret = get_unsigned_int(field);
+               ret = bt_get_unsigned_int(field);
        else
                bt_ctf_field_set_error(-EINVAL);
 
        return ret;
 }
 
-int64_t bt_ctf_get_int64(const struct definition *field)
+int64_t bt_ctf_get_int64(const struct bt_definition *field)
 {
        int64_t ret = 0;
 
        if (field && bt_ctf_field_type(bt_ctf_get_decl_from_def(field)) == CTF_TYPE_INTEGER)
-               ret = get_signed_int(field);
+               ret = bt_get_signed_int(field);
        else
                bt_ctf_field_set_error(-EINVAL);
 
        return ret;
 }
 
-char *bt_ctf_get_char_array(const struct definition *field)
+char *bt_ctf_get_char_array(const struct bt_definition *field)
 {
        char *ret = NULL;
        GString *char_array;
 
        if (field && bt_ctf_field_type(bt_ctf_get_decl_from_def(field)) == CTF_TYPE_ARRAY) {
-               char_array = get_char_array(field);
+               char_array = bt_get_char_array(field);
                if (char_array) {
                        ret = char_array->str;
                        goto end;
@@ -596,12 +596,12 @@ end:
        return ret;
 }
 
-char *bt_ctf_get_string(const struct definition *field)
+char *bt_ctf_get_string(const struct bt_definition *field)
 {
        char *ret = NULL;
 
        if (field && bt_ctf_field_type(bt_ctf_get_decl_from_def(field)) == CTF_TYPE_STRING)
-               ret = get_string(field);
+               ret = bt_get_string(field);
        else
                bt_ctf_field_set_error(-EINVAL);
 
@@ -613,7 +613,7 @@ int bt_ctf_get_event_decl_list(int handle_id, struct bt_context *ctx,
                unsigned int *count)
 {
        struct bt_trace_handle *handle;
-       struct trace_descriptor *td;
+       struct bt_trace_descriptor *td;
        struct ctf_trace *tin;
 
        if (!ctx || !list || !count)
@@ -653,11 +653,11 @@ int bt_ctf_get_decl_fields(struct bt_ctf_event_decl *event_decl,
        gpointer *ret_list = NULL;
        GPtrArray *fields_array = NULL;
        int ret = 0;
-       *count = 0;
 
        if (!event_decl || !list || !count)
                return -EINVAL;
 
+       *count = 0;
        switch (scope) {
        case BT_EVENT_CONTEXT:
                if (event_decl->context_decl) {
@@ -767,7 +767,7 @@ const char *bt_ctf_get_decl_field_name(const struct bt_ctf_field_decl *field)
        return rem_(g_quark_to_string(((struct declaration_field *) field)->name));
 }
 
-const struct declaration *bt_ctf_get_decl_from_def(const struct definition *def)
+const struct bt_declaration *bt_ctf_get_decl_from_def(const struct bt_definition *def)
 {
        if (def)
                return def->declaration;
@@ -775,7 +775,7 @@ const struct declaration *bt_ctf_get_decl_from_def(const struct definition *def)
        return NULL;
 }
 
-const struct declaration *bt_ctf_get_decl_from_field_decl(
+const struct bt_declaration *bt_ctf_get_decl_from_field_decl(
                const struct bt_ctf_field_decl *field)
 {
        if (field)
index 0534d013acc601220dd41986aea26805a7169d88..d2cd914ef02f62b1bf38596fc3deb90ad5643d64 100644 (file)
@@ -120,7 +120,7 @@ struct bt_ctf_event *bt_ctf_iter_read_event_flags(struct bt_ctf_iter *iter,
        assert(iter);
 
        ret = &iter->current_ctf_event;
-       file_stream = heap_maximum(iter->parent.stream_heap);
+       file_stream = bt_heap_maximum(iter->parent.stream_heap);
        if (!file_stream) {
                /* end of file for all streams */
                goto stop;
diff --git a/formats/ctf/memstream.h b/formats/ctf/memstream.h
deleted file mode 100644 (file)
index d2a96cb..0000000
+++ /dev/null
@@ -1,236 +0,0 @@
-#ifndef _BABELTRACE_FORMAT_CTF_MEMSTREAM_H
-#define _BABELTRACE_FORMAT_CTF_MEMSTREAM_H
-
-/*
- * format/ctf/memstream.h
- *
- * Copyright 2012 (c) - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
- *
- * memstream compatibility layer.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-
-#define _GNU_SOURCE
-#include <config.h>
-
-#ifdef BABELTRACE_HAVE_FMEMOPEN
-#include <stdio.h>
-
-static inline
-FILE *babeltrace_fmemopen(void *buf, size_t size, const char *mode)
-{
-       return fmemopen(buf, size, mode);
-}
-
-#else /* BABELTRACE_HAVE_FMEMOPEN */
-
-#include <stdlib.h>
-#include <stdio.h>
-
-/*
- * Fallback for systems which don't have fmemopen. Copy buffer to a
- * temporary file, and use that file as FILE * input.
- */
-static inline
-FILE *babeltrace_fmemopen(void *buf, size_t size, const char *mode)
-{
-       char tmpname[PATH_MAX];
-       size_t len;
-       FILE *fp;
-       int ret;
-
-       /*
-        * Support reading only.
-        */
-       if (strcmp(mode, "rb") != 0) {
-               return NULL;
-       }
-       strncpy(tmpname, "/tmp/babeltrace-tmp-XXXXXX", PATH_MAX);
-       ret = mkstemp(tmpname);
-       if (ret < 0) {
-               return NULL;
-       }
-       /*
-        * We need to write to the file.
-        */
-       fp = fdopen(ret, "w+");
-       if (!fp) {
-               goto error_unlink;
-       }
-       /* Copy the entire buffer to the file */
-       len = fwrite(buf, sizeof(char), size, fp);
-       if (len != size) {
-               goto error_close;
-       }
-       ret = fseek(fp, 0L, SEEK_SET);
-       if (ret < 0) {
-               perror("fseek");
-               goto error_close;
-       }
-       /* We keep the handle open, but can unlink the file on the VFS. */
-       ret = unlink(tmpname);
-       if (ret < 0) {
-               perror("unlink");
-       }
-       return fp;
-
-error_close:
-       ret = fclose(fp);
-       if (ret < 0) {
-               perror("close");
-       }
-error_unlink:
-       ret = unlink(tmpname);
-       if (ret < 0) {
-               perror("unlink");
-       }
-       return NULL;
-}
-
-#endif /* BABELTRACE_HAVE_FMEMOPEN */
-
-#ifdef BABELTRACE_HAVE_OPEN_MEMSTREAM
-
-#include <stdio.h>
-
-static inline
-FILE *babeltrace_open_memstream(char **ptr, size_t *sizeloc)
-{
-       return open_memstream(ptr, sizeloc);
-}
-
-static inline
-int babeltrace_close_memstream(char **buf, size_t *size, FILE *fp)
-{
-       return fclose(fp);
-}
-
-#else /* BABELTRACE_HAVE_OPEN_MEMSTREAM */
-
-#include <stdlib.h>
-#include <stdio.h>
-
-/*
- * Fallback for systems which don't have open_memstream. Create FILE *
- * with babeltrace_open_memstream, but require call to
- * babeltrace_close_memstream to flush all data written to the FILE *
- * into the buffer (which we allocate).
- */
-static inline
-FILE *babeltrace_open_memstream(char **ptr, size_t *sizeloc)
-{
-       char tmpname[PATH_MAX];
-       int ret;
-       FILE *fp;
-
-       strncpy(tmpname, "/tmp/babeltrace-tmp-XXXXXX", PATH_MAX);
-       ret = mkstemp(tmpname);
-       if (ret < 0) {
-               return NULL;
-       }
-       fp = fdopen(ret, "w+");
-       if (!fp) {
-               goto error_unlink;
-       }
-       /*
-        * babeltrace_flush_memstream will update the buffer content
-        * with read from fp. No need to keep the file around, just the
-        * handle.
-        */
-       ret = unlink(tmpname);
-       if (ret < 0) {
-               perror("unlink");
-       }
-       return fp;
-
-error_unlink:
-       ret = unlink(tmpname);
-       if (ret < 0) {
-               perror("unlink");
-       }
-       return NULL;
-}
-
-/* Get file size, allocate buffer, copy. */
-static inline
-int babeltrace_close_memstream(char **buf, size_t *size, FILE *fp)
-{
-       size_t len, n;
-       long pos;
-       int ret;
-
-       ret = fflush(fp);
-       if (ret < 0) {
-               perror("fflush");
-               return ret;
-       }
-       ret = fseek(fp, 0L, SEEK_END);
-       if (ret < 0) {
-               perror("fseek");
-               return ret;
-       }
-       pos = ftell(fp);
-       if (ret < 0) {
-               perror("ftell");
-               return ret;
-       }
-       *size = pos;
-       /* add final \0 */
-       *buf = calloc(pos + 1, sizeof(char));
-       if (!*buf) {
-               return -ENOMEM;
-       }
-       ret = fseek(fp, 0L, SEEK_SET);
-       if (ret < 0) {
-               perror("fseek");
-               goto error_free;
-       }
-       /* Copy the entire file into the buffer */
-       n = 0;
-       clearerr(fp);
-       while (!feof(fp) && !ferror(fp) && (*size - n > 0)) {
-               len = fread(*buf, sizeof(char), *size - n, fp);
-               n += len;
-       }
-       if (n != *size) {
-               ret = -1;
-               goto error_close;
-       }
-       ret = fclose(fp);
-       if (ret < 0) {
-               perror("fclose");
-               return ret;
-       }
-       return 0;
-
-error_close:
-       ret = fclose(fp);
-       if (ret < 0) {
-               perror("fclose");
-       }
-error_free:
-       free(*buf);
-       *buf = NULL;
-       return ret;
-}
-
-#endif /* BABELTRACE_HAVE_OPEN_MEMSTREAM */
-
-#endif /* _BABELTRACE_FORMAT_CTF_MEMSTREAM_H */
index a7f633d9b0f013476068674eeb050dbf6f8de8fc..b33ce5536b4124284100a52f1bc60c664987065a 100644 (file)
@@ -6,9 +6,12 @@ noinst_LTLIBRARIES = libctf-parser.la libctf-ast.la
 
 noinst_HEADERS = \
        ctf-scanner.h \
-       ctf-ast.h
+       ctf-ast.h \
+       ctf-scanner-symbols.h \
+       objstack.h
 
-libctf_parser_la_SOURCES = ctf-lexer.l ctf-parser.y
+libctf_parser_la_SOURCES = ctf-lexer.l ctf-parser.y objstack.c
+libctf_parser_la_CFLAGS = $(AM_CFLAGS) -include ctf-scanner-symbols.h
 
 libctf_ast_la_SOURCES = ctf-visitor-xml.c \
                ctf-visitor-parent-links.c \
index d5a0544a9d6d05f98f35dbe3bd7f68c194d9c09d..a8e58cef121eb82dbbe37427f8014ca798f7114c 100644 (file)
 struct ctf_node;
 struct ctf_parser;
 
-enum node_type {
-       NODE_UNKNOWN = 0,
-       NODE_ROOT,
-
-       NODE_EVENT,
-       NODE_STREAM,
-       NODE_ENV,
-       NODE_TRACE,
-       NODE_CLOCK,
-       NODE_CALLSITE,
-
-       NODE_CTF_EXPRESSION,
-       NODE_UNARY_EXPRESSION,
-
-       NODE_TYPEDEF,
-       NODE_TYPEALIAS_TARGET,
-       NODE_TYPEALIAS_ALIAS,
-       NODE_TYPEALIAS,
-
-       NODE_TYPE_SPECIFIER,
-       NODE_TYPE_SPECIFIER_LIST,
-       NODE_POINTER,
-       NODE_TYPE_DECLARATOR,
-
-       NODE_FLOATING_POINT,
-       NODE_INTEGER,
-       NODE_STRING,
-       NODE_ENUMERATOR,
-       NODE_ENUM,
-       NODE_STRUCT_OR_VARIANT_DECLARATION,
-       NODE_VARIANT,
-       NODE_STRUCT,
+#define FOREACH_CTF_NODES(F) \
+       F(NODE_UNKNOWN) \
+       F(NODE_ROOT) \
+       F(NODE_ERROR) \
+       F(NODE_EVENT) \
+       F(NODE_STREAM) \
+       F(NODE_ENV) \
+       F(NODE_TRACE) \
+       F(NODE_CLOCK) \
+       F(NODE_CALLSITE) \
+       F(NODE_CTF_EXPRESSION) \
+       F(NODE_UNARY_EXPRESSION) \
+       F(NODE_TYPEDEF) \
+       F(NODE_TYPEALIAS_TARGET) \
+       F(NODE_TYPEALIAS_ALIAS) \
+       F(NODE_TYPEALIAS) \
+       F(NODE_TYPE_SPECIFIER) \
+       F(NODE_TYPE_SPECIFIER_LIST) \
+       F(NODE_POINTER) \
+       F(NODE_TYPE_DECLARATOR) \
+       F(NODE_FLOATING_POINT) \
+       F(NODE_INTEGER) \
+       F(NODE_STRING) \
+       F(NODE_ENUMERATOR) \
+       F(NODE_ENUM) \
+       F(NODE_STRUCT_OR_VARIANT_DECLARATION) \
+       F(NODE_VARIANT) \
+       F(NODE_STRUCT)
 
+enum node_type {
+#define ENTRY(S)       S,
+       FOREACH_CTF_NODES(ENTRY)
+#undef ENTRY
        NR_NODE_TYPES,
 };
 
@@ -75,7 +75,7 @@ struct ctf_node {
        struct ctf_node *parent;
        struct bt_list_head siblings;
        struct bt_list_head tmp_head;
-       struct bt_list_head gc;
+       unsigned int lineno;
 
        enum node_type type;
        union {
@@ -147,7 +147,6 @@ struct ctf_node {
                                UNARY_SIGNED_CONSTANT,
                                UNARY_UNSIGNED_CONSTANT,
                                UNARY_SBRAC,
-                               UNARY_NESTED,
                        } type;
                        union {
                                /*
@@ -158,7 +157,6 @@ struct ctf_node {
                                int64_t signed_constant;
                                uint64_t unsigned_constant;
                                struct ctf_node *sbrac_exp;
-                               struct ctf_node *nested_exp;
                        } u;
                        enum {
                                UNARY_LINK_UNKNOWN = 0,
@@ -295,18 +293,22 @@ struct ctf_node {
 
 struct ctf_ast {
        struct ctf_node root;
-       struct bt_list_head allocated_nodes;
 };
 
 const char *node_type(struct ctf_node *node);
 
 struct ctf_trace;
 
+BT_HIDDEN
 int ctf_visitor_print_xml(FILE *fd, int depth, struct ctf_node *node);
+BT_HIDDEN
 int ctf_visitor_semantic_check(FILE *fd, int depth, struct ctf_node *node);
+BT_HIDDEN
 int ctf_visitor_parent_links(FILE *fd, int depth, struct ctf_node *node);
+BT_HIDDEN
 int ctf_visitor_construct_metadata(FILE *fd, int depth, struct ctf_node *node,
                        struct ctf_trace *trace, int byte_order);
+BT_HIDDEN
 int ctf_destroy_metadata(struct ctf_trace *trace);
 
 #endif /* _CTF_AST_H */
index 26aa1bce2322d2571a9b57b24d614484009e3cdc..6b605a0fe583dab98eb6c59feaad0e8b259d7245 100644 (file)
  */
 
 #include <stdio.h>
+#include <ctype.h>
 #include <babeltrace/babeltrace-internal.h>
 #include "ctf-scanner.h"
 #include "ctf-parser.h"
 #include "ctf-ast.h"
 
-__attribute__((visibility("hidden")))
+#define PARSE_INTEGER_LITERAL(base)                                    \
+       do {                                                            \
+               errno = 0;                                              \
+               yylval->ull = strtoull(yytext, NULL, base);             \
+               if (errno) {                                            \
+                       printfl_perror(yylineno, "Integer literal");    \
+                       return ERROR;                                   \
+               }                                                       \
+       } while (0)
+
+BT_HIDDEN
 void setstring(struct ctf_scanner *scanner, YYSTYPE *lvalp, const char *src);
 
 static void yyunput (int c, register char * yy_bp , yyscan_t yyscanner)
        __attribute__((unused));
 static int input (yyscan_t yyscanner) __attribute__((unused));
 
+BT_HIDDEN
+int import_string(struct ctf_scanner *scanner, YYSTYPE *lvalp, const char *src, char delim);
+
 %}
 
 %x comment_ml comment_sl string_lit char_const
 %option reentrant yylineno noyywrap bison-bridge
 %option extra-type="struct ctf_scanner *"
        /* bison-locations */
-INTEGER_SUFFIX                 [ \n\t]*(U|UL|ULL|LU|LLU|Ul|Ull|lU|llU|u|uL|uLL|Lu|LLu|ul|ull|lu|llu)
+INTEGER_SUFFIX                 (U|UL|ULL|LU|LLU|Ul|Ull|lU|llU|u|uL|uLL|Lu|LLu|ul|ull|lu|llu)
 DIGIT                          [0-9]
 NONDIGIT                       [a-zA-Z_]
 HEXDIGIT                       [0-9A-Fa-f]
@@ -53,7 +67,6 @@ UCHARLOWERCASE                        \\u{HEXDIGIT}{4}
 UCHARUPPERCASE                 \\U{HEXDIGIT}{8}
 ID_NONDIGIT                    {NONDIGIT}|{UCHARLOWERCASE}|{UCHARUPPERCASE}
 IDENTIFIER                     {ID_NONDIGIT}({ID_NONDIGIT}|{DIGIT})*
-ESCSEQ                         \\(\'|\"|\?|\\|a|b|f|n|r|t|v|{OCTALDIGIT}{1,3}|u{HEXDIGIT}{4}|U{HEXDIGIT}{8}|x{HEXDIGIT}+)
 %%
 
                                /*
@@ -64,23 +77,13 @@ ESCSEQ                              \\(\'|\"|\?|\\|a|b|f|n|r|t|v|{OCTALDIGIT}{1,3}|u{HEXDIGIT}{4}|U{HEXDIG
 "/*"                           BEGIN(comment_ml);
 <comment_ml>[^*\n]*            /* eat anything that's not a '*' */
 <comment_ml>"*"+[^*/\n]*       /* eat up '*'s not followed by '/'s */
-<comment_ml>\n                 ++yylineno;
+<comment_ml>\n
 <comment_ml>"*"+"/"            BEGIN(INITIAL);
 
-"//"                           BEGIN(comment_sl);
-<comment_sl>[^\n]*\n           ++yylineno; BEGIN(INITIAL);
-
-L\'                            BEGIN(char_const); return CHARACTER_CONSTANT_START;
-\'                             BEGIN(char_const); return CHARACTER_CONSTANT_START;
-<char_const>\'                 BEGIN(INITIAL); return SQUOTE;
+"//"[^\n]*\n                   /* skip comment */
 
-L\"                            BEGIN(string_lit); return STRING_LITERAL_START;
-\"                             BEGIN(string_lit); return STRING_LITERAL_START;
-<string_lit>\"                 BEGIN(INITIAL); return DQUOTE;
-
-<char_const,string_lit>ESCSEQ  return ESCSEQ;
-<char_const,string_lit>\n      ; /* ignore */
-<char_const,string_lit>.       setstring(yyextra, yylval, yytext); return CHAR_STRING_TOKEN;
+L?\"(\\.|[^\\"])*\"            { if (import_string(yyextra, yylval, yytext, '\"') < 0) return ERROR; else return STRING_LITERAL; }
+L?\'(\\.|[^\\'])*\'            { if (import_string(yyextra, yylval, yytext, '\'') < 0) return ERROR; else return CHARACTER_LITERAL; }
 
 "["                            return LSBRAC;
 "]"                            return RSBRAC;
@@ -129,10 +132,11 @@ void                              setstring(yyextra, yylval, yytext); return VOID;
 _Bool                          setstring(yyextra, yylval, yytext); return _BOOL;
 _Complex                       setstring(yyextra, yylval, yytext); return _COMPLEX;
 _Imaginary                     setstring(yyextra, yylval, yytext); return _IMAGINARY;
-[1-9]{DIGIT}*{INTEGER_SUFFIX}? setstring(yyextra, yylval, yytext); return DECIMAL_CONSTANT;
-0{OCTALDIGIT}*{INTEGER_SUFFIX}?        setstring(yyextra, yylval, yytext); return OCTAL_CONSTANT;
-0[xX]{HEXDIGIT}+{INTEGER_SUFFIX}?      setstring(yyextra, yylval, yytext); return HEXADECIMAL_CONSTANT;
+[1-9]{DIGIT}*{INTEGER_SUFFIX}? PARSE_INTEGER_LITERAL(10); return INTEGER_LITERAL;
+0{OCTALDIGIT}*{INTEGER_SUFFIX}?        PARSE_INTEGER_LITERAL(8); return INTEGER_LITERAL;
+0[xX]{HEXDIGIT}+{INTEGER_SUFFIX}?      PARSE_INTEGER_LITERAL(16); return INTEGER_LITERAL;
+
 {IDENTIFIER}                   printf_debug("<IDENTIFIER %s>\n", yytext); setstring(yyextra, yylval, yytext); if (is_type(yyextra, yytext)) return ID_TYPE; else return IDENTIFIER;
-[ \t\n]+                       ; /* ignore */
-.                              return ERROR;
+[ \t\r\n]                      ; /* ignore */
+.                              printfl_error(yylineno, "invalid character '0x%02X'", yytext[0]);  return ERROR;
 %%
index e7dfd80cf847aeea3bcd9ff14d21219984023a3d..f4c61f33d2fd733b29118f6a17ee436d29889e37 100644 (file)
@@ -26,6 +26,7 @@
  */
 
 #include <stdio.h>
+#include <ctype.h>
 #include <unistd.h>
 #include <string.h>
 #include <stdlib.h>
@@ -38,8 +39,9 @@
 #include "ctf-scanner.h"
 #include "ctf-parser.h"
 #include "ctf-ast.h"
+#include "objstack.h"
 
-__attribute__((visibility("hidden")))
+BT_HIDDEN
 int yydebug;
 
 /* Join two lists, put "add" at the end of "head".  */
@@ -55,53 +57,37 @@ _bt_list_splice_tail (struct bt_list_head *add, struct bt_list_head *head)
        }
 }
 
-__attribute__((visibility("hidden")))
+BT_HIDDEN
 int yyparse(struct ctf_scanner *scanner);
-__attribute__((visibility("hidden")))
+BT_HIDDEN
 int yylex(union YYSTYPE *yyval, struct ctf_scanner *scanner);
-__attribute__((visibility("hidden")))
+BT_HIDDEN
 int yylex_init_extra(struct ctf_scanner *scanner, yyscan_t * ptr_yy_globals);
-__attribute__((visibility("hidden")))
+BT_HIDDEN
 int yylex_destroy(yyscan_t yyscanner);
-__attribute__((visibility("hidden")))
+BT_HIDDEN
 void yyrestart(FILE * in_str, yyscan_t scanner);
+BT_HIDDEN
+int yyget_lineno(yyscan_t yyscanner);
+BT_HIDDEN
+char *yyget_text(yyscan_t yyscanner);
 
-struct gc_string {
-       struct bt_list_head gc;
-       size_t alloclen;
-       char s[];
+static const char *node_type_to_str[] = {
+#define ENTRY(S)       [S] = #S,
+       FOREACH_CTF_NODES(ENTRY)
+#undef ENTRY
 };
 
-static const char *node_type_to_str[] = {
-       [ NODE_UNKNOWN ] = "NODE_UNKNOWN",
-       [ NODE_ROOT ] = "NODE_ROOT",
-       [ NODE_EVENT ] = "NODE_EVENT",
-       [ NODE_ENV ] = "NODE_ENV",
-       [ NODE_STREAM ] = "NODE_STREAM",
-       [ NODE_TRACE ] = "NODE_TRACE",
-       [ NODE_CLOCK ] = "NODE_CLOCK",
-       [ NODE_CALLSITE ] = "NODE_CALLSITE",
-       [ NODE_CTF_EXPRESSION ] = "NODE_CTF_EXPRESSION",
-       [ NODE_UNARY_EXPRESSION ] = "NODE_UNARY_EXPRESSION",
-       [ NODE_TYPEDEF ] = "NODE_TYPEDEF",
-       [ NODE_TYPEALIAS_TARGET ] = "NODE_TYPEALIAS_TARGET",
-       [ NODE_TYPEALIAS_ALIAS ] = "NODE_TYPEALIAS_ALIAS",
-       [ NODE_TYPEALIAS ] = "NODE_TYPEALIAS",
-       [ NODE_TYPE_SPECIFIER ] = "NODE_TYPE_SPECIFIER",
-       [ NODE_TYPE_SPECIFIER_LIST ] = "NODE_TYPE_SPECIFIER_LIST",
-       [ NODE_POINTER ] = "NODE_POINTER",
-       [ NODE_TYPE_DECLARATOR ] = "NODE_TYPE_DECLARATOR",
-       [ NODE_FLOATING_POINT ] = "NODE_FLOATING_POINT",
-       [ NODE_INTEGER ] = "NODE_INTEGER",
-       [ NODE_STRING ] = "NODE_STRING",
-       [ NODE_ENUMERATOR ] = "NODE_ENUMERATOR",
-       [ NODE_ENUM ] = "NODE_ENUM",
-       [ NODE_STRUCT_OR_VARIANT_DECLARATION ] = "NODE_STRUCT_OR_VARIANT_DECLARATION",
-       [ NODE_VARIANT ] = "NODE_VARIANT",
-       [ NODE_STRUCT ] = "NODE_STRUCT",
+/*
+ * Static node for out of memory errors. Only "type" is used. lineno is
+ * always left at 0. The rest of the node content can be overwritten,
+ * but is never used.
+ */
+static struct ctf_node error_node = {
+       .type = NODE_ERROR,
 };
 
-__attribute__((visibility("hidden")))
+BT_HIDDEN
 const char *node_type(struct ctf_node *node)
 {
        if (node->type < NR_NODE_TYPES)
@@ -110,62 +96,200 @@ const char *node_type(struct ctf_node *node)
                return NULL;
 }
 
-static struct gc_string *gc_string_alloc(struct ctf_scanner *scanner,
-                                        size_t len)
+void setstring(struct ctf_scanner *scanner, YYSTYPE *lvalp, const char *src)
 {
-       struct gc_string *gstr;
-       size_t alloclen;
-
-       /* TODO: could be faster with find first bit or glib Gstring */
-       /* sizeof long to account for malloc header (int or long ?) */
-       for (alloclen = 8; alloclen < sizeof(long) + sizeof(*gstr) + len;
-            alloclen *= 2);
-
-       gstr = malloc(alloclen);
-       bt_list_add(&gstr->gc, &scanner->allocated_strings);
-       gstr->alloclen = alloclen;
-       return gstr;
+       lvalp->s = objstack_alloc(scanner->objstack, strlen(src) + 1);
+       strcpy(lvalp->s, src);
 }
 
-/*
- * note: never use gc_string_append on a string that has external references.
- * gsrc will be garbage collected immediately, and gstr might be.
- * Should only be used to append characters to a string literal or constant.
- */
-__attribute__((visibility("hidden")))
-struct gc_string *gc_string_append(struct ctf_scanner *scanner,
-                                  struct gc_string *gstr,
-                                  struct gc_string *gsrc)
+static
+int str_check(size_t str_len, size_t offset, size_t len)
 {
-       size_t newlen = strlen(gsrc->s) + strlen(gstr->s) + 1;
-       size_t alloclen;
-
-       /* TODO: could be faster with find first bit or glib Gstring */
-       /* sizeof long to account for malloc header (int or long ?) */
-       for (alloclen = 8; alloclen < sizeof(long) + sizeof(*gstr) + newlen;
-            alloclen *= 2);
-
-       if (alloclen > gstr->alloclen) {
-               struct gc_string *newgstr;
-
-               newgstr = gc_string_alloc(scanner, newlen);
-               strcpy(newgstr->s, gstr->s);
-               strcat(newgstr->s, gsrc->s);
-               bt_list_del(&gstr->gc);
-               free(gstr);
-               gstr = newgstr;
-       } else {
-               strcat(gstr->s, gsrc->s);
+       /* check overflow */
+       if (offset + len < offset)
+               return -1;
+       if (offset + len > str_len)
+               return -1;
+       return 0;
+}
+
+static
+int bt_isodigit(int c)
+{
+       switch (c) {
+       case '0':
+       case '1':
+       case '2':
+       case '3':
+       case '4':
+       case '5':
+       case '6':
+       case '7':
+               return 1;
+       default:
+               return 0;
        }
-       bt_list_del(&gsrc->gc);
-       free(gsrc);
-       return gstr;
 }
 
-void setstring(struct ctf_scanner *scanner, YYSTYPE *lvalp, const char *src)
+static
+int parse_base_sequence(const char *src, size_t len, size_t pos,
+               char *buffer, size_t *buf_len, int base)
 {
-       lvalp->gs = gc_string_alloc(scanner, strlen(src) + 1);
-       strcpy(lvalp->gs->s, src);
+       const size_t max_char = 3;
+       int nr_char = 0;
+
+       while (!str_check(len, pos, 1) && nr_char < max_char) {
+               char c = src[pos++];
+
+               if (base == 8) {
+                       if (bt_isodigit(c))
+                               buffer[nr_char++] = c;
+                       else
+                               break;
+               } else if (base == 16) {
+                       if (isxdigit(c))
+                               buffer[nr_char++] = c;
+                       else
+                               break;
+
+               } else {
+                       /* Unsupported base */
+                       return -1;
+               }
+       }
+       assert(nr_char > 0);
+       buffer[nr_char] = '\0';
+       *buf_len = nr_char;
+       return 0;
+}
+
+static
+int import_basic_string(struct ctf_scanner *scanner, YYSTYPE *lvalp,
+               size_t len, const char *src, char delim)
+{
+       size_t pos = 0, dpos = 0;
+
+       if (str_check(len, pos, 1))
+               return -1;
+       if (src[pos++] != delim)
+               return -1;
+
+       while (src[pos] != delim) {
+               char c;
+
+               if (str_check(len, pos, 1))
+                       return -1;
+               c = src[pos++];
+               if (c == '\\') {
+                       if (str_check(len, pos, 1))
+                               return -1;
+                       c = src[pos++];
+
+                       switch (c) {
+                       case 'a':
+                               c = '\a';
+                               break;
+                       case 'b':
+                               c = '\b';
+                               break;
+                       case 'f':
+                               c = '\f';
+                               break;
+                       case 'n':
+                               c = '\n';
+                               break;
+                       case 'r':
+                               c = '\r';
+                               break;
+                       case 't':
+                               c = '\t';
+                               break;
+                       case 'v':
+                               c = '\v';
+                               break;
+                       case '\\':
+                               c = '\\';
+                               break;
+                       case '\'':
+                               c = '\'';
+                               break;
+                       case '\"':
+                               c = '\"';
+                               break;
+                       case '?':
+                               c = '?';
+                               break;
+                       case '0':
+                       case '1':
+                       case '2':
+                       case '3':
+                       case '4':
+                       case '5':
+                       case '6':
+                       case '7':
+                       {
+                               char oct_buffer[4];
+                               size_t oct_len;
+
+                               if (parse_base_sequence(src, len, pos - 1,
+                                               oct_buffer, &oct_len, 8))
+                                       return -1;
+                               c = strtoul(&oct_buffer[0], NULL, 8);
+                               pos += oct_len - 1;
+                               break;
+                       }
+                       case 'x':
+                       {
+                               char hex_buffer[4];
+                               size_t hex_len;
+
+                               if (parse_base_sequence(src, len, pos,
+                                               hex_buffer, &hex_len, 16))
+                                       return -1;
+                               c = strtoul(&hex_buffer[0], NULL, 16);
+                               pos += hex_len;
+                               break;
+                       }
+                       default:
+                               return -1;
+                       }
+               }
+               if (str_check(len, dpos, 1))
+                       return -1;
+               lvalp->s[dpos++] = c;
+       }
+
+       if (str_check(len, dpos, 1))
+               return -1;
+       lvalp->s[dpos++] = '\0';
+
+       if (str_check(len, pos, 1))
+               return -1;
+       if (src[pos++] != delim)
+               return -1;
+
+       if (str_check(len, pos, 1))
+               return -1;
+       if (src[pos] != '\0')
+               return -1;
+       return 0;
+}
+
+int import_string(struct ctf_scanner *scanner, YYSTYPE *lvalp,
+               const char *src, char delim)
+{
+       size_t len;
+
+       len = strlen(src) + 1;
+       lvalp->s = objstack_alloc(scanner->objstack, len);
+       if (src[0] == 'L') {
+               // TODO: import wide string
+               printfl_error(yyget_lineno(scanner),
+                       "Wide string not supported yet.");
+               return -1;
+       } else {
+               return import_basic_string(scanner, lvalp, len, src, delim);
+       }
 }
 
 static void init_scope(struct ctf_scanner_scope *scope,
@@ -211,7 +335,7 @@ static int lookup_type(struct ctf_scanner_scope *s, const char *id)
        return ret;
 }
 
-__attribute__((visibility("hidden")))
+BT_HIDDEN
 int is_type(struct ctf_scanner *scanner, const char *id)
 {
        struct ctf_scanner_scope *it;
@@ -227,32 +351,33 @@ int is_type(struct ctf_scanner *scanner, const char *id)
        return ret;
 }
 
-static void add_type(struct ctf_scanner *scanner, struct gc_string *id)
+static void add_type(struct ctf_scanner *scanner, char *id)
 {
-       printf_debug("add type %s\n", id->s);
-       if (lookup_type(scanner->cs, id->s))
+       printf_debug("add type %s\n", id);
+       if (lookup_type(scanner->cs, id))
                return;
-       g_hash_table_insert(scanner->cs->types, id->s, id->s);
+       g_hash_table_insert(scanner->cs->types, id, id);
 }
 
 static struct ctf_node *make_node(struct ctf_scanner *scanner,
                                  enum node_type type)
 {
-       struct ctf_ast *ast = ctf_scanner_get_ast(scanner);
        struct ctf_node *node;
 
-       node = malloc(sizeof(*node));
-       if (!node)
-               return NULL;
-       memset(node, 0, sizeof(*node));
+       node = objstack_alloc(scanner->objstack, sizeof(*node));
+       if (!node) {
+               printfl_fatal(yyget_lineno(scanner->scanner), "out of memory");
+               return &error_node;
+       }
        node->type = type;
+       node->lineno = yyget_lineno(scanner->scanner);
        BT_INIT_LIST_HEAD(&node->tmp_head);
-       bt_list_add(&node->gc, &ast->allocated_nodes);
        bt_list_add(&node->siblings, &node->tmp_head);
 
        switch (type) {
        case NODE_ROOT:
-               fprintf(stderr, "[error] %s: trying to create root node\n", __func__);
+               node->type = NODE_ERROR;
+               printfn_fatal(node, "trying to create root node");
                break;
 
        case NODE_EVENT:
@@ -332,8 +457,8 @@ static struct ctf_node *make_node(struct ctf_scanner *scanner,
 
        case NODE_UNKNOWN:
        default:
-               fprintf(stderr, "[error] %s: unknown node type %d\n", __func__,
-                       (int) type);
+               node->type = NODE_ERROR;
+               printfn_fatal(node, "unknown node type '%d'", (int) type);
                break;
        }
 
@@ -392,8 +517,7 @@ static int reparent_ctf_expression(struct ctf_node *node,
 
        case NODE_UNKNOWN:
        default:
-               fprintf(stderr, "[error] %s: unknown node type %d\n", __func__,
-                       (int) parent->type);
+               printfn_fatal(node, "unknown node type '%d'", (int) parent->type);
                return -EINVAL;
        }
        return 0;
@@ -450,8 +574,7 @@ static int reparent_typedef(struct ctf_node *node, struct ctf_node *parent)
 
        case NODE_UNKNOWN:
        default:
-               fprintf(stderr, "[error] %s: unknown node type %d\n", __func__,
-                       (int) parent->type);
+               printfn_fatal(node, "unknown node type %d", parent->type);
                return -EINVAL;
        }
        return 0;
@@ -508,8 +631,7 @@ static int reparent_typealias(struct ctf_node *node, struct ctf_node *parent)
 
        case NODE_UNKNOWN:
        default:
-               fprintf(stderr, "[error] %s: unknown node type %d\n", __func__,
-                       (int) parent->type);
+               printfn_fatal(node, "unknown node type '%d'", (int) parent->type);
                return -EINVAL;
        }
        return 0;
@@ -550,8 +672,7 @@ static int reparent_type_specifier(struct ctf_node *node,
 
        case NODE_UNKNOWN:
        default:
-               fprintf(stderr, "[error] %s: unknown node type %d\n", __func__,
-                       (int) parent->type);
+               printfn_fatal(node, "unknown node type '%d'", (int) parent->type);
                return -EINVAL;
        }
        return 0;
@@ -617,8 +738,7 @@ static int reparent_type_specifier_list(struct ctf_node *node,
 
        case NODE_UNKNOWN:
        default:
-               fprintf(stderr, "[error] %s: unknown node type %d\n", __func__,
-                       (int) parent->type);
+               printfn_fatal(node, "unknown node type '%d'", (int) parent->type);
                return -EINVAL;
        }
        return 0;
@@ -669,8 +789,7 @@ static int reparent_type_declarator(struct ctf_node *node,
 
        case NODE_UNKNOWN:
        default:
-               fprintf(stderr, "[error] %s: unknown node type %d\n", __func__,
-                       (int) parent->type);
+               printfn_fatal(node, "unknown node type '%d'", (int) parent->type);
                return -EINVAL;
        }
        return 0;
@@ -693,7 +812,7 @@ static int set_parent_node(struct ctf_node *node,
 
        switch (node->type) {
        case NODE_ROOT:
-               fprintf(stderr, "[error] %s: trying to reparent root node\n", __func__);
+               printfn_fatal(node, "trying to reparent root node");
                return -EINVAL;
 
        case NODE_EVENT:
@@ -808,20 +927,21 @@ static int set_parent_node(struct ctf_node *node,
 
        case NODE_UNKNOWN:
        default:
-               fprintf(stderr, "[error] %s: unknown node type %d\n", __func__,
-                       (int) parent->type);
+               printfn_fatal(node, "unknown node type '%d'", (int) parent->type);
                return -EINVAL;
        }
        return 0;
 }
 
-__attribute__((visibility("hidden")))
+BT_HIDDEN
 void yyerror(struct ctf_scanner *scanner, const char *str)
 {
-       fprintf(stderr, "error %s\n", str);
+       printfl_error(yyget_lineno(scanner->scanner),
+               "token \"%s\": %s\n",
+               yyget_text(scanner->scanner), str);
 }
  
-__attribute__((visibility("hidden")))
+BT_HIDDEN
 int yywrap(void)
 {
        return 1;
@@ -829,27 +949,17 @@ int yywrap(void)
 
 #define reparent_error(scanner, str)                           \
 do {                                                           \
-       yyerror(scanner, YY_("reparent_error: " str "\n"));     \
+       yyerror(scanner, YY_("reparent_error: " str));  \
        YYERROR;                                                \
 } while (0)
 
-static void free_strings(struct bt_list_head *list)
-{
-       struct gc_string *gstr, *tmp;
-
-       bt_list_for_each_entry_safe(gstr, tmp, list, gc)
-               free(gstr);
-}
-
-static struct ctf_ast *ctf_ast_alloc(void)
+static struct ctf_ast *ctf_ast_alloc(struct ctf_scanner *scanner)
 {
        struct ctf_ast *ast;
 
-       ast = malloc(sizeof(*ast));
+       ast = objstack_alloc(scanner->objstack, sizeof(*ast));
        if (!ast)
                return NULL;
-       memset(ast, 0, sizeof(*ast));
-       BT_INIT_LIST_HEAD(&ast->allocated_nodes);
        ast->root.type = NODE_ROOT;
        BT_INIT_LIST_HEAD(&ast->root.tmp_head);
        BT_INIT_LIST_HEAD(&ast->root.u.root.declaration_list);
@@ -862,15 +972,6 @@ static struct ctf_ast *ctf_ast_alloc(void)
        return ast;
 }
 
-static void ctf_ast_free(struct ctf_ast *ast)
-{
-       struct ctf_node *node, *tmp;
-
-       bt_list_for_each_entry_safe(node, tmp, &ast->allocated_nodes, gc)
-               free(node);
-       free(ast);
-}
-
 int ctf_scanner_append_ast(struct ctf_scanner *scanner)
 {
        return yyparse(scanner);
@@ -890,18 +991,20 @@ struct ctf_scanner *ctf_scanner_alloc(FILE *input)
 
        ret = yylex_init_extra(scanner, &scanner->scanner);
        if (ret) {
-               fprintf(stderr, "yylex_init error\n");
+               printf_fatal("yylex_init error");
                goto cleanup_scanner;
        }
        /* Start processing new stream */
        yyrestart(input, scanner->scanner);
 
-       scanner->ast = ctf_ast_alloc();
-       if (!scanner->ast)
+       scanner->objstack = objstack_create();
+       if (!scanner->objstack)
                goto cleanup_lexer;
+       scanner->ast = ctf_ast_alloc(scanner);
+       if (!scanner->ast)
+               goto cleanup_objstack;
        init_scope(&scanner->root_scope, NULL);
        scanner->cs = &scanner->root_scope;
-       BT_INIT_LIST_HEAD(&scanner->allocated_strings);
 
        if (yydebug)
                fprintf(stdout, "Scanner input is a%s.\n",
@@ -910,10 +1013,12 @@ struct ctf_scanner *ctf_scanner_alloc(FILE *input)
 
        return scanner;
 
+cleanup_objstack:
+       objstack_destroy(scanner->objstack);
 cleanup_lexer:
        ret = yylex_destroy(scanner->scanner);
        if (!ret)
-               fprintf(stderr, "yylex_destroy error\n");
+               printf_fatal("yylex_destroy error");
 cleanup_scanner:
        free(scanner);
        return NULL;
@@ -924,11 +1029,10 @@ void ctf_scanner_free(struct ctf_scanner *scanner)
        int ret;
 
        finalize_scope(&scanner->root_scope);
-       free_strings(&scanner->allocated_strings);
-       ctf_ast_free(scanner->ast);
+       objstack_destroy(scanner->objstack);
        ret = yylex_destroy(scanner->scanner);
        if (ret)
-               fprintf(stderr, "yylex_destroy error\n");
+               printf_error("yylex_destroy error");
        free(scanner);
 }
 
@@ -936,6 +1040,7 @@ void ctf_scanner_free(struct ctf_scanner *scanner)
 
 %define api.pure
        /* %locations */
+%error-verbose
 %parse-param {struct ctf_scanner *scanner}
 %lex-param {struct ctf_scanner *scanner}
 /*
@@ -948,20 +1053,23 @@ void ctf_scanner_free(struct ctf_scanner *scanner)
  */
 %expect 2
 %start file
-%token CHARACTER_CONSTANT_START SQUOTE STRING_LITERAL_START DQUOTE ESCSEQ CHAR_STRING_TOKEN LSBRAC RSBRAC LPAREN RPAREN LBRAC RBRAC RARROW STAR PLUS MINUS LT GT TYPEASSIGN COLON SEMICOLON DOTDOTDOT DOT EQUAL COMMA CONST CHAR DOUBLE ENUM ENV EVENT FLOATING_POINT FLOAT INTEGER INT LONG SHORT SIGNED STREAM STRING STRUCT TRACE CALLSITE CLOCK TYPEALIAS TYPEDEF UNSIGNED VARIANT VOID _BOOL _COMPLEX _IMAGINARY DECIMAL_CONSTANT OCTAL_CONSTANT HEXADECIMAL_CONSTANT TOK_ALIGN
-%token <gs> IDENTIFIER ID_TYPE
+%token INTEGER_LITERAL STRING_LITERAL CHARACTER_LITERAL LSBRAC RSBRAC LPAREN RPAREN LBRAC RBRAC RARROW STAR PLUS MINUS LT GT TYPEASSIGN COLON SEMICOLON DOTDOTDOT DOT EQUAL COMMA CONST CHAR DOUBLE ENUM ENV EVENT FLOATING_POINT FLOAT INTEGER INT LONG SHORT SIGNED STREAM STRING STRUCT TRACE CALLSITE CLOCK TYPEALIAS TYPEDEF UNSIGNED VARIANT VOID _BOOL _COMPLEX _IMAGINARY TOK_ALIGN
+%token <s> IDENTIFIER ID_TYPE
 %token ERROR
 %union
 {
        long long ll;
+       unsigned long long ull;
        char c;
-       struct gc_string *gs;
+       char *s;
        struct ctf_node *n;
 }
 
-%type <gs> keywords
-%type <gs> s_char s_char_sequence c_char c_char_sequence
+%type <s> STRING_LITERAL CHARACTER_LITERAL
+
+%type <s> keywords
 
+%type <ull> INTEGER_LITERAL
 %type <n> postfix_expression unary_expression unary_expression_or_range
 
 %type <n> declaration
@@ -1018,96 +1126,61 @@ file:
 
 keywords:
                VOID
-               {       $$ = yylval.gs;         }
+               {       $$ = yylval.s;          }
        |       CHAR
-               {       $$ = yylval.gs;         }
+               {       $$ = yylval.s;          }
        |       SHORT
-               {       $$ = yylval.gs;         }
+               {       $$ = yylval.s;          }
        |       INT
-               {       $$ = yylval.gs;         }
+               {       $$ = yylval.s;          }
        |       LONG
-               {       $$ = yylval.gs;         }
+               {       $$ = yylval.s;          }
        |       FLOAT
-               {       $$ = yylval.gs;         }
+               {       $$ = yylval.s;          }
        |       DOUBLE
-               {       $$ = yylval.gs;         }
+               {       $$ = yylval.s;          }
        |       SIGNED
-               {       $$ = yylval.gs;         }
+               {       $$ = yylval.s;          }
        |       UNSIGNED
-               {       $$ = yylval.gs;         }
+               {       $$ = yylval.s;          }
        |       _BOOL
-               {       $$ = yylval.gs;         }
+               {       $$ = yylval.s;          }
        |       _COMPLEX
-               {       $$ = yylval.gs;         }
+               {       $$ = yylval.s;          }
        |       _IMAGINARY
-               {       $$ = yylval.gs;         }
+               {       $$ = yylval.s;          }
        |       FLOATING_POINT
-               {       $$ = yylval.gs;         }
+               {       $$ = yylval.s;          }
        |       INTEGER
-               {       $$ = yylval.gs;         }
+               {       $$ = yylval.s;          }
        |       STRING
-               {       $$ = yylval.gs;         }
+               {       $$ = yylval.s;          }
        |       ENUM
-               {       $$ = yylval.gs;         }
+               {       $$ = yylval.s;          }
        |       VARIANT
-               {       $$ = yylval.gs;         }
+               {       $$ = yylval.s;          }
        |       STRUCT
-               {       $$ = yylval.gs;         }
+               {       $$ = yylval.s;          }
        |       CONST
-               {       $$ = yylval.gs;         }
+               {       $$ = yylval.s;          }
        |       TYPEDEF
-               {       $$ = yylval.gs;         }
+               {       $$ = yylval.s;          }
        |       EVENT
-               {       $$ = yylval.gs;         }
+               {       $$ = yylval.s;          }
        |       STREAM
-               {       $$ = yylval.gs;         }
+               {       $$ = yylval.s;          }
        |       ENV
-               {       $$ = yylval.gs;         }
+               {       $$ = yylval.s;          }
        |       TRACE
-               {       $$ = yylval.gs;         }
+               {       $$ = yylval.s;          }
        |       CLOCK
-               {       $$ = yylval.gs;         }
+               {       $$ = yylval.s;          }
        |       CALLSITE
-               {       $$ = yylval.gs;         }
+               {       $$ = yylval.s;          }
        |       TOK_ALIGN
-               {       $$ = yylval.gs;         }
-       ;
-
-/* 1.5 Constants */
-
-c_char_sequence:
-               c_char
-               {       $$ = $1;                                        }
-       |       c_char_sequence c_char
-               {       $$ = gc_string_append(scanner, $1, $2);         }
-       ;
-
-c_char:
-               CHAR_STRING_TOKEN
-               {       $$ = yylval.gs;                                 }
-       |       ESCSEQ
-               {
-                       reparent_error(scanner, "escape sequences not supported yet");
-               }
+               {       $$ = yylval.s;          }
        ;
 
-/* 1.6 String literals */
-
-s_char_sequence:
-               s_char
-               {       $$ = $1;                                        }
-       |       s_char_sequence s_char
-               {       $$ = gc_string_append(scanner, $1, $2);         }
-       ;
-
-s_char:
-               CHAR_STRING_TOKEN
-               {       $$ = yylval.gs;                                 }
-       |       ESCSEQ
-               {
-                       reparent_error(scanner, "escape sequences not supported yet");
-               }
-       ;
 
 /* 2: Phrase structure grammar */
 
@@ -1116,64 +1189,41 @@ postfix_expression:
                {
                        $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
                        $$->u.unary_expression.type = UNARY_STRING;
-                       $$->u.unary_expression.u.string = yylval.gs->s;
+                       $$->u.unary_expression.u.string = yylval.s;
                }
        |       ID_TYPE
                {
                        $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
                        $$->u.unary_expression.type = UNARY_STRING;
-                       $$->u.unary_expression.u.string = yylval.gs->s;
+                       $$->u.unary_expression.u.string = yylval.s;
                }
        |       keywords
                {
                        $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
                        $$->u.unary_expression.type = UNARY_STRING;
-                       $$->u.unary_expression.u.string = yylval.gs->s;
-               }
-       |       DECIMAL_CONSTANT
-               {
-                       $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
-                       $$->u.unary_expression.type = UNARY_UNSIGNED_CONSTANT;
-                       sscanf(yylval.gs->s, "%" PRIu64,
-                              &$$->u.unary_expression.u.unsigned_constant);
-               }
-       |       OCTAL_CONSTANT
-               {
-                       $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
-                       $$->u.unary_expression.type = UNARY_UNSIGNED_CONSTANT;
-                       sscanf(yylval.gs->s, "0%" PRIo64,
-                              &$$->u.unary_expression.u.unsigned_constant);
+                       $$->u.unary_expression.u.string = yylval.s;
                }
-       |       HEXADECIMAL_CONSTANT
+       |       INTEGER_LITERAL
                {
                        $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
                        $$->u.unary_expression.type = UNARY_UNSIGNED_CONSTANT;
-                       sscanf(yylval.gs->s, "0x%" PRIx64,
-                              &$$->u.unary_expression.u.unsigned_constant);
+                       $$->u.unary_expression.u.unsigned_constant = $1;
                }
-       |       STRING_LITERAL_START DQUOTE
+       |       STRING_LITERAL
                {
                        $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
                        $$->u.unary_expression.type = UNARY_STRING;
-                       $$->u.unary_expression.u.string = "";
+                       $$->u.unary_expression.u.string = $1;
                }
-       |       STRING_LITERAL_START s_char_sequence DQUOTE
+       |       CHARACTER_LITERAL
                {
                        $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
                        $$->u.unary_expression.type = UNARY_STRING;
-                       $$->u.unary_expression.u.string = $2->s;
-               }
-       |       CHARACTER_CONSTANT_START c_char_sequence SQUOTE
-               {
-                       $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
-                       $$->u.unary_expression.type = UNARY_STRING;
-                       $$->u.unary_expression.u.string = $2->s;
+                       $$->u.unary_expression.u.string = $1;
                }
        |       LPAREN unary_expression RPAREN
                {
-                       $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
-                       $$->u.unary_expression.type = UNARY_NESTED;
-                       $$->u.unary_expression.u.nested_exp = $2;
+                       $$ = $2;
                }
        |       postfix_expression LSBRAC unary_expression RSBRAC
                {
@@ -1187,7 +1237,7 @@ postfix_expression:
                {
                        $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
                        $$->u.unary_expression.type = UNARY_STRING;
-                       $$->u.unary_expression.u.string = yylval.gs->s;
+                       $$->u.unary_expression.u.string = yylval.s;
                        $$->u.unary_expression.link = UNARY_DOTLINK;
                        bt_list_splice(&($1)->tmp_head, &($$)->tmp_head);
                        bt_list_add_tail(&($$)->siblings, &($$)->tmp_head);
@@ -1196,7 +1246,7 @@ postfix_expression:
                {
                        $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
                        $$->u.unary_expression.type = UNARY_STRING;
-                       $$->u.unary_expression.u.string = yylval.gs->s;
+                       $$->u.unary_expression.u.string = yylval.s;
                        $$->u.unary_expression.link = UNARY_DOTLINK;
                        bt_list_splice(&($1)->tmp_head, &($$)->tmp_head);
                        bt_list_add_tail(&($$)->siblings, &($$)->tmp_head);
@@ -1205,7 +1255,7 @@ postfix_expression:
                {
                        $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
                        $$->u.unary_expression.type = UNARY_STRING;
-                       $$->u.unary_expression.u.string = yylval.gs->s;
+                       $$->u.unary_expression.u.string = yylval.s;
                        $$->u.unary_expression.link = UNARY_ARROWLINK;
                        bt_list_splice(&($1)->tmp_head, &($$)->tmp_head);
                        bt_list_add_tail(&($$)->siblings, &($$)->tmp_head);
@@ -1214,7 +1264,7 @@ postfix_expression:
                {
                        $$ = make_node(scanner, NODE_UNARY_EXPRESSION);
                        $$->u.unary_expression.type = UNARY_STRING;
-                       $$->u.unary_expression.u.string = yylval.gs->s;
+                       $$->u.unary_expression.u.string = yylval.s;
                        $$->u.unary_expression.link = UNARY_ARROWLINK;
                        bt_list_splice(&($1)->tmp_head, &($$)->tmp_head);
                        bt_list_add_tail(&($$)->siblings, &($$)->tmp_head);
@@ -1225,21 +1275,25 @@ unary_expression:
                postfix_expression
                {       $$ = $1;                                }
        |       PLUS postfix_expression
-               {       $$ = $2;                                }
-       |       MINUS postfix_expression
                {
                        $$ = $2;
-                       if ($$->u.unary_expression.type != UNARY_SIGNED_CONSTANT
-                               && $$->u.unary_expression.type != UNARY_UNSIGNED_CONSTANT)
+                       if ($$->u.unary_expression.type != UNARY_UNSIGNED_CONSTANT
+                               && $$->u.unary_expression.type != UNARY_SIGNED_CONSTANT) {
                                reparent_error(scanner, "expecting numeric constant");
-
+                       }
+               }
+       |       MINUS postfix_expression
+               {
+                       $$ = $2;
                        if ($$->u.unary_expression.type == UNARY_UNSIGNED_CONSTANT) {
                                $$->u.unary_expression.type = UNARY_SIGNED_CONSTANT;
                                $$->u.unary_expression.u.signed_constant =
                                        -($$->u.unary_expression.u.unsigned_constant);
-                       } else {
+                       } else if ($$->u.unary_expression.type == UNARY_UNSIGNED_CONSTANT) {
                                $$->u.unary_expression.u.signed_constant =
                                        -($$->u.unary_expression.u.signed_constant);
+                       } else {
+                               reparent_error(scanner, "expecting numeric constant");
                        }
                }
        ;
@@ -1580,7 +1634,7 @@ integer_type_specifier:
                {
                        $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
                        $$->u.type_specifier.type = TYPESPEC_ID_TYPE;
-                       $$->u.type_specifier.id_type = yylval.gs->s;
+                       $$->u.type_specifier.id_type = yylval.s;
                }
        |       INTEGER LBRAC RBRAC
                {
@@ -1663,7 +1717,7 @@ type_specifier:
                {
                        $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
                        $$->u.type_specifier.type = TYPESPEC_ID_TYPE;
-                       $$->u.type_specifier.id_type = yylval.gs->s;
+                       $$->u.type_specifier.id_type = yylval.s;
                }
        |       FLOATING_POINT LBRAC RBRAC
                {
@@ -1745,7 +1799,7 @@ struct_type_specifier:
                {
                        $$ = make_node(scanner, NODE_STRUCT);
                        $$->u._struct.has_body = 1;
-                       $$->u._struct.name = $1->s;
+                       $$->u._struct.name = $1;
                        if ($3 && set_parent_node($3, $$))
                                reparent_error(scanner, "struct reparent error");
                }
@@ -1753,7 +1807,7 @@ struct_type_specifier:
                {
                        $$ = make_node(scanner, NODE_STRUCT);
                        $$->u._struct.has_body = 1;
-                       $$->u._struct.name = $1->s;
+                       $$->u._struct.name = $1;
                        if ($3 && set_parent_node($3, $$))
                                reparent_error(scanner, "struct reparent error");
                }
@@ -1761,13 +1815,13 @@ struct_type_specifier:
                {
                        $$ = make_node(scanner, NODE_STRUCT);
                        $$->u._struct.has_body = 0;
-                       $$->u._struct.name = $1->s;
+                       $$->u._struct.name = $1;
                }
        |       ID_TYPE
                {
                        $$ = make_node(scanner, NODE_STRUCT);
                        $$->u._struct.has_body = 0;
-                       $$->u._struct.name = $1->s;
+                       $$->u._struct.name = $1;
                }
        |       struct_declaration_begin struct_or_variant_declaration_list struct_declaration_end TOK_ALIGN LPAREN unary_expression RPAREN
                {
@@ -1781,7 +1835,7 @@ struct_type_specifier:
                {
                        $$ = make_node(scanner, NODE_STRUCT);
                        $$->u._struct.has_body = 1;
-                       $$->u._struct.name = $1->s;
+                       $$->u._struct.name = $1;
                        bt_list_add_tail(&($7)->siblings, &$$->u._struct.min_align);
                        if ($3 && set_parent_node($3, $$))
                                reparent_error(scanner, "struct reparent error");
@@ -1790,7 +1844,7 @@ struct_type_specifier:
                {
                        $$ = make_node(scanner, NODE_STRUCT);
                        $$->u._struct.has_body = 1;
-                       $$->u._struct.name = $1->s;
+                       $$->u._struct.name = $1;
                        bt_list_add_tail(&($7)->siblings, &$$->u._struct.min_align);
                        if ($3 && set_parent_node($3, $$))
                                reparent_error(scanner, "struct reparent error");
@@ -1819,7 +1873,7 @@ variant_type_specifier:
                {
                        $$ = make_node(scanner, NODE_VARIANT);
                        $$->u.variant.has_body = 1;
-                       $$->u.variant.choice = $2->s;
+                       $$->u.variant.choice = $2;
                        if ($5 && set_parent_node($5, $$))
                                reparent_error(scanner, "variant reparent error");
                }
@@ -1827,7 +1881,7 @@ variant_type_specifier:
                {
                        $$ = make_node(scanner, NODE_VARIANT);
                        $$->u.variant.has_body = 1;
-                       $$->u.variant.choice = $2->s;
+                       $$->u.variant.choice = $2;
                        if ($5 && set_parent_node($5, $$))
                                reparent_error(scanner, "variant reparent error");
                }
@@ -1835,7 +1889,7 @@ variant_type_specifier:
                {
                        $$ = make_node(scanner, NODE_VARIANT);
                        $$->u.variant.has_body = 1;
-                       $$->u.variant.name = $1->s;
+                       $$->u.variant.name = $1;
                        if ($3 && set_parent_node($3, $$))
                                reparent_error(scanner, "variant reparent error");
                }
@@ -1843,8 +1897,8 @@ variant_type_specifier:
                {
                        $$ = make_node(scanner, NODE_VARIANT);
                        $$->u.variant.has_body = 1;
-                       $$->u.variant.name = $1->s;
-                       $$->u.variant.choice = $3->s;
+                       $$->u.variant.name = $1;
+                       $$->u.variant.choice = $3;
                        if ($6 && set_parent_node($6, $$))
                                reparent_error(scanner, "variant reparent error");
                }
@@ -1852,15 +1906,15 @@ variant_type_specifier:
                {
                        $$ = make_node(scanner, NODE_VARIANT);
                        $$->u.variant.has_body = 0;
-                       $$->u.variant.name = $1->s;
-                       $$->u.variant.choice = $3->s;
+                       $$->u.variant.name = $1;
+                       $$->u.variant.choice = $3;
                }
        |       IDENTIFIER LT ID_TYPE GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
                {
                        $$ = make_node(scanner, NODE_VARIANT);
                        $$->u.variant.has_body = 1;
-                       $$->u.variant.name = $1->s;
-                       $$->u.variant.choice = $3->s;
+                       $$->u.variant.name = $1;
+                       $$->u.variant.choice = $3;
                        if ($6 && set_parent_node($6, $$))
                                reparent_error(scanner, "variant reparent error");
                }
@@ -1868,14 +1922,14 @@ variant_type_specifier:
                {
                        $$ = make_node(scanner, NODE_VARIANT);
                        $$->u.variant.has_body = 0;
-                       $$->u.variant.name = $1->s;
-                       $$->u.variant.choice = $3->s;
+                       $$->u.variant.name = $1;
+                       $$->u.variant.choice = $3;
                }
        |       ID_TYPE variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
                {
                        $$ = make_node(scanner, NODE_VARIANT);
                        $$->u.variant.has_body = 1;
-                       $$->u.variant.name = $1->s;
+                       $$->u.variant.name = $1;
                        if ($3 && set_parent_node($3, $$))
                                reparent_error(scanner, "variant reparent error");
                }
@@ -1883,8 +1937,8 @@ variant_type_specifier:
                {
                        $$ = make_node(scanner, NODE_VARIANT);
                        $$->u.variant.has_body = 1;
-                       $$->u.variant.name = $1->s;
-                       $$->u.variant.choice = $3->s;
+                       $$->u.variant.name = $1;
+                       $$->u.variant.choice = $3;
                        if ($6 && set_parent_node($6, $$))
                                reparent_error(scanner, "variant reparent error");
                }
@@ -1892,15 +1946,15 @@ variant_type_specifier:
                {
                        $$ = make_node(scanner, NODE_VARIANT);
                        $$->u.variant.has_body = 0;
-                       $$->u.variant.name = $1->s;
-                       $$->u.variant.choice = $3->s;
+                       $$->u.variant.name = $1;
+                       $$->u.variant.choice = $3;
                }
        |       ID_TYPE LT ID_TYPE GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end
                {
                        $$ = make_node(scanner, NODE_VARIANT);
                        $$->u.variant.has_body = 1;
-                       $$->u.variant.name = $1->s;
-                       $$->u.variant.choice = $3->s;
+                       $$->u.variant.name = $1;
+                       $$->u.variant.choice = $3;
                        if ($6 && set_parent_node($6, $$))
                                reparent_error(scanner, "variant reparent error");
                }
@@ -1908,8 +1962,8 @@ variant_type_specifier:
                {
                        $$ = make_node(scanner, NODE_VARIANT);
                        $$->u.variant.has_body = 0;
-                       $$->u.variant.name = $1->s;
-                       $$->u.variant.choice = $3->s;
+                       $$->u.variant.name = $1;
+                       $$->u.variant.choice = $3;
                }
        ;
 
@@ -1941,14 +1995,14 @@ enum_type_specifier:
                {
                        $$ = make_node(scanner, NODE_ENUM);
                        $$->u._enum.has_body = 1;
-                       $$->u._enum.enum_id = $1->s;
+                       $$->u._enum.enum_id = $1;
                        _bt_list_splice_tail(&($3)->tmp_head, &($$)->u._enum.enumerator_list);
                }
        |       IDENTIFIER COLON integer_declaration_specifiers LBRAC enumerator_list RBRAC
                {
                        $$ = make_node(scanner, NODE_ENUM);
                        $$->u._enum.has_body = 1;
-                       $$->u._enum.enum_id = $1->s;
+                       $$->u._enum.enum_id = $1;
                        ($$)->u._enum.container_type = $3;
                        _bt_list_splice_tail(&($5)->tmp_head, &($$)->u._enum.enumerator_list);
                }
@@ -1956,14 +2010,14 @@ enum_type_specifier:
                {
                        $$ = make_node(scanner, NODE_ENUM);
                        $$->u._enum.has_body = 1;
-                       $$->u._enum.enum_id = $1->s;
+                       $$->u._enum.enum_id = $1;
                        _bt_list_splice_tail(&($3)->tmp_head, &($$)->u._enum.enumerator_list);
                }
        |       ID_TYPE COLON integer_declaration_specifiers LBRAC enumerator_list RBRAC
                {
                        $$ = make_node(scanner, NODE_ENUM);
                        $$->u._enum.has_body = 1;
-                       $$->u._enum.enum_id = $1->s;
+                       $$->u._enum.enum_id = $1;
                        ($$)->u._enum.container_type = $3;
                        _bt_list_splice_tail(&($5)->tmp_head, &($$)->u._enum.enumerator_list);
                }
@@ -1984,14 +2038,14 @@ enum_type_specifier:
                {
                        $$ = make_node(scanner, NODE_ENUM);
                        $$->u._enum.has_body = 1;
-                       $$->u._enum.enum_id = $1->s;
+                       $$->u._enum.enum_id = $1;
                        _bt_list_splice_tail(&($3)->tmp_head, &($$)->u._enum.enumerator_list);
                }
        |       IDENTIFIER COLON integer_declaration_specifiers LBRAC enumerator_list COMMA RBRAC
                {
                        $$ = make_node(scanner, NODE_ENUM);
                        $$->u._enum.has_body = 1;
-                       $$->u._enum.enum_id = $1->s;
+                       $$->u._enum.enum_id = $1;
                        ($$)->u._enum.container_type = $3;
                        _bt_list_splice_tail(&($5)->tmp_head, &($$)->u._enum.enumerator_list);
                }
@@ -1999,20 +2053,20 @@ enum_type_specifier:
                {
                        $$ = make_node(scanner, NODE_ENUM);
                        $$->u._enum.has_body = 0;
-                       $$->u._enum.enum_id = $1->s;
+                       $$->u._enum.enum_id = $1;
                }
        |       ID_TYPE LBRAC enumerator_list COMMA RBRAC
                {
                        $$ = make_node(scanner, NODE_ENUM);
                        $$->u._enum.has_body = 1;
-                       $$->u._enum.enum_id = $1->s;
+                       $$->u._enum.enum_id = $1;
                        _bt_list_splice_tail(&($3)->tmp_head, &($$)->u._enum.enumerator_list);
                }
        |       ID_TYPE COLON integer_declaration_specifiers LBRAC enumerator_list COMMA RBRAC
                {
                        $$ = make_node(scanner, NODE_ENUM);
                        $$->u._enum.has_body = 1;
-                       $$->u._enum.enum_id = $1->s;
+                       $$->u._enum.enum_id = $1;
                        ($$)->u._enum.container_type = $3;
                        _bt_list_splice_tail(&($5)->tmp_head, &($$)->u._enum.enumerator_list);
                }
@@ -2020,7 +2074,7 @@ enum_type_specifier:
                {
                        $$ = make_node(scanner, NODE_ENUM);
                        $$->u._enum.has_body = 0;
-                       $$->u._enum.enum_id = $1->s;
+                       $$->u._enum.enum_id = $1;
                }
        ;
 
@@ -2127,7 +2181,7 @@ alias_declaration_specifiers:
                        $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
                        node = make_node(scanner, NODE_TYPE_SPECIFIER);
                        node->u.type_specifier.type = TYPESPEC_ID_TYPE;
-                       node->u.type_specifier.id_type = yylval.gs->s;
+                       node->u.type_specifier.id_type = yylval.s;
                        bt_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
                }
        |       alias_declaration_specifiers CONST
@@ -2152,7 +2206,7 @@ alias_declaration_specifiers:
                        $$ = $1;
                        node = make_node(scanner, NODE_TYPE_SPECIFIER);
                        node->u.type_specifier.type = TYPESPEC_ID_TYPE;
-                       node->u.type_specifier.id_type = yylval.gs->s;
+                       node->u.type_specifier.id_type = yylval.s;
                        bt_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
                }
        ;
@@ -2194,57 +2248,46 @@ enumerator:
                IDENTIFIER
                {
                        $$ = make_node(scanner, NODE_ENUMERATOR);
-                       $$->u.enumerator.id = $1->s;
+                       $$->u.enumerator.id = $1;
                }
        |       ID_TYPE
                {
                        $$ = make_node(scanner, NODE_ENUMERATOR);
-                       $$->u.enumerator.id = $1->s;
+                       $$->u.enumerator.id = $1;
                }
        |       keywords
                {
                        $$ = make_node(scanner, NODE_ENUMERATOR);
-                       $$->u.enumerator.id = $1->s;
+                       $$->u.enumerator.id = $1;
                }
-       |       STRING_LITERAL_START DQUOTE
+       |       STRING_LITERAL
                {
                        $$ = make_node(scanner, NODE_ENUMERATOR);
-                       $$->u.enumerator.id = "";
-               }
-       |       STRING_LITERAL_START s_char_sequence DQUOTE
-               {
-                       $$ = make_node(scanner, NODE_ENUMERATOR);
-                       $$->u.enumerator.id = $2->s;
+                       $$->u.enumerator.id = $1;
                }
        |       IDENTIFIER EQUAL unary_expression_or_range
                {
                        $$ = make_node(scanner, NODE_ENUMERATOR);
-                       $$->u.enumerator.id = $1->s;
+                       $$->u.enumerator.id = $1;
                        bt_list_splice(&($3)->tmp_head, &($$)->u.enumerator.values);
                }
        |       ID_TYPE EQUAL unary_expression_or_range
                {
                        $$ = make_node(scanner, NODE_ENUMERATOR);
-                       $$->u.enumerator.id = $1->s;
+                       $$->u.enumerator.id = $1;
                        bt_list_splice(&($3)->tmp_head, &($$)->u.enumerator.values);
                }
        |       keywords EQUAL unary_expression_or_range
                {
                        $$ = make_node(scanner, NODE_ENUMERATOR);
-                       $$->u.enumerator.id = $1->s;
+                       $$->u.enumerator.id = $1;
                        bt_list_splice(&($3)->tmp_head, &($$)->u.enumerator.values);
                }
-       |       STRING_LITERAL_START DQUOTE EQUAL unary_expression_or_range
+       |       STRING_LITERAL EQUAL unary_expression_or_range
                {
                        $$ = make_node(scanner, NODE_ENUMERATOR);
-                       $$->u.enumerator.id = "";
-                       bt_list_splice(&($4)->tmp_head, &($$)->u.enumerator.values);
-               }
-       |       STRING_LITERAL_START s_char_sequence DQUOTE EQUAL unary_expression_or_range
-               {
-                       $$ = make_node(scanner, NODE_ENUMERATOR);
-                       $$->u.enumerator.id = $2->s;
-                       bt_list_splice(&($5)->tmp_head, &($$)->u.enumerator.values);
+                       $$->u.enumerator.id = $1;
+                       bt_list_splice(&($3)->tmp_head, &($$)->u.enumerator.values);
                }
        ;
 
@@ -2279,7 +2322,7 @@ direct_abstract_declarator:
                {
                        $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
                        $$->u.type_declarator.type = TYPEDEC_ID;
-                       $$->u.type_declarator.u.id = $1->s;
+                       $$->u.type_declarator.u.id = $1;
                }
        |       LPAREN abstract_declarator RPAREN
                {
@@ -2369,7 +2412,7 @@ direct_declarator:
                {
                        $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
                        $$->u.type_declarator.type = TYPEDEC_ID;
-                       $$->u.type_declarator.u.id = $1->s;
+                       $$->u.type_declarator.u.id = $1;
                }
        |       LPAREN declarator RPAREN
                {
@@ -2403,7 +2446,7 @@ direct_type_declarator:
                        add_type(scanner, $1);
                        $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
                        $$->u.type_declarator.type = TYPEDEC_ID;
-                       $$->u.type_declarator.u.id = $1->s;
+                       $$->u.type_declarator.u.id = $1;
                }
        |       LPAREN type_declarator RPAREN
                {
diff --git a/formats/ctf/metadata/ctf-scanner-symbols.h b/formats/ctf/metadata/ctf-scanner-symbols.h
new file mode 100644 (file)
index 0000000..9b9e363
--- /dev/null
@@ -0,0 +1,50 @@
+#ifndef _CTF_SCANNER_SYMBOLS
+#define _CTF_SCANNER_SYMBOLS
+
+/*
+ * ctf-scanner-symbols.h
+ *
+ * Copyright 2011-2012 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ */
+
+#define yy_create_buffer bt_yy_create_buffer
+#define yy_delete_buffer bt_yy_delete_buffer
+#define yy_flush_buffer bt_yy_flush_buffer
+#define yy_scan_buffer bt_yy_scan_buffer
+#define yy_scan_bytes bt_yy_scan_bytes
+#define yy_scan_string bt_yy_scan_string
+#define yy_switch_to_buffer bt_yy_switch_to_buffer
+#define yyalloc bt_yyalloc
+#define yyfree bt_yyfree
+#define yyget_column bt_yyget_column
+#define yyget_debug bt_yyget_debug
+#define yyget_extra bt_yyget_extra
+#define yyget_in bt_yyget_in
+#define yyget_leng bt_yyget_leng
+#define yyget_lineno bt_yyget_lineno
+#define yyget_lval bt_yyget_lval
+#define yyget_out bt_yyget_out
+#define yyget_text bt_yyget_text
+#define yylex_init bt_yylex_init
+#define yypop_buffer_state bt_yypop_buffer_state
+#define yypush_buffer_state bt_yypush_buffer_state
+#define yyrealloc bt_yyrealloc
+#define yyset_column bt_yyset_column
+#define yyset_debug bt_yyset_debug
+#define yyset_extra bt_yyset_extra
+#define yyset_in bt_yyset_in
+#define yyset_lineno bt_yyset_lineno
+#define yyset_lval bt_yyset_lval
+#define yyset_out bt_yyset_out
+
+#endif /* _CTF_SCANNER_SYMBOLS */
index d5650d0a703e7fb39fb77fbf54079243351895dc..012a4f3b9a6cb5d2a074a9f127c124c463643298 100644 (file)
@@ -36,7 +36,7 @@ struct ctf_scanner {
        struct ctf_ast *ast;
        struct ctf_scanner_scope root_scope;
        struct ctf_scanner_scope *cs;
-       struct bt_list_head allocated_strings;
+       struct objstack *objstack;
 };
 
 struct ctf_scanner *ctf_scanner_alloc(FILE *input);
@@ -49,7 +49,7 @@ struct ctf_ast *ctf_scanner_get_ast(struct ctf_scanner *scanner)
        return scanner->ast;
 }
 
-__attribute__((visibility("hidden")))
+BT_HIDDEN
 int is_type(struct ctf_scanner *scanner, const char *id);
 
 #endif /* _CTF_SCANNER_H */
index c32aa990fc23b952f9e5c827532796e1d22c28d1..664d0af13f2c60faec9e63621c32e6e07cb7037c 100644 (file)
@@ -36,7 +36,7 @@
 #include <babeltrace/list.h>
 #include <babeltrace/types.h>
 #include <babeltrace/ctf/metadata.h>
-#include <babeltrace/uuid.h>
+#include <babeltrace/compat/uuid.h>
 #include <babeltrace/endian.h>
 #include <babeltrace/ctf/events-internal.h>
 #include "ctf-scanner.h"
@@ -58,7 +58,7 @@ struct last_enum_value {
 int opt_clock_force_correlate;
 
 static
-struct declaration *ctf_type_specifier_list_visit(FILE *fd,
+struct bt_declaration *ctf_type_specifier_list_visit(FILE *fd,
                int depth, struct ctf_node *type_specifier_list,
                struct declaration_scope *declaration_scope,
                struct ctf_trace *trace);
@@ -95,10 +95,11 @@ char *concatenate_unary_strings(struct bt_list_head *head)
        bt_list_for_each_entry(node, head, siblings) {
                char *src_string;
 
-               assert(node->type == NODE_UNARY_EXPRESSION);
-               assert(node->u.unary_expression.type == UNARY_STRING);
-               assert((node->u.unary_expression.link == UNARY_LINK_UNKNOWN)
-                       ^ (i != 0));
+               if (node->type != NODE_UNARY_EXPRESSION
+                               || node->u.unary_expression.type != UNARY_STRING
+                               || !((node->u.unary_expression.link != UNARY_LINK_UNKNOWN)
+                                       ^ (i == 0)))
+                       return NULL;
                switch (node->u.unary_expression.link) {
                case UNARY_DOTLINK:
                        g_string_append(str, ".");
@@ -129,10 +130,11 @@ GQuark get_map_clock_name_value(struct bt_list_head *head)
        bt_list_for_each_entry(node, head, siblings) {
                char *src_string;
 
-               assert(node->type == NODE_UNARY_EXPRESSION);
-               assert(node->u.unary_expression.type == UNARY_STRING);
-               assert((node->u.unary_expression.link == UNARY_LINK_UNKNOWN)
-                       ^ (i != 0));
+               if (node->type != NODE_UNARY_EXPRESSION
+                       || node->u.unary_expression.type != UNARY_STRING
+                       || !((node->u.unary_expression.link != UNARY_LINK_UNKNOWN)
+                               ^ (i == 0)))
+                       return 0;
                /* needs to be chained with . */
                switch (node->u.unary_expression.link) {
                case UNARY_DOTLINK:
@@ -184,10 +186,11 @@ int get_unary_unsigned(struct bt_list_head *head, uint64_t *value)
        int i = 0;
 
        bt_list_for_each_entry(node, head, siblings) {
-               assert(node->type == NODE_UNARY_EXPRESSION);
-               assert(node->u.unary_expression.type == UNARY_UNSIGNED_CONSTANT);
-               assert(node->u.unary_expression.link == UNARY_LINK_UNKNOWN);
-               assert(i == 0);
+               if (node->type != NODE_UNARY_EXPRESSION
+                               || node->u.unary_expression.type != UNARY_UNSIGNED_CONSTANT
+                               || node->u.unary_expression.link != UNARY_LINK_UNKNOWN
+                               || i != 0)
+                       return -EINVAL;
                *value = node->u.unary_expression.u.unsigned_constant;
                i++;
        }
@@ -215,11 +218,12 @@ int get_unary_signed(struct bt_list_head *head, int64_t *value)
        int i = 0;
 
        bt_list_for_each_entry(node, head, siblings) {
-               assert(node->type == NODE_UNARY_EXPRESSION);
-               assert(node->u.unary_expression.type == UNARY_UNSIGNED_CONSTANT
-                       || node->u.unary_expression.type == UNARY_SIGNED_CONSTANT);
-               assert(node->u.unary_expression.link == UNARY_LINK_UNKNOWN);
-               assert(i == 0);
+               if (node->type != NODE_UNARY_EXPRESSION
+                               || node->u.unary_expression.type != UNARY_UNSIGNED_CONSTANT
+                               || (node->u.unary_expression.type != UNARY_UNSIGNED_CONSTANT && node->u.unary_expression.type != UNARY_SIGNED_CONSTANT)
+                               || node->u.unary_expression.link != UNARY_LINK_UNKNOWN
+                               || i != 0)
+                       return -EINVAL;
                switch (node->u.unary_expression.type) {
                case UNARY_UNSIGNED_CONSTANT:
                        *value = (int64_t) node->u.unary_expression.u.unsigned_constant;
@@ -228,7 +232,7 @@ int get_unary_signed(struct bt_list_head *head, int64_t *value)
                        *value = node->u.unary_expression.u.signed_constant;
                        break;
                default:
-                       assert(0);
+                       return -EINVAL;
                }
                i++;
        }
@@ -245,10 +249,11 @@ int get_unary_uuid(struct bt_list_head *head, unsigned char *uuid)
        bt_list_for_each_entry(node, head, siblings) {
                const char *src_string;
 
-               assert(node->type == NODE_UNARY_EXPRESSION);
-               assert(node->u.unary_expression.type == UNARY_STRING);
-               assert(node->u.unary_expression.link == UNARY_LINK_UNKNOWN);
-               assert(i == 0);
+               if (node->type != NODE_UNARY_EXPRESSION
+                               || node->u.unary_expression.type != UNARY_STRING
+                               || node->u.unary_expression.link != UNARY_LINK_UNKNOWN
+                               || i != 0)
+                       return -EINVAL;
                src_string = node->u.unary_expression.u.string;
                ret = babeltrace_uuid_parse(src_string, uuid);
        }
@@ -266,13 +271,14 @@ struct ctf_stream_declaration *trace_stream_lookup(struct ctf_trace *trace, uint
 static
 struct ctf_clock *trace_clock_lookup(struct ctf_trace *trace, GQuark clock_name)
 {
-       return g_hash_table_lookup(trace->clocks, (gpointer) (unsigned long) clock_name);
+       return g_hash_table_lookup(trace->parent.clocks, (gpointer) (unsigned long) clock_name);
 }
 
 static
 int visit_type_specifier(FILE *fd, struct ctf_node *type_specifier, GString *str)
 {
-       assert(type_specifier->type == NODE_TYPE_SPECIFIER);
+       if (type_specifier->type != NODE_TYPE_SPECIFIER)
+               return -EINVAL;
 
        switch (type_specifier->u.type_specifier.type) {
        case TYPESPEC_VOID:
@@ -411,12 +417,12 @@ GQuark create_typealias_identifier(FILE *fd, int depth,
 }
 
 static
-struct declaration *ctf_type_declarator_visit(FILE *fd, int depth,
+struct bt_declaration *ctf_type_declarator_visit(FILE *fd, int depth,
        struct ctf_node *type_specifier_list,
        GQuark *field_name,
        struct ctf_node *node_type_declarator,
        struct declaration_scope *declaration_scope,
-       struct declaration *nested_declaration,
+       struct bt_declaration *nested_declaration,
        struct ctf_trace *trace)
 {
        /*
@@ -426,7 +432,9 @@ struct declaration *ctf_type_declarator_visit(FILE *fd, int depth,
         */
 
        if (node_type_declarator) {
-               assert(node_type_declarator->u.type_declarator.type != TYPEDEC_UNKNOWN);
+               if (node_type_declarator->u.type_declarator.type == TYPEDEC_UNKNOWN) {
+                       return NULL;
+               }
 
                /* TODO: gcc bitfields not supported yet. */
                if (node_type_declarator->u.type_declarator.bitfield_len != NULL) {
@@ -445,7 +453,7 @@ struct declaration *ctf_type_declarator_visit(FILE *fd, int depth,
                         */
                        alias_q = create_typealias_identifier(fd, depth,
                                type_specifier_list, node_type_declarator);
-                       nested_declaration = lookup_declaration(alias_q, declaration_scope);
+                       nested_declaration = bt_lookup_declaration(alias_q, declaration_scope);
                        if (!nested_declaration) {
                                fprintf(fd, "[error] %s: cannot find typealias \"%s\".\n", __func__, g_quark_to_string(alias_q));
                                return NULL;
@@ -460,7 +468,7 @@ struct declaration *ctf_type_declarator_visit(FILE *fd, int depth,
                                         * integer declaration to modify it. There could be other references to
                                         * it.
                                         */
-                                       integer_declaration = integer_declaration_new(integer_declaration->len,
+                                       integer_declaration = bt_integer_declaration_new(integer_declaration->len,
                                                integer_declaration->byte_order, integer_declaration->signedness,
                                                integer_declaration->p.alignment, 16, integer_declaration->encoding,
                                                integer_declaration->clock);
@@ -483,7 +491,7 @@ struct declaration *ctf_type_declarator_visit(FILE *fd, int depth,
                        *field_name = 0;
                return nested_declaration;
        } else {
-               struct declaration *declaration;
+               struct bt_declaration *declaration;
                struct ctf_node *first;
 
                /* TYPEDEC_NESTED */
@@ -500,7 +508,9 @@ struct declaration *ctf_type_declarator_visit(FILE *fd, int depth,
                }
                first = _bt_list_first_entry(&node_type_declarator->u.type_declarator.u.nested.length, 
                                struct ctf_node, siblings);
-               assert(first->type == NODE_UNARY_EXPRESSION);
+               if (first->type != NODE_UNARY_EXPRESSION) {
+                       return NULL;
+               }
 
                switch (first->u.unary_expression.type) {
                case UNARY_UNSIGNED_CONSTANT:
@@ -509,14 +519,14 @@ struct declaration *ctf_type_declarator_visit(FILE *fd, int depth,
                        size_t len;
 
                        len = first->u.unary_expression.u.unsigned_constant;
-                       array_declaration = array_declaration_new(len, nested_declaration,
+                       array_declaration = bt_array_declaration_new(len, nested_declaration,
                                                declaration_scope);
 
                        if (!array_declaration) {
                                fprintf(fd, "[error] %s: cannot create array declaration.\n", __func__);
                                return NULL;
                        }
-                       declaration_unref(nested_declaration);
+                       bt_declaration_unref(nested_declaration);
                        declaration = &array_declaration->p;
                        break;
                }
@@ -526,19 +536,21 @@ struct declaration *ctf_type_declarator_visit(FILE *fd, int depth,
                        char *length_name = concatenate_unary_strings(&node_type_declarator->u.type_declarator.u.nested.length);
                        struct declaration_sequence *sequence_declaration;
 
-                       sequence_declaration = sequence_declaration_new(length_name, nested_declaration, declaration_scope);
+                       if (!length_name)
+                               return NULL;
+                       sequence_declaration = bt_sequence_declaration_new(length_name, nested_declaration, declaration_scope);
                        if (!sequence_declaration) {
                                fprintf(fd, "[error] %s: cannot create sequence declaration.\n", __func__);
                                g_free(length_name);
                                return NULL;
                        }
-                       declaration_unref(nested_declaration);
+                       bt_declaration_unref(nested_declaration);
                        declaration = &sequence_declaration->p;
                        g_free(length_name);
                        break;
                }
                default:
-                       assert(0);
+                       return NULL;
                }
 
                /* Pass it as content of outer container */
@@ -562,7 +574,7 @@ int ctf_struct_type_declarators_visit(FILE *fd, int depth,
        GQuark field_name;
 
        bt_list_for_each_entry(iter, type_declarators, siblings) {
-               struct declaration *field_declaration;
+               struct bt_declaration *field_declaration;
 
                field_declaration = ctf_type_declarator_visit(fd, depth,
                                                type_specifier_list,
@@ -575,15 +587,15 @@ int ctf_struct_type_declarators_visit(FILE *fd, int depth,
                }
 
                /* Check if field with same name already exists */
-               if (struct_declaration_lookup_field_index(struct_declaration, field_name) >= 0) {
+               if (bt_struct_declaration_lookup_field_index(struct_declaration, field_name) >= 0) {
                        fprintf(fd, "[error] %s: duplicate field %s in struct\n", __func__, g_quark_to_string(field_name));
                        return -EINVAL;
                }
 
-               struct_declaration_add_field(struct_declaration,
+               bt_struct_declaration_add_field(struct_declaration,
                                             g_quark_to_string(field_name),
                                             field_declaration);
-               declaration_unref(field_declaration);
+               bt_declaration_unref(field_declaration);
        }
        return 0;
 }
@@ -600,7 +612,7 @@ int ctf_variant_type_declarators_visit(FILE *fd, int depth,
        GQuark field_name;
 
        bt_list_for_each_entry(iter, type_declarators, siblings) {
-               struct declaration *field_declaration;
+               struct bt_declaration *field_declaration;
 
                field_declaration = ctf_type_declarator_visit(fd, depth,
                                                type_specifier_list,
@@ -612,15 +624,15 @@ int ctf_variant_type_declarators_visit(FILE *fd, int depth,
                        return -EINVAL;
                }
 
-               if (untagged_variant_declaration_get_field_from_tag(untagged_variant_declaration, field_name) != NULL) {
+               if (bt_untagged_variant_declaration_get_field_from_tag(untagged_variant_declaration, field_name) != NULL) {
                        fprintf(fd, "[error] %s: duplicate field %s in variant\n", __func__, g_quark_to_string(field_name));
                        return -EINVAL;
                }
 
-               untagged_variant_declaration_add_field(untagged_variant_declaration,
+               bt_untagged_variant_declaration_add_field(untagged_variant_declaration,
                                              g_quark_to_string(field_name),
                                              field_declaration);
-               declaration_unref(field_declaration);
+               bt_declaration_unref(field_declaration);
        }
        return 0;
 }
@@ -635,9 +647,9 @@ int ctf_typedef_visit(FILE *fd, int depth, struct declaration_scope *scope,
        GQuark identifier;
 
        bt_list_for_each_entry(iter, type_declarators, siblings) {
-               struct declaration *type_declaration;
+               struct bt_declaration *type_declaration;
                int ret;
-       
+
                type_declaration = ctf_type_declarator_visit(fd, depth,
                                        type_specifier_list,
                                        &identifier, iter,
@@ -652,15 +664,15 @@ int ctf_typedef_visit(FILE *fd, int depth, struct declaration_scope *scope,
                 */
                if (type_declaration->id == CTF_TYPE_UNTAGGED_VARIANT) {
                        fprintf(fd, "[error] %s: typedef of untagged variant is not permitted.\n", __func__);
-                       declaration_unref(type_declaration);
+                       bt_declaration_unref(type_declaration);
                        return -EPERM;
                }
-               ret = register_declaration(identifier, type_declaration, scope);
+               ret = bt_register_declaration(identifier, type_declaration, scope);
                if (ret) {
                        type_declaration->declaration_free(type_declaration);
                        return ret;
                }
-               declaration_unref(type_declaration);
+               bt_declaration_unref(type_declaration);
        }
        return 0;
 }
@@ -670,7 +682,7 @@ int ctf_typealias_visit(FILE *fd, int depth, struct declaration_scope *scope,
                struct ctf_node *target, struct ctf_node *alias,
                struct ctf_trace *trace)
 {
-       struct declaration *type_declaration;
+       struct bt_declaration *type_declaration;
        struct ctf_node *node;
        GQuark dummy_id;
        GQuark alias_q;
@@ -702,7 +714,7 @@ int ctf_typealias_visit(FILE *fd, int depth, struct declaration_scope *scope,
         */
        if (type_declaration->id == CTF_TYPE_UNTAGGED_VARIANT) {
                fprintf(fd, "[error] %s: typedef of untagged variant is not permitted.\n", __func__);
-               declaration_unref(type_declaration);
+               bt_declaration_unref(type_declaration);
                return -EPERM;
        }
        /*
@@ -722,10 +734,10 @@ int ctf_typealias_visit(FILE *fd, int depth, struct declaration_scope *scope,
                                struct ctf_node, siblings);
        alias_q = create_typealias_identifier(fd, depth,
                        alias->u.typealias_alias.type_specifier_list, node);
-       err = register_declaration(alias_q, type_declaration, scope);
+       err = bt_register_declaration(alias_q, type_declaration, scope);
        if (err)
                goto error;
-       declaration_unref(type_declaration);
+       bt_declaration_unref(type_declaration);
        return 0;
 
 error:
@@ -744,7 +756,7 @@ int ctf_struct_declaration_list_visit(FILE *fd, int depth,
 
        switch (iter->type) {
        case NODE_TYPEDEF:
-               /* For each declarator, declare type and add type to struct declaration scope */
+               /* For each declarator, declare type and add type to struct bt_declaration scope */
                ret = ctf_typedef_visit(fd, depth,
                        struct_declaration->scope,
                        iter->u._typedef.type_specifier_list,
@@ -753,7 +765,7 @@ int ctf_struct_declaration_list_visit(FILE *fd, int depth,
                        return ret;
                break;
        case NODE_TYPEALIAS:
-               /* Declare type with declarator and add type to struct declaration scope */
+               /* Declare type with declarator and add type to struct bt_declaration scope */
                ret = ctf_typealias_visit(fd, depth,
                        struct_declaration->scope,
                        iter->u.typealias.target,
@@ -773,7 +785,7 @@ int ctf_struct_declaration_list_visit(FILE *fd, int depth,
                break;
        default:
                fprintf(fd, "[error] %s: unexpected node type %d\n", __func__, (int) iter->type);
-               assert(0);
+               return -EINVAL;
        }
        return 0;
 }
@@ -817,13 +829,13 @@ int ctf_variant_declaration_list_visit(FILE *fd, int depth,
                break;
        default:
                fprintf(fd, "[error] %s: unexpected node type %d\n", __func__, (int) iter->type);
-               assert(0);
+               return -EINVAL;
        }
        return 0;
 }
 
 static
-struct declaration *ctf_declaration_struct_visit(FILE *fd,
+struct bt_declaration *ctf_declaration_struct_visit(FILE *fd,
        int depth, const char *name, struct bt_list_head *declaration_list,
        int has_body, struct bt_list_head *min_align,
        struct declaration_scope *declaration_scope,
@@ -838,11 +850,12 @@ struct declaration *ctf_declaration_struct_visit(FILE *fd,
         * declaration: ref is only taken upon definition.
         */
        if (!has_body) {
-               assert(name);
+               if (!name)
+                       return NULL;
                struct_declaration =
-                       lookup_struct_declaration(g_quark_from_string(name),
+                       bt_lookup_struct_declaration(g_quark_from_string(name),
                                                  declaration_scope);
-               declaration_ref(&struct_declaration->p);
+               bt_declaration_ref(&struct_declaration->p);
                return &struct_declaration->p;
        } else {
                uint64_t min_align_value = 0;
@@ -850,9 +863,8 @@ struct declaration *ctf_declaration_struct_visit(FILE *fd,
                /* For unnamed struct, create type */
                /* For named struct (with body), create type and add to declaration scope */
                if (name) {
-                       if (lookup_struct_declaration(g_quark_from_string(name),
+                       if (bt_lookup_struct_declaration(g_quark_from_string(name),
                                                      declaration_scope)) {
-                               
                                fprintf(fd, "[error] %s: struct %s already declared in scope\n", __func__, name);
                                return NULL;
                        }
@@ -863,11 +875,10 @@ struct declaration *ctf_declaration_struct_visit(FILE *fd,
                        ret = get_unary_unsigned(min_align, &min_align_value);
                        if (ret) {
                                fprintf(fd, "[error] %s: unexpected unary expression for structure \"align\" attribute\n", __func__);
-                               ret = -EINVAL;
                                goto error;
                        }
                }
-               struct_declaration = struct_declaration_new(declaration_scope,
+               struct_declaration = bt_struct_declaration_new(declaration_scope,
                                                            min_align_value);
                bt_list_for_each_entry(iter, declaration_list, siblings) {
                        int ret;
@@ -880,10 +891,11 @@ struct declaration *ctf_declaration_struct_visit(FILE *fd,
                if (name) {
                        int ret;
 
-                       ret = register_struct_declaration(g_quark_from_string(name),
+                       ret = bt_register_struct_declaration(g_quark_from_string(name),
                                        struct_declaration,
                                        declaration_scope);
-                       assert(!ret);
+                       if (ret)
+                               return NULL;
                }
                return &struct_declaration->p;
        }
@@ -894,7 +906,7 @@ error:
 }
 
 static
-struct declaration *ctf_declaration_variant_visit(FILE *fd,
+struct bt_declaration *ctf_declaration_variant_visit(FILE *fd,
        int depth, const char *name, const char *choice,
        struct bt_list_head *declaration_list,
        int has_body, struct declaration_scope *declaration_scope,
@@ -910,23 +922,23 @@ struct declaration *ctf_declaration_variant_visit(FILE *fd,
         * declaration: ref is only taken upon definition.
         */
        if (!has_body) {
-               assert(name);
+               if (!name)
+                       return NULL;
                untagged_variant_declaration =
-                       lookup_variant_declaration(g_quark_from_string(name),
+                       bt_lookup_variant_declaration(g_quark_from_string(name),
                                                   declaration_scope);
-               declaration_ref(&untagged_variant_declaration->p);
+               bt_declaration_ref(&untagged_variant_declaration->p);
        } else {
                /* For unnamed variant, create type */
                /* For named variant (with body), create type and add to declaration scope */
                if (name) {
-                       if (lookup_variant_declaration(g_quark_from_string(name),
+                       if (bt_lookup_variant_declaration(g_quark_from_string(name),
                                                       declaration_scope)) {
-                               
                                fprintf(fd, "[error] %s: variant %s already declared in scope\n", __func__, name);
                                return NULL;
                        }
                }
-               untagged_variant_declaration = untagged_variant_declaration_new(declaration_scope);
+               untagged_variant_declaration = bt_untagged_bt_variant_declaration_new(declaration_scope);
                bt_list_for_each_entry(iter, declaration_list, siblings) {
                        int ret;
 
@@ -938,10 +950,11 @@ struct declaration *ctf_declaration_variant_visit(FILE *fd,
                if (name) {
                        int ret;
 
-                       ret = register_variant_declaration(g_quark_from_string(name),
+                       ret = bt_register_variant_declaration(g_quark_from_string(name),
                                        untagged_variant_declaration,
                                        declaration_scope);
-                       assert(!ret);
+                       if (ret)
+                               return NULL;
                }
        }
        /*
@@ -951,10 +964,10 @@ struct declaration *ctf_declaration_variant_visit(FILE *fd,
        if (!choice) {
                return &untagged_variant_declaration->p;
        } else {
-               variant_declaration = variant_declaration_new(untagged_variant_declaration, choice);
+               variant_declaration = bt_variant_declaration_new(untagged_variant_declaration, choice);
                if (!variant_declaration)
                        goto error;
-               declaration_unref(&untagged_variant_declaration->p);
+               bt_declaration_unref(&untagged_variant_declaration->p);
                return &variant_declaration->p;
        }
 error:
@@ -979,7 +992,8 @@ int ctf_enumerator_list_visit(FILE *fd, int depth,
                bt_list_for_each_entry(iter, &enumerator->u.enumerator.values, siblings) {
                        int64_t *target;
 
-                       assert(iter->type == NODE_UNARY_EXPRESSION);
+                       if (iter->type != NODE_UNARY_EXPRESSION)
+                               return -EINVAL;
                        if (nr_vals == 0)
                                target = &start;
                        else
@@ -1007,7 +1021,7 @@ int ctf_enumerator_list_visit(FILE *fd, int depth,
                if (nr_vals <= 1)
                        end = start;
                last->u.s = end + 1;
-               enum_signed_insert(enum_declaration, start, end, q);
+               bt_enum_signed_insert(enum_declaration, start, end, q);
        } else {
                uint64_t start, end;
                int nr_vals = 0;
@@ -1015,7 +1029,8 @@ int ctf_enumerator_list_visit(FILE *fd, int depth,
                bt_list_for_each_entry(iter, &enumerator->u.enumerator.values, siblings) {
                        uint64_t *target;
 
-                       assert(iter->type == NODE_UNARY_EXPRESSION);
+                       if (iter->type != NODE_UNARY_EXPRESSION)
+                               return -EINVAL;
                        if (nr_vals == 0)
                                target = &start;
                        else
@@ -1047,13 +1062,13 @@ int ctf_enumerator_list_visit(FILE *fd, int depth,
                if (nr_vals <= 1)
                        end = start;
                last->u.u = end + 1;
-               enum_unsigned_insert(enum_declaration, start, end, q);
+               bt_enum_unsigned_insert(enum_declaration, start, end, q);
        }
        return 0;
 }
 
 static
-struct declaration *ctf_declaration_enum_visit(FILE *fd, int depth,
+struct bt_declaration *ctf_declaration_enum_visit(FILE *fd, int depth,
                        const char *name,
                        struct ctf_node *container_type,
                        struct bt_list_head *enumerator_list,
@@ -1061,7 +1076,7 @@ struct declaration *ctf_declaration_enum_visit(FILE *fd, int depth,
                        struct declaration_scope *declaration_scope,
                        struct ctf_trace *trace)
 {
-       struct declaration *declaration;
+       struct bt_declaration *declaration;
        struct declaration_enum *enum_declaration;
        struct declaration_integer *integer_declaration;
        struct last_enum_value last_value;
@@ -1074,25 +1089,25 @@ struct declaration *ctf_declaration_enum_visit(FILE *fd, int depth,
         * declaration: ref is only taken upon definition.
         */
        if (!has_body) {
-               assert(name);
+               if (!name)
+                       return NULL;
                enum_declaration =
-                       lookup_enum_declaration(g_quark_from_string(name),
+                       bt_lookup_enum_declaration(g_quark_from_string(name),
                                                declaration_scope);
-               declaration_ref(&enum_declaration->p);
+               bt_declaration_ref(&enum_declaration->p);
                return &enum_declaration->p;
        } else {
                /* For unnamed enum, create type */
                /* For named enum (with body), create type and add to declaration scope */
                if (name) {
-                       if (lookup_enum_declaration(g_quark_from_string(name),
+                       if (bt_lookup_enum_declaration(g_quark_from_string(name),
                                                    declaration_scope)) {
-                               
                                fprintf(fd, "[error] %s: enum %s already declared in scope\n", __func__, name);
                                return NULL;
                        }
                }
                if (!container_type) {
-                       declaration = lookup_declaration(g_quark_from_static_string("int"),
+                       declaration = bt_lookup_declaration(g_quark_from_static_string("int"),
                                                         declaration_scope);
                        if (!declaration) {
                                fprintf(fd, "[error] %s: \"int\" type declaration missing for enumeration\n", __func__);
@@ -1114,8 +1129,8 @@ struct declaration *ctf_declaration_enum_visit(FILE *fd, int depth,
                        return NULL;
                }
                integer_declaration = container_of(declaration, struct declaration_integer, p);
-               enum_declaration = enum_declaration_new(integer_declaration);
-               declaration_unref(&integer_declaration->p);     /* leave ref to enum */
+               enum_declaration = bt_enum_declaration_new(integer_declaration);
+               bt_declaration_unref(&integer_declaration->p);  /* leave ref to enum */
                if (enum_declaration->integer_declaration->signedness) {
                        last_value.u.s = 0;
                } else {
@@ -1132,11 +1147,12 @@ struct declaration *ctf_declaration_enum_visit(FILE *fd, int depth,
                if (name) {
                        int ret;
 
-                       ret = register_enum_declaration(g_quark_from_string(name),
+                       ret = bt_register_enum_declaration(g_quark_from_string(name),
                                        enum_declaration,
                                        declaration_scope);
-                       assert(!ret);
-                       declaration_unref(&enum_declaration->p);
+                       if (ret)
+                               return NULL;
+                       bt_declaration_unref(&enum_declaration->p);
                }
                return &enum_declaration->p;
        }
@@ -1146,25 +1162,29 @@ error:
 }
 
 static
-struct declaration *ctf_declaration_type_specifier_visit(FILE *fd, int depth,
+struct bt_declaration *ctf_declaration_type_specifier_visit(FILE *fd, int depth,
                struct ctf_node *type_specifier_list,
                struct declaration_scope *declaration_scope)
 {
        GString *str;
-       struct declaration *declaration;
+       struct bt_declaration *declaration;
        char *str_c;
        int ret;
        GQuark id_q;
 
        str = g_string_new("");
        ret = visit_type_specifier_list(fd, type_specifier_list, str);
-       if (ret)
+       if (ret) {
+               (void) g_string_free(str, TRUE);
                return NULL;
+       }
        str_c = g_string_free(str, FALSE);
        id_q = g_quark_from_string(str_c);
        g_free(str_c);
-       declaration = lookup_declaration(id_q, declaration_scope);
-       declaration_ref(declaration);
+       declaration = bt_lookup_declaration(id_q, declaration_scope);
+       if (!declaration)
+               return NULL;
+       bt_declaration_ref(declaration);
        return declaration;
 }
 
@@ -1209,7 +1229,7 @@ int get_boolean(FILE *fd, int depth, struct ctf_node *unary_expression)
                fprintf(fd, "[error] %s: unexpected unary expression type\n",
                        __func__);
                return -EINVAL;
-       } 
+       }
 
 }
 
@@ -1228,7 +1248,7 @@ int get_trace_byte_order(FILE *fd, int depth, struct ctf_node *unary_expression)
        else if (!strcmp(unary_expression->u.unary_expression.u.string, "le"))
                byte_order = LITTLE_ENDIAN;
        else {
-               fprintf(fd, "[error] %s: unexpected string \"%s\". Should be \"native\", \"network\", \"be\" or \"le\".\n",
+               fprintf(fd, "[error] %s: unexpected string \"%s\". Should be \"be\" or \"le\".\n",
                        __func__, unary_expression->u.unary_expression.u.string);
                return -EINVAL;
        }
@@ -1263,7 +1283,7 @@ int get_byte_order(FILE *fd, int depth, struct ctf_node *unary_expression,
 }
 
 static
-struct declaration *ctf_declaration_integer_visit(FILE *fd, int depth,
+struct bt_declaration *ctf_declaration_integer_visit(FILE *fd, int depth,
                struct bt_list_head *expressions,
                struct ctf_trace *trace)
 {
@@ -1282,7 +1302,8 @@ struct declaration *ctf_declaration_integer_visit(FILE *fd, int depth,
 
                left = _bt_list_first_entry(&expression->u.ctf_expression.left, struct ctf_node, siblings);
                right = _bt_list_first_entry(&expression->u.ctf_expression.right, struct ctf_node, siblings);
-               assert(left->u.unary_expression.type == UNARY_STRING);
+               if (left->u.unary_expression.type != UNARY_STRING)
+                       return NULL;
                if (!strcmp(left->u.unary_expression.u.string, "signed")) {
                        signedness = get_boolean(fd, depth, right);
                        if (signedness < 0)
@@ -1442,21 +1463,21 @@ struct declaration *ctf_declaration_integer_visit(FILE *fd, int depth,
                        alignment = CHAR_BIT;
                }
        }
-       integer_declaration = integer_declaration_new(size,
+       integer_declaration = bt_integer_declaration_new(size,
                                byte_order, signedness, alignment,
                                base, encoding, clock);
        return &integer_declaration->p;
 }
 
 static
-struct declaration *ctf_declaration_floating_point_visit(FILE *fd, int depth,
+struct bt_declaration *ctf_declaration_floating_point_visit(FILE *fd, int depth,
                struct bt_list_head *expressions,
                struct ctf_trace *trace)
 {
        struct ctf_node *expression;
-       uint64_t alignment = 1, exp_dig = 0, mant_dig = 0,
-               byte_order = trace->byte_order;
-       int has_alignment = 0, has_exp_dig = 0, has_mant_dig = 0;
+       uint64_t alignment = 1, exp_dig = 0, mant_dig = 0;
+       int byte_order = trace->byte_order, has_alignment = 0,
+               has_exp_dig = 0, has_mant_dig = 0;
        struct declaration_float *float_declaration;
 
        bt_list_for_each_entry(expression, expressions, siblings) {
@@ -1464,7 +1485,8 @@ struct declaration *ctf_declaration_floating_point_visit(FILE *fd, int depth,
 
                left = _bt_list_first_entry(&expression->u.ctf_expression.left, struct ctf_node, siblings);
                right = _bt_list_first_entry(&expression->u.ctf_expression.right, struct ctf_node, siblings);
-               assert(left->u.unary_expression.type == UNARY_STRING);
+               if (left->u.unary_expression.type != UNARY_STRING)
+                       return NULL;
                if (!strcmp(left->u.unary_expression.u.string, "byte_order")) {
                        byte_order = get_byte_order(fd, depth, right, trace);
                        if (byte_order < 0)
@@ -1522,13 +1544,13 @@ struct declaration *ctf_declaration_floating_point_visit(FILE *fd, int depth,
                        alignment = CHAR_BIT;
                }
        }
-       float_declaration = float_declaration_new(mant_dig, exp_dig,
+       float_declaration = bt_float_declaration_new(mant_dig, exp_dig,
                                byte_order, alignment);
        return &float_declaration->p;
 }
 
 static
-struct declaration *ctf_declaration_string_visit(FILE *fd, int depth,
+struct bt_declaration *ctf_declaration_string_visit(FILE *fd, int depth,
                struct bt_list_head *expressions,
                struct ctf_trace *trace)
 {
@@ -1542,7 +1564,8 @@ struct declaration *ctf_declaration_string_visit(FILE *fd, int depth,
 
                left = _bt_list_first_entry(&expression->u.ctf_expression.left, struct ctf_node, siblings);
                right = _bt_list_first_entry(&expression->u.ctf_expression.right, struct ctf_node, siblings);
-               assert(left->u.unary_expression.type == UNARY_STRING);
+               if (left->u.unary_expression.type != UNARY_STRING)
+                       return NULL;
                if (!strcmp(left->u.unary_expression.u.string, "encoding")) {
                        if (right->u.unary_expression.type != UNARY_STRING) {
                                fprintf(fd, "[error] %s: encoding: expecting string\n",
@@ -1558,13 +1581,13 @@ struct declaration *ctf_declaration_string_visit(FILE *fd, int depth,
        }
        if (encoding_c && !strcmp(encoding_c, "ASCII"))
                encoding = CTF_STRING_ASCII;
-       string_declaration = string_declaration_new(encoding);
+       string_declaration = bt_string_declaration_new(encoding);
        return &string_declaration->p;
 }
 
 
 static
-struct declaration *ctf_type_specifier_list_visit(FILE *fd,
+struct bt_declaration *ctf_type_specifier_list_visit(FILE *fd,
                int depth, struct ctf_node *type_specifier_list,
                struct declaration_scope *declaration_scope,
                struct ctf_trace *trace)
@@ -1572,11 +1595,13 @@ struct declaration *ctf_type_specifier_list_visit(FILE *fd,
        struct ctf_node *first;
        struct ctf_node *node;
 
-       assert(type_specifier_list->type == NODE_TYPE_SPECIFIER_LIST);
+       if (type_specifier_list->type != NODE_TYPE_SPECIFIER_LIST)
+               return NULL;
 
        first = _bt_list_first_entry(&type_specifier_list->u.type_specifier_list.head, struct ctf_node, siblings);
 
-       assert(first->type == NODE_TYPE_SPECIFIER);
+       if (first->type != NODE_TYPE_SPECIFIER)
+               return NULL;
 
        node = first->u.type_specifier.node;
 
@@ -1665,6 +1690,8 @@ int ctf_event_declaration_visit(FILE *fd, int depth, struct ctf_node *node, stru
                char *left;
 
                left = concatenate_unary_strings(&node->u.ctf_expression.left);
+               if (!left)
+                       return -EINVAL;
                if (!strcmp(left, "name")) {
                        char *right;
 
@@ -1715,7 +1742,7 @@ int ctf_event_declaration_visit(FILE *fd, int depth, struct ctf_node *node, stru
                        }
                        CTF_EVENT_SET_FIELD(event, stream_id);
                } else if (!strcmp(left, "context")) {
-                       struct declaration *declaration;
+                       struct bt_declaration *declaration;
 
                        if (event->context_decl) {
                                fprintf(fd, "[error] %s: context already declared in event declaration\n", __func__);
@@ -1736,7 +1763,7 @@ int ctf_event_declaration_visit(FILE *fd, int depth, struct ctf_node *node, stru
                        }
                        event->context_decl = container_of(declaration, struct declaration_struct, p);
                } else if (!strcmp(left, "fields")) {
-                       struct declaration *declaration;
+                       struct bt_declaration *declaration;
 
                        if (event->fields_decl) {
                                fprintf(fd, "[error] %s: fields already declared in event declaration\n", __func__);
@@ -1816,7 +1843,7 @@ int ctf_event_visit(FILE *fd, int depth, struct ctf_node *node,
 
        event_decl = g_new0(struct bt_ctf_event_decl, 1);
        event = &event_decl->parent;
-       event->declaration_scope = new_declaration_scope(parent_declaration_scope);
+       event->declaration_scope = bt_new_declaration_scope(parent_declaration_scope);
        event->loglevel = -1;
        bt_list_for_each_entry(iter, &node->u.event.declaration_list, siblings) {
                ret = ctf_event_declaration_visit(fd, depth + 1, iter, event, trace);
@@ -1864,10 +1891,10 @@ int ctf_event_visit(FILE *fd, int depth, struct ctf_node *node,
 
 error:
        if (event->fields_decl)
-               declaration_unref(&event->fields_decl->p);
+               bt_declaration_unref(&event->fields_decl->p);
        if (event->context_decl)
-               declaration_unref(&event->context_decl->p);
-       free_declaration_scope(event->declaration_scope);
+               bt_declaration_unref(&event->context_decl->p);
+       bt_free_declaration_scope(event->declaration_scope);
        g_free(event_decl);
        return ret;
 }
@@ -1901,6 +1928,8 @@ int ctf_stream_declaration_visit(FILE *fd, int depth, struct ctf_node *node, str
                char *left;
 
                left = concatenate_unary_strings(&node->u.ctf_expression.left);
+               if (!left)
+                       return -EINVAL;
                if (!strcmp(left, "id")) {
                        if (CTF_STREAM_FIELD_IS_SET(stream, stream_id)) {
                                fprintf(fd, "[error] %s: id already declared in stream declaration\n", __func__);
@@ -1915,7 +1944,7 @@ int ctf_stream_declaration_visit(FILE *fd, int depth, struct ctf_node *node, str
                        }
                        CTF_STREAM_SET_FIELD(stream, stream_id);
                } else if (!strcmp(left, "event.header")) {
-                       struct declaration *declaration;
+                       struct bt_declaration *declaration;
 
                        if (stream->event_header_decl) {
                                fprintf(fd, "[error] %s: event.header already declared in stream declaration\n", __func__);
@@ -1936,7 +1965,7 @@ int ctf_stream_declaration_visit(FILE *fd, int depth, struct ctf_node *node, str
                        }
                        stream->event_header_decl = container_of(declaration, struct declaration_struct, p);
                } else if (!strcmp(left, "event.context")) {
-                       struct declaration *declaration;
+                       struct bt_declaration *declaration;
 
                        if (stream->event_context_decl) {
                                fprintf(fd, "[error] %s: event.context already declared in stream declaration\n", __func__);
@@ -1957,7 +1986,7 @@ int ctf_stream_declaration_visit(FILE *fd, int depth, struct ctf_node *node, str
                        }
                        stream->event_context_decl = container_of(declaration, struct declaration_struct, p);
                } else if (!strcmp(left, "packet.context")) {
-                       struct declaration *declaration;
+                       struct bt_declaration *declaration;
 
                        if (stream->packet_context_decl) {
                                fprintf(fd, "[error] %s: packet.context already declared in stream declaration\n", __func__);
@@ -2003,7 +2032,7 @@ int ctf_stream_visit(FILE *fd, int depth, struct ctf_node *node,
        struct ctf_stream_declaration *stream;
 
        stream = g_new0(struct ctf_stream_declaration, 1);
-       stream->declaration_scope = new_declaration_scope(parent_declaration_scope);
+       stream->declaration_scope = bt_new_declaration_scope(parent_declaration_scope);
        stream->events_by_id = g_ptr_array_new();
        stream->event_quark_to_id = g_hash_table_new(g_direct_hash, g_direct_equal);
        stream->streams = g_ptr_array_new();
@@ -2017,7 +2046,7 @@ int ctf_stream_visit(FILE *fd, int depth, struct ctf_node *node,
        if (CTF_STREAM_FIELD_IS_SET(stream, stream_id)) {
                /* check that packet header has stream_id field. */
                if (!trace->packet_header_decl
-                   || struct_declaration_lookup_field_index(trace->packet_header_decl, g_quark_from_static_string("stream_id")) < 0) {
+                   || bt_struct_declaration_lookup_field_index(trace->packet_header_decl, g_quark_from_static_string("stream_id")) < 0) {
                        ret = -EPERM;
                        fprintf(fd, "[error] %s: missing stream_id field in packet header declaration, but stream_id attribute is declared for stream.\n", __func__);
                        goto error;
@@ -2040,15 +2069,15 @@ int ctf_stream_visit(FILE *fd, int depth, struct ctf_node *node,
 
 error:
        if (stream->event_header_decl)
-               declaration_unref(&stream->event_header_decl->p);
+               bt_declaration_unref(&stream->event_header_decl->p);
        if (stream->event_context_decl)
-               declaration_unref(&stream->event_context_decl->p);
+               bt_declaration_unref(&stream->event_context_decl->p);
        if (stream->packet_context_decl)
-               declaration_unref(&stream->packet_context_decl->p);
+               bt_declaration_unref(&stream->packet_context_decl->p);
        g_ptr_array_free(stream->streams, TRUE);
        g_ptr_array_free(stream->events_by_id, TRUE);
        g_hash_table_destroy(stream->event_quark_to_id);
-       free_declaration_scope(stream->declaration_scope);
+       bt_free_declaration_scope(stream->declaration_scope);
        g_free(stream);
        return ret;
 }
@@ -2081,6 +2110,8 @@ int ctf_trace_declaration_visit(FILE *fd, int depth, struct ctf_node *node, stru
                char *left;
 
                left = concatenate_unary_strings(&node->u.ctf_expression.left);
+               if (!left)
+                       return -EINVAL;
                if (!strcmp(left, "major")) {
                        if (CTF_TRACE_FIELD_IS_SET(trace, major)) {
                                fprintf(fd, "[error] %s: major already declared in trace declaration\n", __func__);
@@ -2131,8 +2162,10 @@ int ctf_trace_declaration_visit(FILE *fd, int depth, struct ctf_node *node, stru
 
                        right = _bt_list_first_entry(&node->u.ctf_expression.right, struct ctf_node, siblings);
                        byte_order = get_trace_byte_order(fd, depth, right);
-                       if (byte_order < 0)
-                               return -EINVAL;
+                       if (byte_order < 0) {
+                               ret = -EINVAL;
+                               goto error;
+                       }
 
                        if (CTF_TRACE_FIELD_IS_SET(trace, byte_order)
                                && byte_order != trace->byte_order) {
@@ -2155,7 +2188,7 @@ int ctf_trace_declaration_visit(FILE *fd, int depth, struct ctf_node *node, stru
                        }
                        CTF_TRACE_SET_FIELD(trace, byte_order);
                } else if (!strcmp(left, "packet.header")) {
-                       struct declaration *declaration;
+                       struct bt_declaration *declaration;
 
                        if (trace->packet_header_decl) {
                                fprintf(fd, "[error] %s: packet.header already declared in trace declaration\n", __func__);
@@ -2199,7 +2232,7 @@ int ctf_trace_visit(FILE *fd, int depth, struct ctf_node *node, struct ctf_trace
 
        if (trace->declaration_scope)
                return -EEXIST;
-       trace->declaration_scope = new_declaration_scope(trace->root_declaration_scope);
+       trace->declaration_scope = bt_new_declaration_scope(trace->root_declaration_scope);
        trace->streams = g_ptr_array_new();
        trace->event_declarations = g_ptr_array_new();
        bt_list_for_each_entry(iter, &node->u.trace.declaration_list, siblings) {
@@ -2226,7 +2259,7 @@ int ctf_trace_visit(FILE *fd, int depth, struct ctf_node *node, struct ctf_trace
        if (!CTF_TRACE_FIELD_IS_SET(trace, byte_order)) {
                /* check that the packet header contains a "magic" field */
                if (!trace->packet_header_decl
-                   || struct_declaration_lookup_field_index(trace->packet_header_decl, g_quark_from_static_string("magic")) < 0) {
+                   || bt_struct_declaration_lookup_field_index(trace->packet_header_decl, g_quark_from_static_string("magic")) < 0) {
                        ret = -EPERM;
                        fprintf(fd, "[error] %s: missing both byte_order and packet header magic number in trace declaration\n", __func__);
                        goto error;
@@ -2236,12 +2269,12 @@ int ctf_trace_visit(FILE *fd, int depth, struct ctf_node *node, struct ctf_trace
 
 error:
        if (trace->packet_header_decl) {
-               declaration_unref(&trace->packet_header_decl->p);
+               bt_declaration_unref(&trace->packet_header_decl->p);
                trace->packet_header_decl = NULL;
        }
        g_ptr_array_free(trace->streams, TRUE);
        g_ptr_array_free(trace->event_declarations, TRUE);
-       free_declaration_scope(trace->declaration_scope);
+       bt_free_declaration_scope(trace->declaration_scope);
        trace->declaration_scope = NULL;
        return ret;
 }
@@ -2258,6 +2291,8 @@ int ctf_clock_declaration_visit(FILE *fd, int depth, struct ctf_node *node,
                char *left;
 
                left = concatenate_unary_strings(&node->u.ctf_expression.left);
+               if (!left)
+                       return -EINVAL;
                if (!strcmp(left, "name")) {
                        char *right;
 
@@ -2398,7 +2433,7 @@ int ctf_clock_visit(FILE *fd, int depth, struct ctf_node *node, struct ctf_trace
        if (opt_clock_force_correlate) {
                /*
                 * User requested to forcibly correlate the clock
-                * sources, even if we have no correlatation
+                * sources, even if we have no correlation
                 * information.
                 */
                if (!clock->absolute) {
@@ -2411,13 +2446,13 @@ int ctf_clock_visit(FILE *fd, int depth, struct ctf_node *node, struct ctf_trace
                fprintf(fd, "[error] %s: missing name field in clock declaration\n", __func__);
                goto error;
        }
-       if (g_hash_table_size(trace->clocks) > 0) {
+       if (g_hash_table_size(trace->parent.clocks) > 0) {
                fprintf(fd, "[error] Only CTF traces with a single clock description are supported by this babeltrace version.\n");
                ret = -EINVAL;
                goto error;
        }
-       trace->single_clock = clock;
-       g_hash_table_insert(trace->clocks, (gpointer) (unsigned long) clock->name, clock);
+       trace->parent.single_clock = clock;
+       g_hash_table_insert(trace->parent.clocks, (gpointer) (unsigned long) clock->name, clock);
        return 0;
 
 error:
@@ -2451,8 +2486,8 @@ void ctf_clock_default(FILE *fd, int depth, struct ctf_trace *trace)
                clock->absolute = 0;    /* Not an absolute reference across traces */
        }
 
-       trace->single_clock = clock;
-       g_hash_table_insert(trace->clocks, (gpointer) (unsigned long) clock->name, clock);
+       trace->parent.single_clock = clock;
+       g_hash_table_insert(trace->parent.clocks, (gpointer) (unsigned long) clock->name, clock);
 }
 
 static
@@ -2476,6 +2511,8 @@ int ctf_callsite_declaration_visit(FILE *fd, int depth, struct ctf_node *node,
                char *left;
 
                left = concatenate_unary_strings(&node->u.ctf_expression.left);
+               if (!left)
+                       return -EINVAL;
                if (!strcmp(left, "name")) {
                        char *right;
 
@@ -2647,6 +2684,8 @@ int ctf_env_declaration_visit(FILE *fd, int depth, struct ctf_node *node,
                char *left;
 
                left = concatenate_unary_strings(&node->u.ctf_expression.left);
+               if (!left)
+                       return -EINVAL;
                if (!strcmp(left, "vpid")) {
                        uint64_t v;
 
@@ -2762,6 +2801,11 @@ int ctf_env_declaration_visit(FILE *fd, int depth, struct ctf_node *node,
                                char *right;
 
                                right = concatenate_unary_strings(&node->u.ctf_expression.right);
+                               if (!right) {
+                                       fprintf(fd, "[warning] %s: unexpected unary expression for env\n", __func__);
+                                       ret = -EINVAL;
+                                       goto error;
+                               }
                                printf_verbose("env.%s = \"%s\"\n", left, right);
                                g_free(right);
                        } else if (is_unary_unsigned(&node->u.ctf_expression.right)) {
@@ -2769,14 +2813,16 @@ int ctf_env_declaration_visit(FILE *fd, int depth, struct ctf_node *node,
                                int ret;
 
                                ret = get_unary_unsigned(&node->u.ctf_expression.right, &v);
-                               assert(ret == 0);
+                               if (ret)
+                                       goto error;
                                printf_verbose("env.%s = %" PRIu64 "\n", left, v);
                        } else if (is_unary_signed(&node->u.ctf_expression.right)) {
                                int64_t v;
                                int ret;
 
                                ret = get_unary_signed(&node->u.ctf_expression.right, &v);
-                               assert(ret == 0);
+                               if (ret)
+                                       goto error;
                                printf_verbose("env.%s = %" PRId64 "\n", left, v);
                        } else {
                                printf_verbose("%s: attribute \"%s\" has unknown type.\n", __func__, left);
@@ -2841,7 +2887,7 @@ int ctf_root_declaration_visit(FILE *fd, int depth, struct ctf_node *node, struc
                break;
        case NODE_TYPE_SPECIFIER_LIST:
        {
-               struct declaration *declaration;
+               struct bt_declaration *declaration;
 
                /*
                 * Just add the type specifier to the root scope
@@ -2851,7 +2897,7 @@ int ctf_root_declaration_visit(FILE *fd, int depth, struct ctf_node *node, struc
                        node, trace->root_declaration_scope, trace);
                if (!declaration)
                        return -ENOMEM;
-               declaration_unref(declaration);
+               bt_declaration_unref(declaration);
                break;
        }
        default:
@@ -2868,15 +2914,15 @@ int ctf_visitor_construct_metadata(FILE *fd, int depth, struct ctf_node *node,
        struct ctf_node *iter;
        int env_clock_done = 0;
 
-       printf_verbose("CTF visitor: metadata construction... ");
+       printf_verbose("CTF visitor: metadata construction...\n");
        trace->byte_order = byte_order;
-       trace->clocks = g_hash_table_new_full(g_direct_hash, g_direct_equal,
-                               NULL, clock_free);
+       trace->parent.clocks = g_hash_table_new_full(g_direct_hash,
+                               g_direct_equal, NULL, clock_free);
        trace->callsites = g_hash_table_new_full(g_direct_hash, g_direct_equal,
                                NULL, callsite_free);
 
 retry:
-       trace->root_declaration_scope = new_declaration_scope(NULL);
+       trace->root_declaration_scope = bt_new_declaration_scope(NULL);
 
        switch (node->type) {
        case NODE_ROOT:
@@ -2910,7 +2956,7 @@ retry:
                bt_list_for_each_entry(iter, &node->u.root.trace, siblings) {
                        ret = ctf_trace_visit(fd, depth + 1, iter, trace);
                        if (ret == -EINTR) {
-                               free_declaration_scope(trace->root_declaration_scope);
+                               bt_free_declaration_scope(trace->root_declaration_scope);
                                /*
                                 * Need to restart creation of type
                                 * definitions, aliases and
@@ -2971,9 +3017,9 @@ retry:
        return ret;
 
 error:
-       free_declaration_scope(trace->root_declaration_scope);
+       bt_free_declaration_scope(trace->root_declaration_scope);
        g_hash_table_destroy(trace->callsites);
-       g_hash_table_destroy(trace->clocks);
+       g_hash_table_destroy(trace->parent.clocks);
        return ret;
 }
 
@@ -3004,32 +3050,32 @@ int ctf_destroy_metadata(struct ctf_trace *trace)
                                        if (!event)
                                                continue;
                                        if (&event->event_fields->p)
-                                               definition_unref(&event->event_fields->p);
+                                               bt_definition_unref(&event->event_fields->p);
                                        if (&event->event_context->p)
-                                               definition_unref(&event->event_context->p);
+                                               bt_definition_unref(&event->event_context->p);
                                        g_free(event);
                                }
                                if (&stream_def->trace_packet_header->p)
-                                       definition_unref(&stream_def->trace_packet_header->p);
+                                       bt_definition_unref(&stream_def->trace_packet_header->p);
                                if (&stream_def->stream_event_header->p)
-                                       definition_unref(&stream_def->stream_event_header->p);
+                                       bt_definition_unref(&stream_def->stream_event_header->p);
                                if (&stream_def->stream_packet_context->p)
-                                       definition_unref(&stream_def->stream_packet_context->p);
+                                       bt_definition_unref(&stream_def->stream_packet_context->p);
                                if (&stream_def->stream_event_context->p)
-                                       definition_unref(&stream_def->stream_event_context->p);
+                                       bt_definition_unref(&stream_def->stream_event_context->p);
                                g_ptr_array_free(stream_def->events_by_id, TRUE);
                                g_free(stream_def);
                        }
                        if (stream->event_header_decl)
-                               declaration_unref(&stream->event_header_decl->p);
+                               bt_declaration_unref(&stream->event_header_decl->p);
                        if (stream->event_context_decl)
-                               declaration_unref(&stream->event_context_decl->p);
+                               bt_declaration_unref(&stream->event_context_decl->p);
                        if (stream->packet_context_decl)
-                               declaration_unref(&stream->packet_context_decl->p);
+                               bt_declaration_unref(&stream->packet_context_decl->p);
                        g_ptr_array_free(stream->streams, TRUE);
                        g_ptr_array_free(stream->events_by_id, TRUE);
                        g_hash_table_destroy(stream->event_quark_to_id);
-                       free_declaration_scope(stream->declaration_scope);
+                       bt_free_declaration_scope(stream->declaration_scope);
                        g_free(stream);
                }
                g_ptr_array_free(trace->streams, TRUE);
@@ -3056,23 +3102,23 @@ int ctf_destroy_metadata(struct ctf_trace *trace)
 
                        event = &event_decl->parent;
                        if (event->fields_decl)
-                               declaration_unref(&event->fields_decl->p);
+                               bt_declaration_unref(&event->fields_decl->p);
                        if (event->context_decl)
-                               declaration_unref(&event->context_decl->p);
-                       free_declaration_scope(event->declaration_scope);
+                               bt_declaration_unref(&event->context_decl->p);
+                       bt_free_declaration_scope(event->declaration_scope);
 
                        g_free(event);
                }
                g_ptr_array_free(trace->event_declarations, TRUE);
        }
        if (trace->packet_header_decl)
-               declaration_unref(&trace->packet_header_decl->p);
+               bt_declaration_unref(&trace->packet_header_decl->p);
 
-       free_declaration_scope(trace->root_declaration_scope);
-       free_declaration_scope(trace->declaration_scope);
+       bt_free_declaration_scope(trace->root_declaration_scope);
+       bt_free_declaration_scope(trace->declaration_scope);
 
        g_hash_table_destroy(trace->callsites);
-       g_hash_table_destroy(trace->clocks);
+       g_hash_table_destroy(trace->parent.clocks);
 
        metadata_stream = container_of(trace->metadata, struct ctf_file_stream, parent);
        g_free(metadata_stream);
index 953727e84c3eccc809328f7f7ca6f82e8c7e0cc7..104afb717ddad5e78fb2dcbe87c9dabc0c0fb3eb 100644 (file)
@@ -69,13 +69,6 @@ int ctf_visitor_unary_expression(FILE *fd, int depth, struct ctf_node *node)
                if (ret)
                        return ret;
                break;
-       case UNARY_NESTED:
-               node->u.unary_expression.u.nested_exp->parent = node;
-               ret = ctf_visitor_unary_expression(fd, depth + 1,
-                       node->u.unary_expression.u.nested_exp);
-               if (ret)
-                       return ret;
-               break;
 
        case UNARY_UNKNOWN:
        default:
index 0276f836806fa8a1f97d7c03d8a22044adee0821..3c1d37e74827b7e1b7a7034361f7cd45330297b3 100644 (file)
@@ -104,16 +104,6 @@ int ctf_visitor_print_unary_expression(FILE *fd, int depth, struct ctf_node *nod
                print_tabs(fd, depth);
                fprintf(fd, "</unary_expression_sbrac>\n");
                break;
-       case UNARY_NESTED:
-               print_tabs(fd, depth);
-               fprintf(fd, "<unary_expression_nested>\n");
-               ret = ctf_visitor_print_unary_expression(fd, depth + 1,
-                       node->u.unary_expression.u.nested_exp);
-               if (ret)
-                       return ret;
-               print_tabs(fd, depth);
-               fprintf(fd, "</unary_expression_nested>\n");
-               break;
 
        case UNARY_UNKNOWN:
        default:
diff --git a/formats/ctf/metadata/objstack.c b/formats/ctf/metadata/objstack.c
new file mode 100644 (file)
index 0000000..9e264a4
--- /dev/null
@@ -0,0 +1,133 @@
+/*
+ * objstack.c
+ *
+ * Common Trace Format Object Stack.
+ *
+ * Copyright 2013 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#include <stdlib.h>
+#include <babeltrace/list.h>
+#include <babeltrace/babeltrace-internal.h>
+
+#define OBJSTACK_INIT_LEN              128
+#define OBJSTACK_POISON                        0xcc
+
+struct objstack {
+       struct bt_list_head head;       /* list of struct objstack_node */
+};
+
+struct objstack_node {
+       struct bt_list_head node;
+       size_t len;
+       size_t used_len;
+       char data[];
+};
+
+BT_HIDDEN
+struct objstack *objstack_create(void)
+{
+       struct objstack *objstack;
+       struct objstack_node *node;
+
+       objstack = calloc(1, sizeof(*objstack));
+       if (!objstack)
+               return NULL;
+       node = calloc(sizeof(struct objstack_node) + OBJSTACK_INIT_LEN,
+                       sizeof(char));
+       if (!node) {
+               free(objstack);
+               return NULL;
+       }
+       BT_INIT_LIST_HEAD(&objstack->head);
+       bt_list_add_tail(&node->node, &objstack->head);
+       node->len = OBJSTACK_INIT_LEN;
+       return objstack;
+}
+
+static
+void objstack_node_free(struct objstack_node *node)
+{
+       size_t offset, len;
+       char *p;
+
+       if (!node)
+               return;
+       p = (char *) node;
+       len = sizeof(*node) + node->len;
+       for (offset = 0; offset < len; offset++)
+               p[offset] = OBJSTACK_POISON;
+       free(node);
+}
+
+BT_HIDDEN
+void objstack_destroy(struct objstack *objstack)
+{
+       struct objstack_node *node, *p;
+
+       if (!objstack)
+               return;
+       bt_list_for_each_entry_safe(node, p, &objstack->head, node) {
+               bt_list_del(&node->node);
+               objstack_node_free(node);
+       }
+       free(objstack);
+}
+
+static
+struct objstack_node *objstack_append_node(struct objstack *objstack)
+{
+       struct objstack_node *last_node, *new_node;
+
+       /* Get last node */
+       last_node = bt_list_entry(objstack->head.prev,
+                       struct objstack_node, node);
+
+       /* Allocate new node with double of size of last node */
+       new_node = calloc(sizeof(struct objstack_node) + (last_node->len << 1),
+                       sizeof(char));
+       if (!new_node) {
+               return NULL;
+       }
+       bt_list_add_tail(&new_node->node, &objstack->head);
+       new_node->len = last_node->len << 1;
+       return new_node;
+}
+
+BT_HIDDEN
+void *objstack_alloc(struct objstack *objstack, size_t len)
+{
+       struct objstack_node *last_node;
+       void *p;
+
+       /* Get last node */
+       last_node = bt_list_entry(objstack->head.prev,
+                       struct objstack_node, node);
+       while (last_node->len - last_node->used_len < len) {
+               last_node = objstack_append_node(objstack);
+               if (!last_node) {
+                       return NULL;
+               }
+       }
+       p = &last_node->data[last_node->used_len];
+       last_node->used_len += len;
+       return p;
+}
diff --git a/formats/ctf/metadata/objstack.h b/formats/ctf/metadata/objstack.h
new file mode 100644 (file)
index 0000000..c026eb5
--- /dev/null
@@ -0,0 +1,44 @@
+#ifndef _OBJSTACK_H
+#define _OBJSTACK_H
+
+/*
+ * objstack.h
+ *
+ * Common Trace Format Object Stack.
+ *
+ * Copyright 2013 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+struct objstack;
+
+BT_HIDDEN
+struct objstack *objstack_create(void);
+BT_HIDDEN
+void objstack_destroy(struct objstack *objstack);
+
+/*
+ * Allocate len bytes of zeroed memory.
+ * Return NULL on error.
+ */
+BT_HIDDEN
+void *objstack_alloc(struct objstack *objstack, size_t len);
+
+#endif /* _OBJSTACK_H */
index d5b6ed46b44d25d81e87840cb1675e17bea612c7..ea3ecfd8a656d5db9b4f389ee1302b5b6b5926ca 100644 (file)
 
 #include <babeltrace/ctf/types.h>
 
-int ctf_array_read(struct stream_pos *ppos, struct definition *definition)
+int ctf_array_read(struct bt_stream_pos *ppos, struct bt_definition *definition)
 {
        struct definition_array *array_definition =
                container_of(definition, struct definition_array, p);
        struct declaration_array *array_declaration =
                array_definition->declaration;
-       struct declaration *elem = array_declaration->elem;
+       struct bt_declaration *elem = array_declaration->elem;
        struct ctf_stream_pos *pos =
                container_of(ppos, struct ctf_stream_pos, parent);
 
@@ -61,16 +61,16 @@ int ctf_array_read(struct stream_pos *ppos, struct definition *definition)
                        }
                }
        }
-       return array_rw(ppos, definition);
+       return bt_array_rw(ppos, definition);
 }
 
-int ctf_array_write(struct stream_pos *ppos, struct definition *definition)
+int ctf_array_write(struct bt_stream_pos *ppos, struct bt_definition *definition)
 {
        struct definition_array *array_definition =
                container_of(definition, struct definition_array, p);
        struct declaration_array *array_declaration =
                array_definition->declaration;
-       struct declaration *elem = array_declaration->elem;
+       struct bt_declaration *elem = array_declaration->elem;
        struct ctf_stream_pos *pos =
                container_of(ppos, struct ctf_stream_pos, parent);
 
@@ -96,5 +96,5 @@ int ctf_array_write(struct stream_pos *ppos, struct definition *definition)
                        }
                }
        }
-       return array_rw(ppos, definition);
+       return bt_array_rw(ppos, definition);
 }
index e4e7ac85bb72f094d1ee197e7276cfbe95aa5493..9461af625479f19c9788dd0d0fc37cdf13295ae7 100644 (file)
@@ -31,7 +31,7 @@
 #include <stdint.h>
 #include <glib.h>
 
-int ctf_enum_read(struct stream_pos *ppos, struct definition *definition)
+int ctf_enum_read(struct bt_stream_pos *ppos, struct bt_definition *definition)
 {
        struct definition_enum *enum_definition =
                container_of(definition, struct definition_enum, p);
@@ -48,14 +48,14 @@ int ctf_enum_read(struct stream_pos *ppos, struct definition *definition)
        if (ret)
                return ret;
        if (!integer_declaration->signedness) {
-               qs = enum_uint_to_quark_set(enum_declaration,
+               qs = bt_enum_uint_to_quark_set(enum_declaration,
                        integer_definition->value._unsigned);
                if (!qs) {
                        fprintf(stderr, "[warning] Unknown value %" PRIu64 " in enum.\n",
                                integer_definition->value._unsigned);
                }
        } else {
-               qs = enum_int_to_quark_set(enum_declaration,
+               qs = bt_enum_int_to_quark_set(enum_declaration,
                        integer_definition->value._signed);
                if (!qs) {
                        fprintf(stderr, "[warning] Unknown value %" PRId64 " in enum.\n",
@@ -69,7 +69,7 @@ int ctf_enum_read(struct stream_pos *ppos, struct definition *definition)
        return 0;
 }
 
-int ctf_enum_write(struct stream_pos *pos, struct definition *definition)
+int ctf_enum_write(struct bt_stream_pos *pos, struct bt_definition *definition)
 {
        struct definition_enum *enum_definition =
                container_of(definition, struct definition_enum, p);
index 0cf9caeb6c7795212c53dc7d540c1a9fdd53b36e..2daadf91e40de1325832d39e867ab6ff38e826f0 100644 (file)
@@ -96,9 +96,9 @@ static void float_unlock(void)
        assert(!ret);
 }
 
-int _ctf_float_copy(struct stream_pos *destp,
+static int _ctf_float_copy(struct bt_stream_pos *destp,
                    struct definition_float *dest_definition,
-                   struct stream_pos *srcp,
+                   struct bt_stream_pos *srcp,
                    const struct definition_float *src_definition)
 {
        int ret;
@@ -165,7 +165,7 @@ int _ctf_float_copy(struct stream_pos *destp,
        return 0;
 }
 
-int ctf_float_read(struct stream_pos *ppos, struct definition *definition)
+int ctf_float_read(struct bt_stream_pos *ppos, struct bt_definition *definition)
 {
        struct definition_float *float_definition =
                container_of(definition, struct definition_float, p);
@@ -173,7 +173,7 @@ int ctf_float_read(struct stream_pos *ppos, struct definition *definition)
                float_definition->declaration;
        struct ctf_stream_pos *pos = ctf_pos(ppos);
        union doubleIEEE754 u;
-       struct definition *tmpdef;
+       struct bt_definition *tmpdef;
        struct definition_float *tmpfloat;
        struct ctf_stream_pos destp;
        struct mmap_align mma;
@@ -197,7 +197,7 @@ int ctf_float_read(struct stream_pos *ppos, struct definition *definition)
        }
        tmpfloat = container_of(tmpdef, struct definition_float, p);
        memset(&destp, 0, sizeof(destp));
-       ctf_init_pos(&destp, -1, O_RDWR);
+       ctf_init_pos(&destp, NULL, -1, O_RDWR);
        mmap_align_set_addr(&mma, (char *) u.bits);
        destp.base_mma = &mma;
        destp.packet_size = sizeof(u) * CHAR_BIT;
@@ -216,13 +216,13 @@ int ctf_float_read(struct stream_pos *ppos, struct definition *definition)
        }
 
 end_unref:
-       definition_unref(tmpdef);
+       bt_definition_unref(tmpdef);
 end:
        float_unlock();
        return ret;
 }
 
-int ctf_float_write(struct stream_pos *ppos, struct definition *definition)
+int ctf_float_write(struct bt_stream_pos *ppos, struct bt_definition *definition)
 {
        struct definition_float *float_definition =
                container_of(definition, struct definition_float, p);
@@ -230,7 +230,7 @@ int ctf_float_write(struct stream_pos *ppos, struct definition *definition)
                float_definition->declaration;
        struct ctf_stream_pos *pos = ctf_pos(ppos);
        union doubleIEEE754 u;
-       struct definition *tmpdef;
+       struct bt_definition *tmpdef;
        struct definition_float *tmpfloat;
        struct ctf_stream_pos srcp;
        struct mmap_align mma;
@@ -253,7 +253,7 @@ int ctf_float_write(struct stream_pos *ppos, struct definition *definition)
                goto end;
        }
        tmpfloat = container_of(tmpdef, struct definition_float, p);
-       ctf_init_pos(&srcp, -1, O_RDONLY);
+       ctf_init_pos(&srcp, NULL, -1, O_RDONLY);
        mmap_align_set_addr(&mma, (char *) u.bits);
        srcp.base_mma = &mma;
        srcp.packet_size = sizeof(u) * CHAR_BIT;
@@ -272,28 +272,30 @@ int ctf_float_write(struct stream_pos *ppos, struct definition *definition)
        ret = _ctf_float_copy(ppos, float_definition, &srcp.parent, tmpfloat);
 
 end_unref:
-       definition_unref(tmpdef);
+       bt_definition_unref(tmpdef);
 end:
        float_unlock();
        return ret;
 }
 
+static
 void __attribute__((constructor)) ctf_float_init(void)
 {
        static_float_declaration =
-               float_declaration_new(FLT_MANT_DIG,
+               bt_float_declaration_new(FLT_MANT_DIG,
                                sizeof(float) * CHAR_BIT - FLT_MANT_DIG,
                                BYTE_ORDER,
                                __alignof__(float));
        static_double_declaration =
-               float_declaration_new(DBL_MANT_DIG,
+               bt_float_declaration_new(DBL_MANT_DIG,
                                sizeof(double) * CHAR_BIT - DBL_MANT_DIG,
                                BYTE_ORDER,
                                __alignof__(double));
 }
 
+static
 void __attribute__((destructor)) ctf_float_fini(void)
 {
-       declaration_unref(&static_float_declaration->p);
-       declaration_unref(&static_double_declaration->p);
+       bt_declaration_unref(&static_float_declaration->p);
+       bt_declaration_unref(&static_double_declaration->p);
 }
index 66036ae2511004fafe8bd3056cb848949f11a209..257341adfa41ce6320a68a00e04cf6bc4d43490f 100644 (file)
@@ -39,8 +39,8 @@
  */
 
 static
-int _aligned_integer_read(struct stream_pos *ppos,
-                         struct definition *definition)
+int _aligned_integer_read(struct bt_stream_pos *ppos,
+                         struct bt_definition *definition)
 {
        struct definition_integer *integer_definition =
                container_of(definition, struct definition_integer, p);
@@ -141,8 +141,8 @@ int _aligned_integer_read(struct stream_pos *ppos,
 }
 
 static
-int _aligned_integer_write(struct stream_pos *ppos,
-                           struct definition *definition)
+int _aligned_integer_write(struct bt_stream_pos *ppos,
+                           struct bt_definition *definition)
 {
        struct definition_integer *integer_definition =
                container_of(definition, struct definition_integer, p);
@@ -211,7 +211,7 @@ end:
        return 0;
 }
 
-int ctf_integer_read(struct stream_pos *ppos, struct definition *definition)
+int ctf_integer_read(struct bt_stream_pos *ppos, struct bt_definition *definition)
 {
        struct definition_integer *integer_definition =
                container_of(definition, struct definition_integer, p);
@@ -256,7 +256,7 @@ int ctf_integer_read(struct stream_pos *ppos, struct definition *definition)
        return 0;
 }
 
-int ctf_integer_write(struct stream_pos *ppos, struct definition *definition)
+int ctf_integer_write(struct bt_stream_pos *ppos, struct bt_definition *definition)
 {
        struct definition_integer *integer_definition =
                container_of(definition, struct definition_integer, p);
index 7f12bbceade30ce1727504b3a8d36d9d2b1fc094..898c36725672c8e4b01084e1850e4c27050634d6 100644 (file)
 
 #include <babeltrace/ctf/types.h>
 
-int ctf_sequence_read(struct stream_pos *ppos, struct definition *definition)
+int ctf_sequence_read(struct bt_stream_pos *ppos, struct bt_definition *definition)
 {
        struct definition_sequence *sequence_definition =
                container_of(definition, struct definition_sequence, p);
        struct declaration_sequence *sequence_declaration =
                sequence_definition->declaration;
-       struct declaration *elem = sequence_declaration->elem;
+       struct bt_declaration *elem = sequence_declaration->elem;
        struct ctf_stream_pos *pos = ctf_pos(ppos);
 
        if (elem->id == CTF_TYPE_INTEGER) {
@@ -46,7 +46,7 @@ int ctf_sequence_read(struct stream_pos *ppos, struct definition *definition)
 
                        if (integer_declaration->len == CHAR_BIT
                            && integer_declaration->p.alignment == CHAR_BIT) {
-                               uint64_t len = sequence_len(sequence_definition);
+                               uint64_t len = bt_sequence_len(sequence_definition);
 
                                ctf_align_pos(pos, integer_declaration->p.alignment);
                                if (!ctf_pos_access_ok(pos, len * CHAR_BIT))
@@ -60,16 +60,16 @@ int ctf_sequence_read(struct stream_pos *ppos, struct definition *definition)
                        }
                }
        }
-       return sequence_rw(ppos, definition);
+       return bt_sequence_rw(ppos, definition);
 }
 
-int ctf_sequence_write(struct stream_pos *ppos, struct definition *definition)
+int ctf_sequence_write(struct bt_stream_pos *ppos, struct bt_definition *definition)
 {
        struct definition_sequence *sequence_definition =
                container_of(definition, struct definition_sequence, p);
        struct declaration_sequence *sequence_declaration =
                sequence_definition->declaration;
-       struct declaration *elem = sequence_declaration->elem;
+       struct bt_declaration *elem = sequence_declaration->elem;
        struct ctf_stream_pos *pos = ctf_pos(ppos);
 
        if (elem->id == CTF_TYPE_INTEGER) {
@@ -81,7 +81,7 @@ int ctf_sequence_write(struct stream_pos *ppos, struct definition *definition)
 
                        if (integer_declaration->len == CHAR_BIT
                            && integer_declaration->p.alignment == CHAR_BIT) {
-                               uint64_t len = sequence_len(sequence_definition);
+                               uint64_t len = bt_sequence_len(sequence_definition);
 
                                ctf_align_pos(pos, integer_declaration->p.alignment);
                                if (!ctf_pos_access_ok(pos, len * CHAR_BIT))
@@ -94,5 +94,5 @@ int ctf_sequence_write(struct stream_pos *ppos, struct definition *definition)
                        }
                }
        }
-       return sequence_rw(ppos, definition);
+       return bt_sequence_rw(ppos, definition);
 }
index 357e273a4e8929a130445ed764f6473e61ea0892..a2433bf5922d2013e80f19a1e1897842657de535 100644 (file)
@@ -31,7 +31,7 @@
 #include <limits.h>            /* C99 limits */
 #include <string.h>
 
-int ctf_string_read(struct stream_pos *ppos, struct definition *definition)
+int ctf_string_read(struct bt_stream_pos *ppos, struct bt_definition *definition)
 {
        struct definition_string *string_definition =
                container_of(definition, struct definition_string, p);
@@ -68,8 +68,8 @@ int ctf_string_read(struct stream_pos *ppos, struct definition *definition)
        return 0;
 }
 
-int ctf_string_write(struct stream_pos *ppos,
-                     struct definition *definition)
+int ctf_string_write(struct bt_stream_pos *ppos,
+                     struct bt_definition *definition)
 {
        struct definition_string *string_definition =
                container_of(definition, struct definition_string, p);
index 21ce96f6d9eae370ebf0cd5ffe5d10000caab387..106f682c8ee2d886a9daded1bb32d027e20a7abc 100644 (file)
 
 #include <babeltrace/ctf/types.h>
 
-int ctf_struct_rw(struct stream_pos *ppos, struct definition *definition)
+int ctf_struct_rw(struct bt_stream_pos *ppos, struct bt_definition *definition)
 {
-       struct declaration *declaration = definition->declaration;
+       struct bt_declaration *declaration = definition->declaration;
        struct ctf_stream_pos *pos = ctf_pos(ppos);
 
        ctf_align_pos(pos, declaration->alignment);
-       return struct_rw(ppos, definition);
+       return bt_struct_rw(ppos, definition);
 }
index 297f26ff5feb3f9e739e82fb8c7582f3dec6dfca..b3d6396a6f9f075f21be4fd71e871a55c2c038f6 100644 (file)
 
 #include <babeltrace/ctf/types.h>
 
-int ctf_variant_rw(struct stream_pos *ppos, struct definition *definition)
+int ctf_variant_rw(struct bt_stream_pos *ppos, struct bt_definition *definition)
 {
-       struct declaration *declaration = definition->declaration;
+       struct bt_declaration *declaration = definition->declaration;
        struct ctf_stream_pos *pos = ctf_pos(ppos);
 
        ctf_align_pos(pos, declaration->alignment);
-       return variant_rw(ppos, definition);
+       return bt_variant_rw(ppos, definition);
 }
index 824be61b34a05b678df163b36597fdde84382806..7bf253912b612d56a92bd8e01c92d1e05c7d2da3 100644 (file)
@@ -19,6 +19,7 @@ noinst_HEADERS = \
        babeltrace/clock-internal.h \
        babeltrace/compiler.h \
        babeltrace/context-internal.h \
+       babeltrace/format-internal.h \
        babeltrace/iterator-internal.h \
        babeltrace/trace-collection.h \
        babeltrace/prio_heap.h \
@@ -30,6 +31,8 @@ noinst_HEADERS = \
        babeltrace/ctf/types.h \
        babeltrace/ctf/callbacks-internal.h \
        babeltrace/trace-handle-internal.h \
-       babeltrace/uuid.h \
+       babeltrace/compat/uuid.h \
+       babeltrace/compat/memstream.h \
+       babeltrace/compat/utc.h \
        babeltrace/endian.h \
        babeltrace/mmap-align.h
index c567d3952d532ed8aabb16005f6f16f4ad7b4218..9b9ffbdf4a7cf2213848c0cbd9437957fddaa8a8 100644 (file)
@@ -27,6 +27,9 @@
 #include <stdio.h>
 #include <glib.h>
 #include <stdint.h>
+#include <string.h>
+
+#define PERROR_BUFLEN  200
 
 extern int babeltrace_verbose, babeltrace_debug;
 
@@ -42,12 +45,149 @@ extern int babeltrace_verbose, babeltrace_debug;
                        fprintf(stdout, "[debug] " fmt, ## args);       \
        } while (0)
 
-#define likely(x)      __builtin_expect(!!(x), 1)
-#define unlikely(x)    __builtin_expect(!!(x), 0)
+#define _bt_printf(fp, kindstr, fmt, args...)                          \
+       fprintf(fp, "[%s]%s%s%s: " fmt "\n",                            \
+               kindstr,                                                \
+               babeltrace_debug ? " \"" : "",                          \
+               babeltrace_debug ? __func__ : "",                       \
+               babeltrace_debug ? "\"" : "",                           \
+               ## args)
+
+#define _bt_printfl(fp, kindstr, lineno, fmt, args...)                 \
+       fprintf(fp, "[%s]%s%s%s at line %u: " fmt "\n",                 \
+               kindstr,                                                \
+               babeltrace_debug ? " \"" : "",                          \
+               babeltrace_debug ? __func__ : "",                       \
+               babeltrace_debug ? "\"" : "",                           \
+               lineno,                                                 \
+               ## args)
+
+#define _bt_printfe(fp, kindstr, perrorstr, fmt, args...)              \
+       fprintf(fp, "[%s]%s%s%s: %s: " fmt "\n",                        \
+               kindstr,                                                \
+               babeltrace_debug ? " \"" : "",                          \
+               babeltrace_debug ? __func__ : "",                       \
+               babeltrace_debug ? "\"" : "",                           \
+               perrorstr,                                              \
+               ## args)
+
+#define _bt_printfle(fp, kindstr, lineno, perrorstr, fmt, args...)     \
+       fprintf(fp, "[%s]%s%s%s at line %u: %s: " fmt "\n",             \
+               kindstr,                                                \
+               babeltrace_debug ? " \"" : "",                          \
+               babeltrace_debug ? __func__ : "",                       \
+               babeltrace_debug ? "\"" : "",                           \
+               lineno,                                                 \
+               perrorstr,                                              \
+               ## args)
+
+#if !defined(__linux__) || ((_POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600) && !defined(_GNU_SOURCE))
+
+#define _bt_printf_perror(fp, fmt, args...)                            \
+       ({                                                              \
+               char buf[PERROR_BUFLEN] = "Error in strerror_r()";      \
+               strerror_r(errno, buf, sizeof(buf));                    \
+               _bt_printfe(fp, "error", buf, fmt, ## args);            \
+       })
+
+#define _bt_printfl_perror(fp, lineno, fmt, args...)                   \
+       ({                                                              \
+               char buf[PERROR_BUFLEN] = "Error in strerror_r()";      \
+               strerror_r(errno, buf, sizeof(buf));                    \
+               _bt_printfle(fp, "error", lineno, buf, fmt, ## args);   \
+       })
+
+#else
+
+/*
+ * Version using GNU strerror_r, for linux with appropriate defines.
+ */
+
+#define _bt_printf_perror(fp, fmt, args...)                            \
+       ({                                                              \
+               char *buf;                                              \
+               char tmp[PERROR_BUFLEN] = "Error in strerror_r()";      \
+               buf = strerror_r(errno, tmp, sizeof(tmp));              \
+               _bt_printfe(fp, "error", buf, fmt, ## args);            \
+       })
+
+#define _bt_printfl_perror(fp, lineno, fmt, args...)                   \
+       ({                                                              \
+               char *buf;                                              \
+               char tmp[PERROR_BUFLEN] = "Error in strerror_r()";      \
+               buf = strerror_r(errno, tmp, sizeof(tmp));              \
+               _bt_printfle(fp, "error", lineno, buf, fmt, ## args);   \
+       })
+
+#endif
+
+/* printf without lineno information */
+#define printf_fatal(fmt, args...)                                     \
+       _bt_printf(stderr, "fatal", fmt, ## args)
+#define printf_error(fmt, args...)                                     \
+       _bt_printf(stderr, "error", fmt, ## args)
+#define printf_warning(fmt, args...)                                   \
+       _bt_printf(stderr, "warning", fmt, ## args)
+#define printf_perror(fmt, args...)                                    \
+       _bt_printf_perror(stderr, fmt, ## args)
+
+/* printf with lineno information */
+#define printfl_fatal(lineno, fmt, args...)                            \
+       _bt_printfl(stderr, "fatal", lineno, fmt, ## args)
+#define printfl_error(lineno, fmt, args...)                            \
+       _bt_printfl(stderr, "error", lineno, fmt, ## args)
+#define printfl_warning(lineno, fmt, args...)                          \
+       _bt_printfl(stderr, "warning", lineno, fmt, ## args)
+#define printfl_perror(lineno, fmt, args...)                           \
+       _bt_printfl_perror(stderr, lineno, fmt, ## args)
+
+/* printf with node lineno information */
+#define printfn_fatal(node, fmt, args...)                              \
+       _bt_printfl(stderr, "fatal", (node)->lineno, fmt, ## args)
+#define printfn_error(node, fmt, args...)                              \
+       _bt_printfl(stderr, "error", (node)->lineno, fmt, ## args)
+#define printfn_warning(node, fmt, args...)                            \
+       _bt_printfl(stderr, "warning", (node)->lineno, fmt, ## args)
+#define printfn_perror(node, fmt, args...)                             \
+       _bt_printfl_perror(stderr, (node)->lineno, fmt, ## args)
+
+/* fprintf with Node lineno information */
+#define fprintfn_fatal(fp, node, fmt, args...)                         \
+       _bt_printfl(fp, "fatal", (node)->lineno, fmt, ## args)
+#define fprintfn_error(fp, node, fmt, args...)                         \
+       _bt_printfl(fp, "error", (node)->lineno, fmt, ## args)
+#define fprintfn_warning(fp, node, fmt, args...)                       \
+       _bt_printfl(fp, "warning", (node)->lineno, fmt, ## args)
+#define fprintfn_perror(fp, node, fmt, args...)                                \
+       _bt_printfl_perror(fp, (node)->lineno, fmt, ## args)
+
+#ifndef likely
+# ifdef __GNUC__
+#  define likely(x)      __builtin_expect(!!(x), 1)
+# else
+#  define likely(x)      (!!(x))
+# endif
+#endif
+
+#ifndef unlikely
+# ifdef __GNUC__
+#  define unlikely(x)    __builtin_expect(!!(x), 0)
+# else
+#  define unlikely(x)    (!!(x))
+# endif
+#endif
+
+/*
+ * BT_HIDDEN: set the hidden attribute for internal functions
+ */
+#define BT_HIDDEN __attribute__((visibility("hidden")))
+
+#define BT_CTF_MAJOR   1
+#define BT_CTF_MINOR   8
 
-struct trace_descriptor;
+struct bt_trace_descriptor;
 struct trace_collection {
-       GPtrArray *array;       /* struct trace_descriptor */
+       GPtrArray *array;       /* struct bt_trace_descriptor */
        GHashTable *clocks;     /* struct ctf_clock */
 
        uint64_t single_clock_offset_avg;
@@ -80,5 +220,6 @@ extern int opt_all_field_names,
        opt_clock_force_correlate;
 
 extern uint64_t opt_clock_offset;
+extern uint64_t opt_clock_offset_ns;
 
 #endif
diff --git a/include/babeltrace/compat/memstream.h b/include/babeltrace/compat/memstream.h
new file mode 100644 (file)
index 0000000..d2a96cb
--- /dev/null
@@ -0,0 +1,236 @@
+#ifndef _BABELTRACE_FORMAT_CTF_MEMSTREAM_H
+#define _BABELTRACE_FORMAT_CTF_MEMSTREAM_H
+
+/*
+ * format/ctf/memstream.h
+ *
+ * Copyright 2012 (c) - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
+ *
+ * memstream compatibility layer.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#define _GNU_SOURCE
+#include <config.h>
+
+#ifdef BABELTRACE_HAVE_FMEMOPEN
+#include <stdio.h>
+
+static inline
+FILE *babeltrace_fmemopen(void *buf, size_t size, const char *mode)
+{
+       return fmemopen(buf, size, mode);
+}
+
+#else /* BABELTRACE_HAVE_FMEMOPEN */
+
+#include <stdlib.h>
+#include <stdio.h>
+
+/*
+ * Fallback for systems which don't have fmemopen. Copy buffer to a
+ * temporary file, and use that file as FILE * input.
+ */
+static inline
+FILE *babeltrace_fmemopen(void *buf, size_t size, const char *mode)
+{
+       char tmpname[PATH_MAX];
+       size_t len;
+       FILE *fp;
+       int ret;
+
+       /*
+        * Support reading only.
+        */
+       if (strcmp(mode, "rb") != 0) {
+               return NULL;
+       }
+       strncpy(tmpname, "/tmp/babeltrace-tmp-XXXXXX", PATH_MAX);
+       ret = mkstemp(tmpname);
+       if (ret < 0) {
+               return NULL;
+       }
+       /*
+        * We need to write to the file.
+        */
+       fp = fdopen(ret, "w+");
+       if (!fp) {
+               goto error_unlink;
+       }
+       /* Copy the entire buffer to the file */
+       len = fwrite(buf, sizeof(char), size, fp);
+       if (len != size) {
+               goto error_close;
+       }
+       ret = fseek(fp, 0L, SEEK_SET);
+       if (ret < 0) {
+               perror("fseek");
+               goto error_close;
+       }
+       /* We keep the handle open, but can unlink the file on the VFS. */
+       ret = unlink(tmpname);
+       if (ret < 0) {
+               perror("unlink");
+       }
+       return fp;
+
+error_close:
+       ret = fclose(fp);
+       if (ret < 0) {
+               perror("close");
+       }
+error_unlink:
+       ret = unlink(tmpname);
+       if (ret < 0) {
+               perror("unlink");
+       }
+       return NULL;
+}
+
+#endif /* BABELTRACE_HAVE_FMEMOPEN */
+
+#ifdef BABELTRACE_HAVE_OPEN_MEMSTREAM
+
+#include <stdio.h>
+
+static inline
+FILE *babeltrace_open_memstream(char **ptr, size_t *sizeloc)
+{
+       return open_memstream(ptr, sizeloc);
+}
+
+static inline
+int babeltrace_close_memstream(char **buf, size_t *size, FILE *fp)
+{
+       return fclose(fp);
+}
+
+#else /* BABELTRACE_HAVE_OPEN_MEMSTREAM */
+
+#include <stdlib.h>
+#include <stdio.h>
+
+/*
+ * Fallback for systems which don't have open_memstream. Create FILE *
+ * with babeltrace_open_memstream, but require call to
+ * babeltrace_close_memstream to flush all data written to the FILE *
+ * into the buffer (which we allocate).
+ */
+static inline
+FILE *babeltrace_open_memstream(char **ptr, size_t *sizeloc)
+{
+       char tmpname[PATH_MAX];
+       int ret;
+       FILE *fp;
+
+       strncpy(tmpname, "/tmp/babeltrace-tmp-XXXXXX", PATH_MAX);
+       ret = mkstemp(tmpname);
+       if (ret < 0) {
+               return NULL;
+       }
+       fp = fdopen(ret, "w+");
+       if (!fp) {
+               goto error_unlink;
+       }
+       /*
+        * babeltrace_flush_memstream will update the buffer content
+        * with read from fp. No need to keep the file around, just the
+        * handle.
+        */
+       ret = unlink(tmpname);
+       if (ret < 0) {
+               perror("unlink");
+       }
+       return fp;
+
+error_unlink:
+       ret = unlink(tmpname);
+       if (ret < 0) {
+               perror("unlink");
+       }
+       return NULL;
+}
+
+/* Get file size, allocate buffer, copy. */
+static inline
+int babeltrace_close_memstream(char **buf, size_t *size, FILE *fp)
+{
+       size_t len, n;
+       long pos;
+       int ret;
+
+       ret = fflush(fp);
+       if (ret < 0) {
+               perror("fflush");
+               return ret;
+       }
+       ret = fseek(fp, 0L, SEEK_END);
+       if (ret < 0) {
+               perror("fseek");
+               return ret;
+       }
+       pos = ftell(fp);
+       if (ret < 0) {
+               perror("ftell");
+               return ret;
+       }
+       *size = pos;
+       /* add final \0 */
+       *buf = calloc(pos + 1, sizeof(char));
+       if (!*buf) {
+               return -ENOMEM;
+       }
+       ret = fseek(fp, 0L, SEEK_SET);
+       if (ret < 0) {
+               perror("fseek");
+               goto error_free;
+       }
+       /* Copy the entire file into the buffer */
+       n = 0;
+       clearerr(fp);
+       while (!feof(fp) && !ferror(fp) && (*size - n > 0)) {
+               len = fread(*buf, sizeof(char), *size - n, fp);
+               n += len;
+       }
+       if (n != *size) {
+               ret = -1;
+               goto error_close;
+       }
+       ret = fclose(fp);
+       if (ret < 0) {
+               perror("fclose");
+               return ret;
+       }
+       return 0;
+
+error_close:
+       ret = fclose(fp);
+       if (ret < 0) {
+               perror("fclose");
+       }
+error_free:
+       free(*buf);
+       *buf = NULL;
+       return ret;
+}
+
+#endif /* BABELTRACE_HAVE_OPEN_MEMSTREAM */
+
+#endif /* _BABELTRACE_FORMAT_CTF_MEMSTREAM_H */
diff --git a/include/babeltrace/compat/utc.h b/include/babeltrace/compat/utc.h
new file mode 100644 (file)
index 0000000..d59d856
--- /dev/null
@@ -0,0 +1,86 @@
+#ifndef _BABELTRACE_UTC_H
+#define _BABELTRACE_UTC_H
+
+/*
+ * Copyright (C) 2011-2013 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#include <time.h>
+
+/* If set, use GNU or BSD timegm(3) */
+#if defined(_BSD_SOURCE) || defined(_SVID_SOURCE)
+
+static inline
+time_t babeltrace_timegm(struct tm *tm)
+{
+       return timegm(tm);
+}
+
+#else
+
+#include <string.h>
+#include <stdlib.h>
+
+/*
+ * Note: Below implementation of timegm() is not thread safe
+ * as it changes the environment
+ * variable TZ. It is OK as long as it is kept in self-contained program,
+ * but should not be used within thread-safe library code.
+ */
+
+static inline
+time_t babeltrace_timegm(struct tm *tm)
+{
+       time_t ret;
+       char *tz;
+
+       tz = getenv("TZ");
+       /*
+        * Make a temporary copy, as the environment variable will be
+        * modified.
+        */
+       if (tz) {
+               tz = strdup(tz);
+               if (!tz) {
+                       /*
+                        * Memory allocation error.
+                        */
+                       return (time_t) -1;
+               }
+       }
+
+       /* Temporarily setting TZ to 1 for UTC */
+       setenv("TZ", "", 1);
+       tzset();
+       ret = mktime(tm);
+       if (tz) {
+               setenv("TZ", tz, 1);
+               free(tz);
+       } else {
+               unsetenv("TZ");
+       }
+       tzset();
+       return ret;
+}
+
+#endif
+
+#endif /* _BABELTRACE_UTC_H */
diff --git a/include/babeltrace/compat/uuid.h b/include/babeltrace/compat/uuid.h
new file mode 100644 (file)
index 0000000..2ce7467
--- /dev/null
@@ -0,0 +1,129 @@
+#ifndef _BABELTRACE_UUID_H
+#define _BABELTRACE_UUID_H
+
+/*
+ * babeltrace/uuid.h
+ *
+ * Copyright (C) 2011   Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#include <config.h>
+
+/* Includes final \0. */
+#define BABELTRACE_UUID_STR_LEN                37
+#define BABELTRACE_UUID_LEN            16
+
+#ifdef BABELTRACE_HAVE_LIBUUID
+#include <uuid/uuid.h>
+
+static inline
+int babeltrace_uuid_generate(unsigned char *uuid_out)
+{
+       uuid_generate(uuid_out);
+       return 0;
+}
+
+static inline
+int babeltrace_uuid_unparse(const unsigned char *uuid_in, char *str_out)
+{
+       uuid_unparse(uuid_in, str_out);
+       return 0;
+}
+
+static inline
+int babeltrace_uuid_parse(const char *str_in, unsigned char *uuid_out)
+{
+       return uuid_parse(str_in, uuid_out);
+}
+
+static inline
+int babeltrace_uuid_compare(const unsigned char *uuid_a,
+               const unsigned char *uuid_b)
+{
+       return uuid_compare(uuid_a, uuid_b);
+}
+
+#elif defined(BABELTRACE_HAVE_LIBC_UUID)
+#include <uuid.h>
+#include <stdint.h>
+#include <string.h>
+#include <stdlib.h>
+
+static inline
+int babeltrace_uuid_generate(unsigned char *uuid_out)
+{
+       uint32_t status;
+
+       uuid_create((uuid_t *) uuid_out, &status);
+       if (status == uuid_s_ok)
+               return 0;
+       else
+               return -1;
+}
+
+static inline
+int babeltrace_uuid_unparse(const unsigned char *uuid_in, char *str_out)
+{
+       uint32_t status;
+       char *alloc_str;
+       int ret;
+
+       uuid_to_string((uuid_t *) uuid_in, &alloc_str, &status);
+       if (status == uuid_s_ok) {
+               strcpy(str_out, alloc_str);
+               ret = 0;
+       } else {
+               ret = -1;
+       }
+       free(alloc_str);
+       return ret;
+}
+
+static inline
+int babeltrace_uuid_parse(const char *str_in, unsigned char *uuid_out)
+{
+       uint32_t status;
+
+       uuid_from_string(str_in, (uuid_t *) uuid_out, &status);
+       if (status == uuid_s_ok)
+               return 0;
+       else
+               return -1;
+}
+
+static inline
+int babeltrace_uuid_compare(const unsigned char *uuid_a,
+               const unsigned char *uuid_b)
+{
+       uint32_t status;
+
+       uuid_compare((uuid_t *) uuid_a, (uuid_t *) uuid_b, &status);
+       if (status == uuid_s_ok)
+               return 0;
+       else
+               return -1;
+}
+
+#else
+#error "Babeltrace needs to have a UUID generator configured."
+#endif
+
+#endif /* _BABELTRACE_UUID_H */
index f29ccf083f034c5e73a36132b42103668a3dfa19..b28df09f060cdcac484b08b8927c28b9f7e408f3 100644 (file)
@@ -40,7 +40,7 @@ extern "C" {
 
 /* struct bt_context is opaque to the user */
 struct bt_context;
-struct stream_pos;
+struct bt_stream_pos;
 struct bt_ctf_event;
 
 /*
@@ -82,9 +82,9 @@ struct bt_context *bt_context_create(void);
  */
 int bt_context_add_trace(struct bt_context *ctx, const char *path,
                const char *format,
-               void (*packet_seek)(struct stream_pos *pos,
+               void (*packet_seek)(struct bt_stream_pos *pos,
                        size_t index, int whence),
-               struct mmap_stream_list *stream_list,
+               struct bt_mmap_stream_list *stream_list,
                FILE *metadata);
 
 /*
index fc555fdd96f5e79cef3ddc9cae20e70a19628929..5e92984dba40906c59bb96c5e4455182bc13233e 100644 (file)
 
 #include <babeltrace/types.h>
 #include <babeltrace/format.h>
+#include <babeltrace/format-internal.h>
 #include <babeltrace/ctf/types.h>
 #include <sys/types.h>
 #include <dirent.h>
-#include <babeltrace/uuid.h>
+#include <babeltrace/compat/uuid.h>
 #include <assert.h>
 #include <glib.h>
 
@@ -66,6 +67,7 @@ struct ctf_stream_definition {
        uint64_t prev_real_timestamp_end;       /* End-of-last-packet timestamp in ns */
        uint64_t prev_cycles_timestamp;         /* Start-of-last-packet timestamp in cycles */
        uint64_t prev_cycles_timestamp_end;     /* End-of-last-packet timestamp in cycles */
+       char path[PATH_MAX];                    /* Path to stream. '\0' for mmap traces */
 };
 
 struct ctf_event_definition {
@@ -174,7 +176,8 @@ struct ctf_tracer_env {
 };
 
 struct ctf_trace {
-       struct trace_descriptor parent;
+       struct bt_trace_descriptor parent;
+
        /* root scope */
        struct declaration_scope *root_declaration_scope;
 
@@ -183,10 +186,9 @@ struct ctf_trace {
        struct definition_scope *definition_scope;
        GPtrArray *streams;                     /* Array of struct ctf_stream_declaration pointers */
        struct ctf_stream_definition *metadata;
-       GHashTable *clocks;
+       char *metadata_string;
+       int metadata_packetized;
        GHashTable *callsites;
-       struct ctf_clock *single_clock;         /* currently supports only one clock */
-       struct trace_collection *collection;    /* Container of this trace */
        GPtrArray *event_declarations;          /* Array of all the struct bt_ctf_event_decl */
 
        struct declaration_struct *packet_header_decl;
@@ -209,13 +211,6 @@ struct ctf_trace {
        DIR *dir;
        int dirfd;
        int flags;              /* open flags */
-
-       /* Heap of streams, ordered to always get the lowest timestam */
-       struct ptr_heap *stream_heap;
-       char path[PATH_MAX];
-
-       struct bt_context *ctx;
-       struct bt_trace_handle *handle;
 };
 
 #define CTF_STREAM_SET_FIELD(ctf_stream, field)                                \
@@ -234,7 +229,7 @@ struct ctf_trace {
 
 struct ctf_stream_declaration {
        struct ctf_trace *trace;
-       /* parent is lexical scope conaining the stream scope */
+       /* parent is lexical scope containing the stream scope */
        struct declaration_scope *declaration_scope;
        /* innermost definition scope. to be used as parent of event. */
        struct definition_scope *definition_scope;
@@ -271,7 +266,7 @@ struct ctf_stream_declaration {
 struct ctf_event_declaration {
        /* stream mapped by stream_id */
        struct ctf_stream_declaration *stream;
-       /* parent is lexical scope conaining the event scope */
+       /* parent is lexical scope containing the event scope */
        struct declaration_scope *declaration_scope;
 
        struct declaration_struct *context_decl;
index d69af90523220b33ee03dc18b3fd039583add267..7b4b7171e733176b54536816e0a9ee1f8b06423b 100644 (file)
 #include <babeltrace/babeltrace-internal.h>
 #include <babeltrace/types.h>
 #include <babeltrace/format.h>
+#include <babeltrace/format-internal.h>
 
 /*
- * Inherit from both struct stream_pos and struct trace_descriptor.
+ * Inherit from both struct bt_stream_pos and struct bt_trace_descriptor.
  */
 struct ctf_text_stream_pos {
-       struct stream_pos parent;
-       struct trace_descriptor trace_descriptor;
+       struct bt_stream_pos parent;
+       struct bt_trace_descriptor trace_descriptor;
        FILE *fp;               /* File pointer. NULL if unset. */
        int depth;
        int dummy;              /* disable output */
@@ -53,7 +54,7 @@ struct ctf_text_stream_pos {
 };
 
 static inline
-struct ctf_text_stream_pos *ctf_text_pos(struct stream_pos *pos)
+struct ctf_text_stream_pos *ctf_text_pos(struct bt_stream_pos *pos)
 {
        return container_of(pos, struct ctf_text_stream_pos, parent);
 }
@@ -61,14 +62,22 @@ struct ctf_text_stream_pos *ctf_text_pos(struct stream_pos *pos)
 /*
  * Write only is supported for now.
  */
-int ctf_text_integer_write(struct stream_pos *pos, struct definition *definition);
-int ctf_text_float_write(struct stream_pos *pos, struct definition *definition);
-int ctf_text_string_write(struct stream_pos *pos, struct definition *definition);
-int ctf_text_enum_write(struct stream_pos *pos, struct definition *definition);
-int ctf_text_struct_write(struct stream_pos *pos, struct definition *definition);
-int ctf_text_variant_write(struct stream_pos *pos, struct definition *definition);
-int ctf_text_array_write(struct stream_pos *pos, struct definition *definition);
-int ctf_text_sequence_write(struct stream_pos *pos, struct definition *definition);
+BT_HIDDEN
+int ctf_text_integer_write(struct bt_stream_pos *pos, struct bt_definition *definition);
+BT_HIDDEN
+int ctf_text_float_write(struct bt_stream_pos *pos, struct bt_definition *definition);
+BT_HIDDEN
+int ctf_text_string_write(struct bt_stream_pos *pos, struct bt_definition *definition);
+BT_HIDDEN
+int ctf_text_enum_write(struct bt_stream_pos *pos, struct bt_definition *definition);
+BT_HIDDEN
+int ctf_text_struct_write(struct bt_stream_pos *pos, struct bt_definition *definition);
+BT_HIDDEN
+int ctf_text_variant_write(struct bt_stream_pos *pos, struct bt_definition *definition);
+BT_HIDDEN
+int ctf_text_array_write(struct bt_stream_pos *pos, struct bt_definition *definition);
+BT_HIDDEN
+int ctf_text_sequence_write(struct bt_stream_pos *pos, struct bt_definition *definition);
 
 static inline
 void print_pos_tabs(struct ctf_text_stream_pos *pos)
@@ -82,6 +91,7 @@ void print_pos_tabs(struct ctf_text_stream_pos *pos)
 /*
  * Check if the field must be printed.
  */
-int print_field(struct definition *definition);
+BT_HIDDEN
+int print_field(struct bt_definition *definition);
 
 #endif /* _BABELTRACE_CTF_TEXT_TYPES_H */
index 0390b9a4ef3d22309c873a172fbbc48bf14125f5..41bc8461ef7bb79aaf4d95dee758d287880802cd 100644 (file)
@@ -60,6 +60,7 @@ struct bt_dependencies {
        int refcount;                   /* free when decremented to 0 */
 };
 
+BT_HIDDEN
 void process_callbacks(struct bt_ctf_iter *iter, struct ctf_stream_definition *stream);
 
 #endif /* _BABELTRACE_CALLBACKS_INTERNAL_H */
index c178767ced7d00ea7ed412522eed09c7803ed441..bc75769d5021b6f1bc1fe569b53cef6e0b843fa1 100644 (file)
@@ -51,13 +51,13 @@ enum bt_cb_ret {
 /*
  * Receives a variable number of strings as parameter, ended with NULL.
  */
-struct bt_dependencies *babeltrace_dependencies_create(const char *first, ...);
+struct bt_dependencies *bt_dependencies_create(const char *first, ...);
 
 /*
  * struct bt_dependencies must be destroyed explicitly if not passed as
  * parameter to a bt_ctf_iter_add_callback().
  */
-void babeltrace_dependencies_destroy(struct bt_dependencies *dep);
+void bt_dependencies_destroy(struct bt_dependencies *dep);
 
 /*
  * bt_ctf_iter_add_callback: Add a callback to iterator.
index 0356906f3432eb6192bf13e997dfe1c6858a32d9..be111c1710144a86056cb6441ab8357a2a31ba65 100644 (file)
@@ -79,4 +79,7 @@ struct bt_ctf_iter {
        uint64_t events_lost;
 };
 
+void ctf_print_discarded(FILE *fp, struct ctf_stream_definition *stream,
+                       int end_stream);
+
 #endif /*_BABELTRACE_CTF_EVENTS_INTERNAL_H */
index 19d73612b45d78695d5508e5fc6788a855cea3f3..c92470cf83de30effd11a2da27928f804f501980 100644 (file)
@@ -39,8 +39,8 @@
 extern "C" {
 #endif
 
-struct definition;
-struct declaration;
+struct bt_definition;
+struct bt_declaration;
 struct bt_ctf_event;
 struct bt_ctf_event_decl;
 struct bt_ctf_field_decl;
@@ -94,7 +94,7 @@ enum ctf_string_encoding {
  * between the enum and the actual definition of top-level scopes.
  * On error return NULL.
  */
-const struct definition *bt_ctf_get_top_level_scope(const struct bt_ctf_event *event,
+const struct bt_definition *bt_ctf_get_top_level_scope(const struct bt_ctf_event *event,
                enum bt_ctf_scope scope);
 
 /*
@@ -130,47 +130,47 @@ uint64_t bt_ctf_get_timestamp(const struct bt_ctf_event *event);
  * from which the event is extracted is unchanged).
  */
 int bt_ctf_get_field_list(const struct bt_ctf_event *event,
-               const struct definition *scope,
-               struct definition const * const **list,
+               const struct bt_definition *scope,
+               struct bt_definition const * const **list,
                unsigned int *count);
 
 /*
  * bt_ctf_get_field: returns the definition of a specific field
  */
-const struct definition *bt_ctf_get_field(const struct bt_ctf_event *event,
-               const struct definition *scope,
+const struct bt_definition *bt_ctf_get_field(const struct bt_ctf_event *event,
+               const struct bt_definition *scope,
                const char *field);
 
 /*
  * bt_ctf_get_index: if the field is an array or a sequence, return the element
  * at position index, otherwise return NULL;
  */
-const struct definition *bt_ctf_get_index(const struct bt_ctf_event *event,
-               const struct definition *field,
+const struct bt_definition *bt_ctf_get_index(const struct bt_ctf_event *event,
+               const struct bt_definition *field,
                unsigned int index);
 
 /*
  * bt_ctf_field_name: returns the name of a field or NULL on error
  */
-const char *bt_ctf_field_name(const struct definition *def);
+const char *bt_ctf_field_name(const struct bt_definition *def);
 
 /*
  * bt_ctf_get_decl_from_def: return the declaration of a field from
  * its definition or NULL on error
  */
-const struct declaration *bt_ctf_get_decl_from_def(const struct definition *def);
+const struct bt_declaration *bt_ctf_get_decl_from_def(const struct bt_definition *def);
 
 /*
  * bt_ctf_get_decl_from_field_decl: return the declaration of a field from
  * a field_decl or NULL on error
  */
-const struct declaration *bt_ctf_get_decl_from_field_decl(
+const struct bt_declaration *bt_ctf_get_decl_from_field_decl(
                const struct bt_ctf_field_decl *field);
 
 /*
  * bt_ctf_field_type: returns the type of a field or -1 if unknown
  */
-enum ctf_type_id bt_ctf_field_type(const struct declaration *decl);
+enum ctf_type_id bt_ctf_field_type(const struct bt_declaration *decl);
 
 /*
  * bt_ctf_get_int_signedness: return the signedness of an integer
@@ -179,37 +179,37 @@ enum ctf_type_id bt_ctf_field_type(const struct declaration *decl);
  * return 1 if signed
  * return -1 on error
  */
-int bt_ctf_get_int_signedness(const struct declaration *decl);
+int bt_ctf_get_int_signedness(const struct bt_declaration *decl);
 
 /*
  * bt_ctf_get_int_base: return the base of an int or a negative value on error
  */
-int bt_ctf_get_int_base(const struct declaration *decl);
+int bt_ctf_get_int_base(const struct bt_declaration *decl);
 
 /*
  * bt_ctf_get_int_byte_order: return the byte order of an int or a negative
  * value on error
  */
-int bt_ctf_get_int_byte_order(const struct declaration *decl);
+int bt_ctf_get_int_byte_order(const struct bt_declaration *decl);
 
 /*
  * bt_ctf_get_int_len: return the size, in bits, of an int or a negative
  * value on error
  */
-ssize_t bt_ctf_get_int_len(const struct declaration *decl);
+ssize_t bt_ctf_get_int_len(const struct bt_declaration *decl);
 
 /*
  * bt_ctf_get_encoding: return the encoding of an int, a string, or of
  * the integer contained in a char array or a sequence.
  * return a negative value on error
  */
-enum ctf_string_encoding bt_ctf_get_encoding(const struct declaration *decl);
+enum ctf_string_encoding bt_ctf_get_encoding(const struct bt_declaration *decl);
 
 /*
  * bt_ctf_get_array_len: return the len of an array or a negative
  * value on error
  */
-int bt_ctf_get_array_len(const struct declaration *decl);
+int bt_ctf_get_array_len(const struct bt_declaration *decl);
 
 /*
  * Field access functions
@@ -225,12 +225,12 @@ int bt_ctf_get_array_len(const struct declaration *decl);
  * bt_ctf_get_enum_str gets the string matching the current enumeration
  * value, or NULL if the current value does not match any string.
  */
-uint64_t bt_ctf_get_uint64(const struct definition *field);
-int64_t bt_ctf_get_int64(const struct definition *field);
-const struct definition *bt_ctf_get_enum_int(const struct definition *field);
-const char *bt_ctf_get_enum_str(const struct definition *field);
-char *bt_ctf_get_char_array(const struct definition *field);
-char *bt_ctf_get_string(const struct definition *field);
+uint64_t bt_ctf_get_uint64(const struct bt_definition *field);
+int64_t bt_ctf_get_int64(const struct bt_definition *field);
+const struct bt_definition *bt_ctf_get_enum_int(const struct bt_definition *field);
+const char *bt_ctf_get_enum_str(const struct bt_definition *field);
+char *bt_ctf_get_char_array(const struct bt_definition *field);
+char *bt_ctf_get_string(const struct bt_definition *field);
 
 /*
  * bt_ctf_field_get_error: returns the last error code encountered while
index 6b8752e2d60ce8136b05ac07ddfb6428f056c870..715cdbd0e182e39f204a4e19aba338ba49265e91 100644 (file)
@@ -59,7 +59,7 @@ struct packet_index {
  * Always update ctf_stream_pos with ctf_move_pos and ctf_init_pos.
  */
 struct ctf_stream_pos {
-       struct stream_pos parent;
+       struct bt_stream_pos parent;
        int fd;                 /* backing file fd. -1 if unset. */
        GArray *packet_cycles_index;    /* contains struct packet_index in cycles */
        GArray *packet_real_index;      /* contains struct packet_index in ns */
@@ -77,7 +77,7 @@ struct ctf_stream_pos {
        int64_t last_offset;    /* offset before the last read_event */
        uint64_t cur_index;     /* current index in packet index */
        uint64_t last_events_discarded; /* last known amount of event discarded */
-       void (*packet_seek)(struct stream_pos *pos, size_t index,
+       void (*packet_seek)(struct bt_stream_pos *pos, size_t index,
                        int whence); /* function called to switch packet */
 
        int dummy;              /* dummy position, for length calculation */
@@ -85,29 +85,44 @@ struct ctf_stream_pos {
 };
 
 static inline
-struct ctf_stream_pos *ctf_pos(struct stream_pos *pos)
+struct ctf_stream_pos *ctf_pos(struct bt_stream_pos *pos)
 {
        return container_of(pos, struct ctf_stream_pos, parent);
 }
 
-int ctf_integer_read(struct stream_pos *pos, struct definition *definition);
-int ctf_integer_write(struct stream_pos *pos, struct definition *definition);
-int ctf_float_read(struct stream_pos *pos, struct definition *definition);
-int ctf_float_write(struct stream_pos *pos, struct definition *definition);
-int ctf_string_read(struct stream_pos *pos, struct definition *definition);
-int ctf_string_write(struct stream_pos *pos, struct definition *definition);
-int ctf_enum_read(struct stream_pos *pos, struct definition *definition);
-int ctf_enum_write(struct stream_pos *pos, struct definition *definition);
-int ctf_struct_rw(struct stream_pos *pos, struct definition *definition);
-int ctf_variant_rw(struct stream_pos *pos, struct definition *definition);
-int ctf_array_read(struct stream_pos *pos, struct definition *definition);
-int ctf_array_write(struct stream_pos *pos, struct definition *definition);
-int ctf_sequence_read(struct stream_pos *pos, struct definition *definition);
-int ctf_sequence_write(struct stream_pos *pos, struct definition *definition);
-
-void ctf_packet_seek(struct stream_pos *pos, size_t index, int whence);
-
-int ctf_init_pos(struct ctf_stream_pos *pos, int fd, int open_flags);
+BT_HIDDEN
+int ctf_integer_read(struct bt_stream_pos *pos, struct bt_definition *definition);
+BT_HIDDEN
+int ctf_integer_write(struct bt_stream_pos *pos, struct bt_definition *definition);
+BT_HIDDEN
+int ctf_float_read(struct bt_stream_pos *pos, struct bt_definition *definition);
+BT_HIDDEN
+int ctf_float_write(struct bt_stream_pos *pos, struct bt_definition *definition);
+BT_HIDDEN
+int ctf_string_read(struct bt_stream_pos *pos, struct bt_definition *definition);
+BT_HIDDEN
+int ctf_string_write(struct bt_stream_pos *pos, struct bt_definition *definition);
+BT_HIDDEN
+int ctf_enum_read(struct bt_stream_pos *pos, struct bt_definition *definition);
+BT_HIDDEN
+int ctf_enum_write(struct bt_stream_pos *pos, struct bt_definition *definition);
+BT_HIDDEN
+int ctf_struct_rw(struct bt_stream_pos *pos, struct bt_definition *definition);
+BT_HIDDEN
+int ctf_variant_rw(struct bt_stream_pos *pos, struct bt_definition *definition);
+BT_HIDDEN
+int ctf_array_read(struct bt_stream_pos *pos, struct bt_definition *definition);
+BT_HIDDEN
+int ctf_array_write(struct bt_stream_pos *pos, struct bt_definition *definition);
+BT_HIDDEN
+int ctf_sequence_read(struct bt_stream_pos *pos, struct bt_definition *definition);
+BT_HIDDEN
+int ctf_sequence_write(struct bt_stream_pos *pos, struct bt_definition *definition);
+
+void ctf_packet_seek(struct bt_stream_pos *pos, size_t index, int whence);
+
+int ctf_init_pos(struct ctf_stream_pos *pos, struct bt_trace_descriptor *trace,
+               int fd, int open_flags);
 int ctf_fini_pos(struct ctf_stream_pos *pos);
 
 /*
diff --git a/include/babeltrace/format-internal.h b/include/babeltrace/format-internal.h
new file mode 100644 (file)
index 0000000..7f3eb5e
--- /dev/null
@@ -0,0 +1,54 @@
+#ifndef _BABELTRACE_FORMAT_INTERNAL_H
+#define _BABELTRACE_FORMAT_INTERNAL_H
+
+/*
+ * BabelTrace
+ *
+ * Trace Format Internal Header
+ *
+ * Copyright 2010-2013 EfficiOS Inc. and Linux Foundation
+ *
+ * Author: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#include <limits.h>
+#include <babeltrace/context-internal.h>
+#include <babeltrace/babeltrace-internal.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* Parent trace descriptor */
+struct bt_trace_descriptor {
+       char path[PATH_MAX];            /* trace path */
+       struct bt_context *ctx;
+       struct bt_trace_handle *handle;
+       struct trace_collection *collection;    /* Container of this trace */
+       GHashTable *clocks;
+       struct ctf_clock *single_clock;         /* currently supports only one clock */
+};
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _BABELTRACE_FORMAT_INTERNAL_H */
index c6faca71d9ada4774e82483e5f527904037a6761..07e854fee08645acb85b1e4cf0083992e385598e 100644 (file)
@@ -41,51 +41,48 @@ extern "C" {
 typedef int bt_intern_str;
 
 /* forward declaration */
-struct stream_pos;
+struct bt_stream_pos;
 struct bt_context;
 struct bt_trace_handle;
+struct bt_trace_descriptor;
 
-/* Parent trace descriptor */
-struct trace_descriptor {
-};
-
-struct mmap_stream {
+struct bt_mmap_stream {
        int fd;
        struct bt_list_head list;
 };
 
-struct mmap_stream_list {
+struct bt_mmap_stream_list {
        struct bt_list_head head;
 };
 
-struct format {
+struct bt_format {
        bt_intern_str name;
 
-       struct trace_descriptor *(*open_trace)(const char *path, int flags,
-                       void (*packet_seek)(struct stream_pos *pos,
+       struct bt_trace_descriptor *(*open_trace)(const char *path, int flags,
+                       void (*packet_seek)(struct bt_stream_pos *pos,
                                size_t index, int whence),
                        FILE *metadata_fp);
-       struct trace_descriptor *(*open_mmap_trace)(
-                       struct mmap_stream_list *mmap_list,
-                       void (*packet_seek)(struct stream_pos *pos,
+       struct bt_trace_descriptor *(*open_mmap_trace)(
+                       struct bt_mmap_stream_list *mmap_list,
+                       void (*packet_seek)(struct bt_stream_pos *pos,
                                size_t index, int whence),
                        FILE *metadata_fp);
-       int (*close_trace)(struct trace_descriptor *descriptor);
-       void (*set_context)(struct trace_descriptor *descriptor,
+       int (*close_trace)(struct bt_trace_descriptor *descriptor);
+       void (*set_context)(struct bt_trace_descriptor *descriptor,
                        struct bt_context *ctx);
-       void (*set_handle)(struct trace_descriptor *descriptor,
+       void (*set_handle)(struct bt_trace_descriptor *descriptor,
                        struct bt_trace_handle *handle);
-       uint64_t (*timestamp_begin)(struct trace_descriptor *descriptor,
+       uint64_t (*timestamp_begin)(struct bt_trace_descriptor *descriptor,
                        struct bt_trace_handle *handle, enum bt_clock_type type);
-       uint64_t (*timestamp_end)(struct trace_descriptor *descriptor,
+       uint64_t (*timestamp_end)(struct bt_trace_descriptor *descriptor,
                        struct bt_trace_handle *handle, enum bt_clock_type type);
-       int (*convert_index_timestamp)(struct trace_descriptor *descriptor);
+       int (*convert_index_timestamp)(struct bt_trace_descriptor *descriptor);
 };
 
-extern struct format *bt_lookup_format(bt_intern_str qname);
+extern struct bt_format *bt_lookup_format(bt_intern_str qname);
 extern void bt_fprintf_format_list(FILE *fp);
-extern int bt_register_format(struct format *format);
-extern void bt_unregister_format(struct format *format);
+extern int bt_register_format(struct bt_format *format);
+extern void bt_unregister_format(struct bt_format *format);
 
 #ifdef __cplusplus
 }
index 90aec8f8cacd976edb08a0ec06b404da2a677ccc..52de47c86d50f1864abe6fd4c876e85514bae5cd 100644 (file)
@@ -47,38 +47,38 @@ void check_heap(const struct ptr_heap *heap)
 #endif
 
 /**
- * heap_maximum - return the largest element in the heap
+ * bt_heap_maximum - return the largest element in the heap
  * @heap: the heap to be operated on
  *
  * Returns the largest element in the heap, without performing any modification
  * to the heap structure. Returns NULL if the heap is empty.
  */
-static inline void *heap_maximum(const struct ptr_heap *heap)
+static inline void *bt_heap_maximum(const struct ptr_heap *heap)
 {
        check_heap(heap);
        return likely(heap->len) ? heap->ptrs[0] : NULL;
 }
 
 /**
- * heap_init - initialize the heap
+ * bt_heap_init - initialize the heap
  * @heap: the heap to initialize
  * @alloc_len: number of elements initially allocated
  * @gt: function to compare the elements
  *
  * Returns -ENOMEM if out of memory.
  */
-extern int heap_init(struct ptr_heap *heap,
+extern int bt_heap_init(struct ptr_heap *heap,
                     size_t alloc_len,
                     int gt(void *a, void *b));
 
 /**
- * heap_free - free the heap
+ * bt_heap_free - free the heap
  * @heap: the heap to free
  */
-extern void heap_free(struct ptr_heap *heap);
+extern void bt_heap_free(struct ptr_heap *heap);
 
 /**
- * heap_insert - insert an element into the heap
+ * bt_heap_insert - insert an element into the heap
  * @heap: the heap to be operated on
  * @p: the element to add
  *
@@ -86,19 +86,19 @@ extern void heap_free(struct ptr_heap *heap);
  *
  * Returns -ENOMEM if out of memory.
  */
-extern int heap_insert(struct ptr_heap *heap, void *p);
+extern int bt_heap_insert(struct ptr_heap *heap, void *p);
 
 /**
- * heap_remove - remove the largest element from the heap
+ * bt_heap_remove - remove the largest element from the heap
  * @heap: the heap to be operated on
  *
  * Returns the largest element in the heap. It removes this element from the
  * heap. Returns NULL if the heap is empty.
  */
-extern void *heap_remove(struct ptr_heap *heap);
+extern void *bt_heap_remove(struct ptr_heap *heap);
 
 /**
- * heap_cherrypick - remove a given element from the heap
+ * bt_heap_cherrypick - remove a given element from the heap
  * @heap: the heap to be operated on
  * @p: the element
  *
@@ -106,10 +106,10 @@ extern void *heap_remove(struct ptr_heap *heap);
  * return NULL. This algorithm has a complexity of O(n), which is higher than
  * O(log(n)) provided by the rest of this API.
  */
-extern void *heap_cherrypick(struct ptr_heap *heap, void *p);
+extern void *bt_heap_cherrypick(struct ptr_heap *heap, void *p);
 
 /**
- * heap_replace_max - replace the the largest element from the heap
+ * bt_heap_replace_max - replace the the largest element from the heap
  * @heap: the heap to be operated on
  * @p: the pointer to be inserted as topmost element replacement
  *
@@ -117,18 +117,18 @@ extern void *heap_cherrypick(struct ptr_heap *heap, void *p);
  * heap. The heap is rebalanced only once after the insertion. Returns NULL if
  * the heap is empty.
  *
- * This is the equivalent of calling heap_remove() and then heap_insert(), but
+ * This is the equivalent of calling bt_heap_remove() and then bt_heap_insert(), but
  * it only rebalances the heap once. It never allocates memory.
  */
-extern void *heap_replace_max(struct ptr_heap *heap, void *p);
+extern void *bt_heap_replace_max(struct ptr_heap *heap, void *p);
 
 /**
- * heap_copy - copy a heap
+ * bt_heap_copy - copy a heap
  * @dst: the destination heap (must be allocated)
  * @src: the source heap
  *
  * Returns -ENOMEM if out of memory.
  */
-extern int heap_copy(struct ptr_heap *dst, struct ptr_heap *src);
+extern int bt_heap_copy(struct ptr_heap *dst, struct ptr_heap *src);
 
 #endif /* _BABELTRACE_PRIO_HEAP_H */
index 2ac9ba6a315883286a1580a74e12d3c80d489196..904a7d8594e290280a84dfd249e102ee63eda6c2 100644 (file)
@@ -35,12 +35,12 @@ extern "C" {
 
 struct trace_collection;
 
-void init_trace_collection(struct trace_collection *tc);
-void finalize_trace_collection(struct trace_collection *tc);
-int trace_collection_add(struct trace_collection *tc,
-                        struct trace_descriptor *td);
-int trace_collection_remove(struct trace_collection *tc,
-                        struct trace_descriptor *td);
+void bt_init_trace_collection(struct trace_collection *tc);
+void bt_finalize_trace_collection(struct trace_collection *tc);
+int bt_trace_collection_add(struct trace_collection *tc,
+                        struct bt_trace_descriptor *td);
+int bt_trace_collection_remove(struct trace_collection *tc,
+                        struct bt_trace_descriptor *td);
 
 #ifdef __cplusplus
 }
index 2b5a5ae198e75163458c0f696184c92e11b9f23d..5e9c1c6a943865ed3d45121ab73c56983cfefa66 100644 (file)
@@ -43,8 +43,8 @@
  */
 struct bt_trace_handle {
        int id;
-       struct trace_descriptor *td;
-       struct format *format;
+       struct bt_trace_descriptor *td;
+       struct bt_format *format;
        char path[PATH_MAX];
        uint64_t real_timestamp_begin;
        uint64_t real_timestamp_end;
index b42ba03e066ef65cd7b18d4f0d8fed5e0f82a345..8d660bea0e747fa21b0e20221a038dc4fbb5fab0 100644 (file)
@@ -43,9 +43,9 @@
 #define DEFAULT_NR_STRUCT_FIELDS 8
 
 struct ctf_stream_definition;
-struct stream_pos;
-struct format;
-struct definition;
+struct bt_stream_pos;
+struct bt_format;
+struct bt_definition;
 struct ctf_clock;
 
 /* type scope */
@@ -78,27 +78,27 @@ struct definition_scope {
        GArray *scope_path;     /* array of GQuark */
 };
 
-struct declaration {
+struct bt_declaration {
        enum ctf_type_id id;
        size_t alignment;       /* type alignment, in bits */
        int ref;                /* number of references to the type */
        /*
         * declaration_free called with declaration ref is decremented to 0.
         */
-       void (*declaration_free)(struct declaration *declaration);
-       struct definition *
-               (*definition_new)(struct declaration *declaration,
+       void (*declaration_free)(struct bt_declaration *declaration);
+       struct bt_definition *
+               (*definition_new)(struct bt_declaration *declaration,
                                  struct definition_scope *parent_scope,
                                  GQuark field_name, int index,
                                  const char *root_name);
        /*
         * definition_free called with definition ref is decremented to 0.
         */
-       void (*definition_free)(struct definition *definition);
+       void (*definition_free)(struct bt_definition *definition);
 };
 
-struct definition {
-       struct declaration *declaration;
+struct bt_definition {
+       struct bt_declaration *declaration;
        int index;              /* Position of the definition in its container */
        GQuark name;            /* Field name in its container (or 0 if unset) */
        int ref;                /* number of references to the definition */
@@ -106,19 +106,24 @@ struct definition {
        struct definition_scope *scope;
 };
 
-typedef int (*rw_dispatch)(struct stream_pos *pos,
-                          struct definition *definition);
+typedef int (*rw_dispatch)(struct bt_stream_pos *pos,
+                          struct bt_definition *definition);
 
 /* Parent of per-plugin positions */
-struct stream_pos {
+struct bt_stream_pos {
        /* read/write dispatch table. Specific to plugin used for stream. */
        rw_dispatch *rw_table;  /* rw dispatch table */
-       int (*event_cb)(struct stream_pos *pos,
+       int (*event_cb)(struct bt_stream_pos *pos,
                        struct ctf_stream_definition *stream);
+       int (*pre_trace_cb)(struct bt_stream_pos *pos,
+                       struct bt_trace_descriptor *trace);
+       int (*post_trace_cb)(struct bt_stream_pos *pos,
+                       struct bt_trace_descriptor *trace);
+       struct bt_trace_descriptor *trace;
 };
 
 static inline
-int generic_rw(struct stream_pos *pos, struct definition *definition)
+int generic_rw(struct bt_stream_pos *pos, struct bt_definition *definition)
 {
        enum ctf_type_id dispatch_id = definition->declaration->id;
        rw_dispatch call;
@@ -134,7 +139,7 @@ int generic_rw(struct stream_pos *pos, struct definition *definition)
  * read/write non aligned on CHAR_BIT.
  */
 struct declaration_integer {
-       struct declaration p;
+       struct bt_declaration p;
        size_t len;             /* length, in bits. */
        int byte_order;         /* byte order */
        int signedness;
@@ -144,7 +149,7 @@ struct declaration_integer {
 };
 
 struct definition_integer {
-       struct definition p;
+       struct bt_definition p;
        struct declaration_integer *declaration;
        /* Last values read */
        union {
@@ -154,7 +159,7 @@ struct definition_integer {
 };
 
 struct declaration_float {
-       struct declaration p;
+       struct bt_declaration p;
        struct declaration_integer *sign;
        struct declaration_integer *mantissa;
        struct declaration_integer *exp;
@@ -163,7 +168,7 @@ struct declaration_float {
 };
 
 struct definition_float {
-       struct definition p;
+       struct bt_definition p;
        struct declaration_float *declaration;
        struct definition_integer *sign;
        struct definition_integer *mantissa;
@@ -211,13 +216,13 @@ struct enum_table {
 };
 
 struct declaration_enum {
-       struct declaration p;
+       struct bt_declaration p;
        struct declaration_integer *integer_declaration;
        struct enum_table table;
 };
 
 struct definition_enum {
-       struct definition p;
+       struct bt_definition p;
        struct definition_integer *integer;
        struct declaration_enum *declaration;
        /* Last GQuark values read. Keeping a reference on the GQuark array. */
@@ -225,12 +230,12 @@ struct definition_enum {
 };
 
 struct declaration_string {
-       struct declaration p;
+       struct bt_declaration p;
        enum ctf_string_encoding encoding;
 };
 
 struct definition_string {
-       struct definition p;
+       struct bt_definition p;
        struct declaration_string *declaration;
        char *value;    /* freed at definition_string teardown */
        size_t len, alloc_len;
@@ -238,77 +243,77 @@ struct definition_string {
 
 struct declaration_field {
        GQuark name;
-       struct declaration *declaration;
+       struct bt_declaration *declaration;
 };
 
 struct declaration_struct {
-       struct declaration p;
+       struct bt_declaration p;
        GHashTable *fields_by_name;     /* Tuples (field name, field index) */
        struct declaration_scope *scope;
        GArray *fields;                 /* Array of declaration_field */
 };
 
 struct definition_struct {
-       struct definition p;
+       struct bt_definition p;
        struct declaration_struct *declaration;
-       GPtrArray *fields;              /* Array of pointers to struct definition */
+       GPtrArray *fields;              /* Array of pointers to struct bt_definition */
 };
 
 struct declaration_untagged_variant {
-       struct declaration p;
+       struct bt_declaration p;
        GHashTable *fields_by_tag;      /* Tuples (field tag, field index) */
        struct declaration_scope *scope;
        GArray *fields;                 /* Array of declaration_field */
 };
 
 struct declaration_variant {
-       struct declaration p;
+       struct bt_declaration p;
        struct declaration_untagged_variant *untagged_variant;
        GArray *tag_name;               /* Array of GQuark */
 };
 
 /* A variant needs to be tagged to be defined. */
 struct definition_variant {
-       struct definition p;
+       struct bt_definition p;
        struct declaration_variant *declaration;
-       struct definition *enum_tag;
-       GPtrArray *fields;              /* Array of pointers to struct definition */
-       struct definition *current_field;       /* Last field read */
+       struct bt_definition *enum_tag;
+       GPtrArray *fields;              /* Array of pointers to struct bt_definition */
+       struct bt_definition *current_field;    /* Last field read */
 };
 
 struct declaration_array {
-       struct declaration p;
+       struct bt_declaration p;
        size_t len;
-       struct declaration *elem;
+       struct bt_declaration *elem;
        struct declaration_scope *scope;
 };
 
 struct definition_array {
-       struct definition p;
+       struct bt_definition p;
        struct declaration_array *declaration;
-       GPtrArray *elems;               /* Array of pointers to struct definition */
+       GPtrArray *elems;               /* Array of pointers to struct bt_definition */
        GString *string;                /* String for encoded integer children */
 };
 
 struct declaration_sequence {
-       struct declaration p;
+       struct bt_declaration p;
        GArray *length_name;            /* Array of GQuark */
-       struct declaration *elem;
+       struct bt_declaration *elem;
        struct declaration_scope *scope;
 };
 
 struct definition_sequence {
-       struct definition p;
+       struct bt_definition p;
        struct declaration_sequence *declaration;
        struct definition_integer *length;
-       GPtrArray *elems;               /* Array of pointers to struct definition */
+       GPtrArray *elems;               /* Array of pointers to struct bt_definition */
        GString *string;                /* String for encoded integer children */
 };
 
-int register_declaration(GQuark declaration_name,
-                        struct declaration *declaration,
+int bt_register_declaration(GQuark declaration_name,
+                        struct bt_declaration *declaration,
                         struct declaration_scope *scope);
-struct declaration *lookup_declaration(GQuark declaration_name,
+struct bt_declaration *bt_lookup_declaration(GQuark declaration_name,
                                struct declaration_scope *scope);
 
 /*
@@ -317,76 +322,76 @@ struct declaration *lookup_declaration(GQuark declaration_name,
  * that a named variant can be declared without specifying its target
  * "choice" tag field immediately.
  */
-int register_struct_declaration(GQuark struct_name,
+int bt_register_struct_declaration(GQuark struct_name,
                                struct declaration_struct *struct_declaration,
                                struct declaration_scope *scope);
 struct declaration_struct *
-       lookup_struct_declaration(GQuark struct_name,
+       bt_lookup_struct_declaration(GQuark struct_name,
                                  struct declaration_scope *scope);
-int register_variant_declaration(GQuark variant_name,
+int bt_register_variant_declaration(GQuark variant_name,
                          struct declaration_untagged_variant *untagged_variant_declaration,
                          struct declaration_scope *scope);
-struct declaration_untagged_variant *lookup_variant_declaration(GQuark variant_name,
+struct declaration_untagged_variant *bt_lookup_variant_declaration(GQuark variant_name,
                                         struct declaration_scope *scope);
-int register_enum_declaration(GQuark enum_name,
+int bt_register_enum_declaration(GQuark enum_name,
                              struct declaration_enum *enum_declaration,
                              struct declaration_scope *scope);
 struct declaration_enum *
-       lookup_enum_declaration(GQuark enum_name,
+       bt_lookup_enum_declaration(GQuark enum_name,
                                struct declaration_scope *scope);
 
 struct declaration_scope *
-       new_declaration_scope(struct declaration_scope *parent_scope);
-void free_declaration_scope(struct declaration_scope *scope);
+       bt_new_declaration_scope(struct declaration_scope *parent_scope);
+void bt_free_declaration_scope(struct declaration_scope *scope);
 
 /*
  * field_definition is for field definitions. They are registered into
  * definition scopes.
  */
-struct definition *
-       lookup_path_definition(GArray *cur_path,        /* array of GQuark */
+struct bt_definition *
+       bt_lookup_path_definition(GArray *cur_path,     /* array of GQuark */
                               GArray *lookup_path,     /* array of GQuark */
                               struct definition_scope *scope);
-int register_field_definition(GQuark field_name,
-                             struct definition *definition,
+int bt_register_field_definition(GQuark field_name,
+                             struct bt_definition *definition,
                              struct definition_scope *scope);
 struct definition_scope *
-       new_definition_scope(struct definition_scope *parent_scope,
+       bt_new_definition_scope(struct definition_scope *parent_scope,
                             GQuark field_name, const char *root_name);
-void free_definition_scope(struct definition_scope *scope);
+void bt_free_definition_scope(struct definition_scope *scope);
 
-GQuark new_definition_path(struct definition_scope *parent_scope,
+GQuark bt_new_definition_path(struct definition_scope *parent_scope,
                           GQuark field_name, const char *root_name);
 
 static inline
-int compare_definition_path(struct definition *definition, GQuark path)
+int compare_definition_path(struct bt_definition *definition, GQuark path)
 {
        return definition->path == path;
 }
 
-void declaration_ref(struct declaration *declaration);
-void declaration_unref(struct declaration *declaration);
+void bt_declaration_ref(struct bt_declaration *declaration);
+void bt_declaration_unref(struct bt_declaration *declaration);
 
-void definition_ref(struct definition *definition);
-void definition_unref(struct definition *definition);
+void bt_definition_ref(struct bt_definition *definition);
+void bt_definition_unref(struct bt_definition *definition);
 
-struct declaration_integer *integer_declaration_new(size_t len, int byte_order,
+struct declaration_integer *bt_integer_declaration_new(size_t len, int byte_order,
                                  int signedness, size_t alignment,
                                  int base, enum ctf_string_encoding encoding,
                                  struct ctf_clock *clock);
-uint64_t get_unsigned_int(const struct definition *field);
-int64_t get_signed_int(const struct definition *field);
-int get_int_signedness(const struct definition *field);
-int get_int_byte_order(const struct definition *field);
-int get_int_base(const struct definition *field);
-size_t get_int_len(const struct definition *field);    /* in bits */
-enum ctf_string_encoding get_int_encoding(const struct definition *field);
+uint64_t bt_get_unsigned_int(const struct bt_definition *field);
+int64_t bt_get_signed_int(const struct bt_definition *field);
+int bt_get_int_signedness(const struct bt_definition *field);
+int bt_get_int_byte_order(const struct bt_definition *field);
+int bt_get_int_base(const struct bt_definition *field);
+size_t bt_get_int_len(const struct bt_definition *field);      /* in bits */
+enum ctf_string_encoding bt_get_int_encoding(const struct bt_definition *field);
 
 /*
  * mantissa_len is the length of the number of bytes represented by the mantissa
  * (e.g. result of DBL_MANT_DIG). It includes the leading 1.
  */
-struct declaration_float *float_declaration_new(size_t mantissa_len,
+struct declaration_float *bt_float_declaration_new(size_t mantissa_len,
                                  size_t exp_len, int byte_order,
                                  size_t alignment);
 
@@ -399,14 +404,14 @@ struct declaration_float *float_declaration_new(size_t mantissa_len,
  * Returns a GArray of GQuark or NULL.
  * Caller must release the GArray with g_array_unref().
  */
-GArray *enum_uint_to_quark_set(const struct declaration_enum *enum_declaration,
+GArray *bt_enum_uint_to_quark_set(const struct declaration_enum *enum_declaration,
                               uint64_t v);
 
 /*
  * Returns a GArray of GQuark or NULL.
  * Caller must release the GArray with g_array_unref().
  */
-GArray *enum_int_to_quark_set(const struct declaration_enum *enum_declaration,
+GArray *bt_enum_int_to_quark_set(const struct declaration_enum *enum_declaration,
                              int64_t v);
 
 /*
@@ -414,73 +419,73 @@ GArray *enum_int_to_quark_set(const struct declaration_enum *enum_declaration,
  * Callers do _not_ own the returned GArray (and therefore _don't_ need to
  * release it).
  */
-GArray *enum_quark_to_range_set(const struct declaration_enum *enum_declaration,
+GArray *bt_enum_quark_to_range_set(const struct declaration_enum *enum_declaration,
                                GQuark q);
-void enum_signed_insert(struct declaration_enum *enum_declaration,
+void bt_enum_signed_insert(struct declaration_enum *enum_declaration,
                         int64_t start, int64_t end, GQuark q);
-void enum_unsigned_insert(struct declaration_enum *enum_declaration,
+void bt_enum_unsigned_insert(struct declaration_enum *enum_declaration,
                          uint64_t start, uint64_t end, GQuark q);
-size_t enum_get_nr_enumerators(struct declaration_enum *enum_declaration);
+size_t bt_enum_get_nr_enumerators(struct declaration_enum *enum_declaration);
 
 struct declaration_enum *
-       enum_declaration_new(struct declaration_integer *integer_declaration);
+       bt_enum_declaration_new(struct declaration_integer *integer_declaration);
 
 struct declaration_string *
-       string_declaration_new(enum ctf_string_encoding encoding);
-char *get_string(const struct definition *field);
-enum ctf_string_encoding get_string_encoding(const struct definition *field);
+       bt_string_declaration_new(enum ctf_string_encoding encoding);
+char *bt_get_string(const struct bt_definition *field);
+enum ctf_string_encoding bt_get_string_encoding(const struct bt_definition *field);
 
 struct declaration_struct *
-       struct_declaration_new(struct declaration_scope *parent_scope,
+       bt_struct_declaration_new(struct declaration_scope *parent_scope,
                               uint64_t min_align);
-void struct_declaration_add_field(struct declaration_struct *struct_declaration,
+void bt_struct_declaration_add_field(struct declaration_struct *struct_declaration,
                                  const char *field_name,
-                                 struct declaration *field_declaration);
+                                 struct bt_declaration *field_declaration);
 /*
  * Returns the index of a field within a structure.
  */
-int struct_declaration_lookup_field_index(struct declaration_struct *struct_declaration,
+int bt_struct_declaration_lookup_field_index(struct declaration_struct *struct_declaration,
                                                    GQuark field_name);
 /*
  * field returned only valid as long as the field structure is not appended to.
  */
 struct declaration_field *
-struct_declaration_get_field_from_index(struct declaration_struct *struct_declaration,
+bt_struct_declaration_get_field_from_index(struct declaration_struct *struct_declaration,
                                        int index);
-struct definition *
-struct_definition_get_field_from_index(struct definition_struct *struct_definition,
+struct bt_definition *
+bt_struct_definition_get_field_from_index(struct definition_struct *struct_definition,
                                       int index);
-int struct_rw(struct stream_pos *pos, struct definition *definition);
-uint64_t struct_declaration_len(struct declaration_struct *struct_declaration);
+int bt_struct_rw(struct bt_stream_pos *pos, struct bt_definition *definition);
+uint64_t bt_struct_declaration_len(struct declaration_struct *struct_declaration);
 
 /*
  * The tag enumeration is validated to ensure that it contains only mappings
  * from numeric values to a single tag. Overlapping tag value ranges are
  * therefore forbidden.
  */
-struct declaration_untagged_variant *untagged_variant_declaration_new(
+struct declaration_untagged_variant *bt_untagged_bt_variant_declaration_new(
                struct declaration_scope *parent_scope);
-struct declaration_variant *variant_declaration_new(struct declaration_untagged_variant *untagged_variant,
+struct declaration_variant *bt_variant_declaration_new(struct declaration_untagged_variant *untagged_variant,
                const char *tag);
 
-void untagged_variant_declaration_add_field(struct declaration_untagged_variant *untagged_variant_declaration,
+void bt_untagged_variant_declaration_add_field(struct declaration_untagged_variant *untagged_variant_declaration,
                const char *field_name,
-               struct declaration *field_declaration);
+               struct bt_declaration *field_declaration);
 struct declaration_field *
-       untagged_variant_declaration_get_field_from_tag(struct declaration_untagged_variant *untagged_variant_declaration,
+       bt_untagged_variant_declaration_get_field_from_tag(struct declaration_untagged_variant *untagged_variant_declaration,
                GQuark tag);
 /*
  * Returns 0 on success, -EPERM on error.
  */
 int variant_definition_set_tag(struct definition_variant *variant,
-                              struct definition *enum_tag);
+                              struct bt_definition *enum_tag);
 /*
  * Returns the field selected by the current tag value.
  * field returned only valid as long as the variant structure is not appended
  * to.
  */
-struct definition *variant_get_current_field(struct definition_variant *variant);
-int variant_rw(struct stream_pos *pos, struct definition *definition);
+struct bt_definition *bt_variant_get_current_field(struct definition_variant *variant);
+int bt_variant_rw(struct bt_stream_pos *pos, struct bt_definition *definition);
 
 /*
  * elem_declaration passed as parameter now belongs to the array. No
@@ -488,43 +493,43 @@ int variant_rw(struct stream_pos *pos, struct definition *definition);
  * array.
  */
 struct declaration_array *
-       array_declaration_new(size_t len, struct declaration *elem_declaration,
+       bt_array_declaration_new(size_t len, struct bt_declaration *elem_declaration,
                struct declaration_scope *parent_scope);
-uint64_t array_len(struct definition_array *array);
-struct definition *array_index(struct definition_array *array, uint64_t i);
-int array_rw(struct stream_pos *pos, struct definition *definition);
-GString *get_char_array(const struct definition *field);
-int get_array_len(const struct definition *field);
+uint64_t bt_array_len(struct definition_array *array);
+struct bt_definition *bt_array_index(struct definition_array *array, uint64_t i);
+int bt_array_rw(struct bt_stream_pos *pos, struct bt_definition *definition);
+GString *bt_get_char_array(const struct bt_definition *field);
+int bt_get_array_len(const struct bt_definition *field);
 
 /*
  * int_declaration and elem_declaration passed as parameter now belong
  * to the sequence. No need to free them explicitly.
  */
 struct declaration_sequence *
-       sequence_declaration_new(const char *length_name,
-               struct declaration *elem_declaration,
+       bt_sequence_declaration_new(const char *length_name,
+               struct bt_declaration *elem_declaration,
                struct declaration_scope *parent_scope);
-uint64_t sequence_len(struct definition_sequence *sequence);
-struct definition *sequence_index(struct definition_sequence *sequence, uint64_t i);
-int sequence_rw(struct stream_pos *pos, struct definition *definition);
+uint64_t bt_sequence_len(struct definition_sequence *sequence);
+struct bt_definition *bt_sequence_index(struct definition_sequence *sequence, uint64_t i);
+int bt_sequence_rw(struct bt_stream_pos *pos, struct bt_definition *definition);
 
 /*
  * in: path (dot separated), out: q (GArray of GQuark)
  */
-void append_scope_path(const char *path, GArray *q);
+void bt_append_scope_path(const char *path, GArray *q);
 
 /*
  * Lookup helpers.
  */
-struct definition *lookup_definition(const struct definition *definition,
+struct bt_definition *bt_lookup_definition(const struct bt_definition *definition,
                                     const char *field_name);
-struct definition_integer *lookup_integer(const struct definition *definition,
+struct definition_integer *bt_lookup_integer(const struct bt_definition *definition,
                                          const char *field_name,
                                          int signedness);
-struct definition_enum *lookup_enum(const struct definition *definition,
+struct definition_enum *bt_lookup_enum(const struct bt_definition *definition,
                                    const char *field_name,
                                    int signedness);
-struct definition *lookup_variant(const struct definition *definition,
+struct bt_definition *bt_lookup_variant(const struct bt_definition *definition,
                                  const char *field_name);
 
 static inline
diff --git a/include/babeltrace/uuid.h b/include/babeltrace/uuid.h
deleted file mode 100644 (file)
index 2ce7467..0000000
+++ /dev/null
@@ -1,129 +0,0 @@
-#ifndef _BABELTRACE_UUID_H
-#define _BABELTRACE_UUID_H
-
-/*
- * babeltrace/uuid.h
- *
- * Copyright (C) 2011   Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-
-#include <config.h>
-
-/* Includes final \0. */
-#define BABELTRACE_UUID_STR_LEN                37
-#define BABELTRACE_UUID_LEN            16
-
-#ifdef BABELTRACE_HAVE_LIBUUID
-#include <uuid/uuid.h>
-
-static inline
-int babeltrace_uuid_generate(unsigned char *uuid_out)
-{
-       uuid_generate(uuid_out);
-       return 0;
-}
-
-static inline
-int babeltrace_uuid_unparse(const unsigned char *uuid_in, char *str_out)
-{
-       uuid_unparse(uuid_in, str_out);
-       return 0;
-}
-
-static inline
-int babeltrace_uuid_parse(const char *str_in, unsigned char *uuid_out)
-{
-       return uuid_parse(str_in, uuid_out);
-}
-
-static inline
-int babeltrace_uuid_compare(const unsigned char *uuid_a,
-               const unsigned char *uuid_b)
-{
-       return uuid_compare(uuid_a, uuid_b);
-}
-
-#elif defined(BABELTRACE_HAVE_LIBC_UUID)
-#include <uuid.h>
-#include <stdint.h>
-#include <string.h>
-#include <stdlib.h>
-
-static inline
-int babeltrace_uuid_generate(unsigned char *uuid_out)
-{
-       uint32_t status;
-
-       uuid_create((uuid_t *) uuid_out, &status);
-       if (status == uuid_s_ok)
-               return 0;
-       else
-               return -1;
-}
-
-static inline
-int babeltrace_uuid_unparse(const unsigned char *uuid_in, char *str_out)
-{
-       uint32_t status;
-       char *alloc_str;
-       int ret;
-
-       uuid_to_string((uuid_t *) uuid_in, &alloc_str, &status);
-       if (status == uuid_s_ok) {
-               strcpy(str_out, alloc_str);
-               ret = 0;
-       } else {
-               ret = -1;
-       }
-       free(alloc_str);
-       return ret;
-}
-
-static inline
-int babeltrace_uuid_parse(const char *str_in, unsigned char *uuid_out)
-{
-       uint32_t status;
-
-       uuid_from_string(str_in, (uuid_t *) uuid_out, &status);
-       if (status == uuid_s_ok)
-               return 0;
-       else
-               return -1;
-}
-
-static inline
-int babeltrace_uuid_compare(const unsigned char *uuid_a,
-               const unsigned char *uuid_b)
-{
-       uint32_t status;
-
-       uuid_compare((uuid_t *) uuid_a, (uuid_t *) uuid_b, &status);
-       if (status == uuid_s_ok)
-               return 0;
-       else
-               return -1;
-}
-
-#else
-#error "Babeltrace needs to have a UUID generator configured."
-#endif
-
-#endif /* _BABELTRACE_UUID_H */
index 5516e494f2bbb74c68be2a7924e2fa091935cf3e..dc7736689170e10da3ba1164f543c79e334fdbe3 100644 (file)
@@ -60,20 +60,20 @@ struct bt_context *bt_context_create(void)
 
        ctx->current_iterator = NULL;
        ctx->tc = g_new0(struct trace_collection, 1);
-       init_trace_collection(ctx->tc);
+       bt_init_trace_collection(ctx->tc);
 
        return ctx;
 }
 
 int bt_context_add_trace(struct bt_context *ctx, const char *path,
                const char *format_name,
-               void (*packet_seek)(struct stream_pos *pos, size_t index,
+               void (*packet_seek)(struct bt_stream_pos *pos, size_t index,
                        int whence),
-               struct mmap_stream_list *stream_list,
+               struct bt_mmap_stream_list *stream_list,
                FILE *metadata)
 {
-       struct trace_descriptor *td;
-       struct format *fmt;
+       struct bt_trace_descriptor *td;
+       struct bt_format *fmt;
        struct bt_trace_handle *handle;
        int ret, closeret;
 
@@ -90,7 +90,7 @@ int bt_context_add_trace(struct bt_context *ctx, const char *path,
        if (path) {
                td = fmt->open_trace(path, O_RDONLY, packet_seek, NULL);
                if (!td) {
-                       fprintf(stderr, "[warning] [Context] Cannot open_trace of format %s at path %s.\n\n",
+                       fprintf(stderr, "[warning] [Context] Cannot open_trace of format %s at path %s.\n",
                                        format_name, path);
                        ret = -1;
                        goto end;
@@ -107,7 +107,7 @@ int bt_context_add_trace(struct bt_context *ctx, const char *path,
 
        /* Create an handle for the trace */
        handle = bt_trace_handle_create(ctx);
-       if (handle < 0) {
+       if (!handle) {
                fprintf(stderr, "[error] [Context] Creating trace handle %s .\n\n",
                                path);
                ret = -1;
@@ -129,7 +129,7 @@ int bt_context_add_trace(struct bt_context *ctx, const char *path,
        g_hash_table_insert(ctx->trace_handles,
                (gpointer) (unsigned long) handle->id,
                handle);
-       ret = trace_collection_add(ctx->tc, td);
+       ret = bt_trace_collection_add(ctx->tc, td);
        if (ret != 0)
                goto error;
 
@@ -167,7 +167,7 @@ int bt_context_remove_trace(struct bt_context *ctx, int handle_id)
                return -ENOENT;
 
        /* Remove from containers */
-       trace_collection_remove(ctx->tc, handle->td);
+       bt_trace_collection_remove(ctx->tc, handle->td);
        /* Close the trace */
        ret = handle->format->close_trace(handle->td);
        if (ret) {
@@ -184,7 +184,7 @@ static
 void bt_context_destroy(struct bt_context *ctx)
 {
        assert(ctx);
-       finalize_trace_collection(ctx->tc);
+       bt_finalize_trace_collection(ctx->tc);
 
        /*
         * Remove all traces. The g_hash_table_destroy will call
index 41a46020f6c690b4cc253044d845c0919e34cf0f..009fcd3fecf0b502e19a4719225d470fd4719c7d 100644 (file)
@@ -73,16 +73,24 @@ static int stream_read_event(struct ctf_file_stream *sin)
 }
 
 /*
- * returns true if a < b, false otherwise.
+ * Return true if a < b, false otherwise.
+ * If time stamps are exactly the same, compare by stream path. This
+ * ensures we get the same result between runs on the same trace
+ * collection on different environments.
+ * The result will be random for memory-mapped traces since there is no
+ * fixed path leading to those (they have empty path string).
  */
 static int stream_compare(void *a, void *b)
 {
        struct ctf_file_stream *s_a = a, *s_b = b;
 
-       if (s_a->parent.real_timestamp < s_b->parent.real_timestamp)
+       if (s_a->parent.real_timestamp < s_b->parent.real_timestamp) {
                return 1;
-       else
+       } else if (likely(s_a->parent.real_timestamp > s_b->parent.real_timestamp)) {
                return 0;
+       } else {
+               return strcmp(s_a->parent.path, s_b->parent.path);
+       }
 }
 
 void bt_iter_free_pos(struct bt_iter_pos *iter_pos)
@@ -180,7 +188,7 @@ static int seek_ctf_trace_by_timestamp(struct ctf_trace *tin,
                        ret = seek_file_stream_by_timestamp(cfs, timestamp);
                        if (ret == 0) {
                                /* Add to heap */
-                               ret = heap_insert(stream_heap, cfs);
+                               ret = bt_heap_insert(stream_heap, cfs);
                                if (ret) {
                                        /* Return positive error. */
                                        return -ret;
@@ -309,7 +317,7 @@ static int seek_last_ctf_trace_collection(struct trace_collection *tc,
        /* For each trace in the trace_collection */
        for (i = 0; i < tc->array->len; i++) {
                struct ctf_trace *tin;
-               struct trace_descriptor *td_read;
+               struct bt_trace_descriptor *td_read;
 
                td_read = g_ptr_array_index(tc->array, i);
                if (!td_read)
@@ -358,8 +366,8 @@ int bt_iter_set_pos(struct bt_iter *iter, const struct bt_iter_pos *iter_pos)
                if (!iter_pos->u.restore)
                        return -EINVAL;
 
-               heap_free(iter->stream_heap);
-               ret = heap_init(iter->stream_heap, 0, stream_compare);
+               bt_heap_free(iter->stream_heap);
+               ret = bt_heap_init(iter->stream_heap, 0, stream_compare);
                if (ret < 0)
                        goto error_heap_init;
 
@@ -404,7 +412,7 @@ int bt_iter_set_pos(struct bt_iter *iter, const struct bt_iter_pos *iter_pos)
                        }
 
                        /* Add to heap */
-                       ret = heap_insert(iter->stream_heap,
+                       ret = bt_heap_insert(iter->stream_heap,
                                        saved_pos->file_stream);
                        if (ret)
                                goto error;
@@ -413,15 +421,15 @@ int bt_iter_set_pos(struct bt_iter *iter, const struct bt_iter_pos *iter_pos)
        case BT_SEEK_TIME:
                tc = iter->ctx->tc;
 
-               heap_free(iter->stream_heap);
-               ret = heap_init(iter->stream_heap, 0, stream_compare);
+               bt_heap_free(iter->stream_heap);
+               ret = bt_heap_init(iter->stream_heap, 0, stream_compare);
                if (ret < 0)
                        goto error_heap_init;
 
                /* for each trace in the trace_collection */
                for (i = 0; i < tc->array->len; i++) {
                        struct ctf_trace *tin;
-                       struct trace_descriptor *td_read;
+                       struct bt_trace_descriptor *td_read;
 
                        td_read = g_ptr_array_index(tc->array, i);
                        if (!td_read)
@@ -444,14 +452,14 @@ int bt_iter_set_pos(struct bt_iter *iter, const struct bt_iter_pos *iter_pos)
                return 0;
        case BT_SEEK_BEGIN:
                tc = iter->ctx->tc;
-               heap_free(iter->stream_heap);
-               ret = heap_init(iter->stream_heap, 0, stream_compare);
+               bt_heap_free(iter->stream_heap);
+               ret = bt_heap_init(iter->stream_heap, 0, stream_compare);
                if (ret < 0)
                        goto error_heap_init;
 
                for (i = 0; i < tc->array->len; i++) {
                        struct ctf_trace *tin;
-                       struct trace_descriptor *td_read;
+                       struct bt_trace_descriptor *td_read;
                        int stream_id;
 
                        td_read = g_ptr_array_index(tc->array, i);
@@ -487,7 +495,7 @@ int bt_iter_set_pos(struct bt_iter *iter, const struct bt_iter_pos *iter_pos)
                                                /* Do not add EOF streams */
                                                continue;
                                        }
-                                       ret = heap_insert(iter->stream_heap, file_stream);
+                                       ret = bt_heap_insert(iter->stream_heap, file_stream);
                                        if (ret)
                                                goto error;
                                }
@@ -503,13 +511,13 @@ int bt_iter_set_pos(struct bt_iter *iter, const struct bt_iter_pos *iter_pos)
                if (ret != 0 || !cfs)
                        goto error;
                /* remove all streams from the heap */
-               heap_free(iter->stream_heap);
+               bt_heap_free(iter->stream_heap);
                /* Create a new empty heap */
-               ret = heap_init(iter->stream_heap, 0, stream_compare);
+               ret = bt_heap_init(iter->stream_heap, 0, stream_compare);
                if (ret < 0)
                        goto error;
                /* Insert the stream that contains the last event */
-               ret = heap_insert(iter->stream_heap, cfs);
+               ret = bt_heap_insert(iter->stream_heap, cfs);
                if (ret)
                        goto error;
                break;
@@ -522,10 +530,10 @@ int bt_iter_set_pos(struct bt_iter *iter, const struct bt_iter_pos *iter_pos)
        return 0;
 
 error:
-       heap_free(iter->stream_heap);
+       bt_heap_free(iter->stream_heap);
 error_heap_init:
-       if (heap_init(iter->stream_heap, 0, stream_compare) < 0) {
-               heap_free(iter->stream_heap);
+       if (bt_heap_init(iter->stream_heap, 0, stream_compare) < 0) {
+               bt_heap_free(iter->stream_heap);
                g_free(iter->stream_heap);
                iter->stream_heap = NULL;
                ret = -ENOMEM;
@@ -555,12 +563,12 @@ struct bt_iter_pos *bt_iter_get_pos(struct bt_iter *iter)
        if (!pos->u.restore->stream_saved_pos)
                goto error;
 
-       ret = heap_copy(&iter_heap_copy, iter->stream_heap);
+       ret = bt_heap_copy(&iter_heap_copy, iter->stream_heap);
        if (ret < 0)
                goto error_heap;
 
        /* iterate over each stream in the heap */
-       file_stream = heap_maximum(&iter_heap_copy);
+       file_stream = bt_heap_maximum(&iter_heap_copy);
        while (file_stream != NULL) {
                struct stream_saved_pos saved_pos;
 
@@ -584,12 +592,12 @@ struct bt_iter_pos *bt_iter_get_pos(struct bt_iter *iter)
                                saved_pos.current_real_timestamp);
 
                /* remove the stream from the heap copy */
-               removed = heap_remove(&iter_heap_copy);
+               removed = bt_heap_remove(&iter_heap_copy);
                assert(removed == file_stream);
 
-               file_stream = heap_maximum(&iter_heap_copy);
+               file_stream = bt_heap_maximum(&iter_heap_copy);
        }
-       heap_free(&iter_heap_copy);
+       bt_heap_free(&iter_heap_copy);
        return pos;
 
 error_heap:
@@ -669,13 +677,13 @@ int bt_iter_init(struct bt_iter *iter,
        bt_context_get(ctx);
        iter->ctx = ctx;
 
-       ret = heap_init(iter->stream_heap, 0, stream_compare);
+       ret = bt_heap_init(iter->stream_heap, 0, stream_compare);
        if (ret < 0)
                goto error_heap_init;
 
        for (i = 0; i < ctx->tc->array->len; i++) {
                struct ctf_trace *tin;
-               struct trace_descriptor *td_read;
+               struct bt_trace_descriptor *td_read;
 
                td_read = g_ptr_array_index(ctx->tc->array, i);
                if (!td_read)
@@ -718,7 +726,7 @@ int bt_iter_init(struct bt_iter *iter,
                                        goto error;
                                }
                                /* Add to heap */
-                               ret = heap_insert(iter->stream_heap, file_stream);
+                               ret = bt_heap_insert(iter->stream_heap, file_stream);
                                if (ret)
                                        goto error;
                        }
@@ -729,7 +737,7 @@ int bt_iter_init(struct bt_iter *iter,
        return 0;
 
 error:
-       heap_free(iter->stream_heap);
+       bt_heap_free(iter->stream_heap);
 error_heap_init:
        g_free(iter->stream_heap);
        iter->stream_heap = NULL;
@@ -760,7 +768,7 @@ void bt_iter_fini(struct bt_iter *iter)
 {
        assert(iter);
        if (iter->stream_heap) {
-               heap_free(iter->stream_heap);
+               bt_heap_free(iter->stream_heap);
                g_free(iter->stream_heap);
        }
        iter->ctx->current_iterator = NULL;
@@ -782,7 +790,7 @@ int bt_iter_next(struct bt_iter *iter)
        if (!iter)
                return -EINVAL;
 
-       file_stream = heap_maximum(iter->stream_heap);
+       file_stream = bt_heap_maximum(iter->stream_heap);
        if (!file_stream) {
                /* end of file for all streams */
                ret = 0;
@@ -791,7 +799,7 @@ int bt_iter_next(struct bt_iter *iter)
 
        ret = stream_read_event(file_stream);
        if (ret == EOF) {
-               removed = heap_remove(iter->stream_heap);
+               removed = bt_heap_remove(iter->stream_heap);
                assert(removed == file_stream);
                ret = 0;
                goto end;
@@ -799,7 +807,7 @@ int bt_iter_next(struct bt_iter *iter)
                goto end;
        }
        /* Reinsert the file stream into the heap, and rebalance. */
-       removed = heap_replace_max(iter->stream_heap, file_stream);
+       removed = bt_heap_replace_max(iter->stream_heap, file_stream);
        assert(removed == file_stream);
 
 end:
index 43b4e8a4d509bbda62e2f696d9b8327ae6bf003c..8942a113aec50038fe20f59c6bbf84756a2d780d 100644 (file)
@@ -102,7 +102,7 @@ int heap_set_len(struct ptr_heap *heap, size_t new_len)
        return 0;
 }
 
-int heap_init(struct ptr_heap *heap, size_t alloc_len,
+int bt_heap_init(struct ptr_heap *heap, size_t alloc_len,
              int gt(void *a, void *b))
 {
        heap->ptrs = NULL;
@@ -111,12 +111,12 @@ int heap_init(struct ptr_heap *heap, size_t alloc_len,
        heap->gt = gt;
        /*
         * Minimum size allocated is 1 entry to ensure memory allocation
-        * never fails within heap_replace_max.
+        * never fails within bt_heap_replace_max.
         */
        return heap_grow(heap, max_t(size_t, 1, alloc_len));
 }
 
-void heap_free(struct ptr_heap *heap)
+void bt_heap_free(struct ptr_heap *heap)
 {
        free(heap->ptrs);
 }
@@ -147,7 +147,7 @@ static void heapify(struct ptr_heap *heap, size_t i)
        check_heap(heap);
 }
 
-void *heap_replace_max(struct ptr_heap *heap, void *p)
+void *bt_heap_replace_max(struct ptr_heap *heap, void *p)
 {
        void *res;
 
@@ -165,7 +165,7 @@ void *heap_replace_max(struct ptr_heap *heap, void *p)
        return res;
 }
 
-int heap_insert(struct ptr_heap *heap, void *p)
+int bt_heap_insert(struct ptr_heap *heap, void *p)
 {
        void **ptrs;
        size_t pos;
@@ -186,7 +186,7 @@ int heap_insert(struct ptr_heap *heap, void *p)
        return 0;
 }
 
-void *heap_remove(struct ptr_heap *heap)
+void *bt_heap_remove(struct ptr_heap *heap)
 {
        switch (heap->len) {
        case 0:
@@ -198,10 +198,10 @@ void *heap_remove(struct ptr_heap *heap)
        /* Shrink, replace the current max by previous last entry and heapify */
        heap_set_len(heap, heap->len - 1);
        /* len changed. previous last entry is at heap->len */
-       return heap_replace_max(heap, heap->ptrs[heap->len]);
+       return bt_heap_replace_max(heap, heap->ptrs[heap->len]);
 }
 
-void *heap_cherrypick(struct ptr_heap *heap, void *p)
+void *bt_heap_cherrypick(struct ptr_heap *heap, void *p)
 {
        size_t pos, len = heap->len;
 
@@ -223,11 +223,11 @@ found:
        return p;
 }
 
-int heap_copy(struct ptr_heap *dst, struct ptr_heap *src)
+int bt_heap_copy(struct ptr_heap *dst, struct ptr_heap *src)
 {
        int ret;
 
-       ret = heap_init(dst, src->alloc_len, src->gt);
+       ret = bt_heap_init(dst, src->alloc_len, src->gt);
        if (ret < 0)
                goto end;
 
index 28af184f8c5da58c7122637a0353a09cc13b5453..bdce0c6d01e9cf306753791f44a588ed5cbe15a8 100644 (file)
@@ -67,7 +67,7 @@ void format_refcount_dec(void)
                format_cleanup();
 }
 
-struct format *bt_lookup_format(bt_intern_str name)
+struct bt_format *bt_lookup_format(bt_intern_str name)
 {
        if (!init_done)
                return NULL;
@@ -103,7 +103,7 @@ void bt_fprintf_format_list(FILE *fp)
        fprintf(fp, ".\n");
 }
 
-int bt_register_format(struct format *format)
+int bt_register_format(struct bt_format *format)
 {
        if (!format)
                return -EINVAL;
@@ -121,7 +121,7 @@ int bt_register_format(struct format *format)
        return 0;
 }
 
-void bt_unregister_format(struct format *format)
+void bt_unregister_format(struct bt_format *format)
 {
        assert(bt_lookup_format(format->name));
        g_hash_table_remove(format_registry,
index 4f1379c5a43d73cb4e0bcae9053339bf533f7802..b854c97440422b009ce12111d54f136f94431515 100644 (file)
@@ -155,18 +155,12 @@ static void clock_add(gpointer key, gpointer value, gpointer user_data)
  * correlate this trace with at least one other clock in the trace and
  * convert the index from cycles to real time.
  */
-int trace_collection_add(struct trace_collection *tc,
-                               struct trace_descriptor *td)
+int bt_trace_collection_add(struct trace_collection *tc,
+                       struct bt_trace_descriptor *trace)
 {
-       struct ctf_trace *trace;
-
-       if (!tc || !td)
+       if (!tc || !trace)
                return -EINVAL;
 
-       trace = container_of(td, struct ctf_trace, parent);
-       g_ptr_array_add(tc->array, td);
-       trace->collection = tc;
-
        if (tc->array->len > 1) {
                struct clock_match clock_match = {
                        .clocks = tc->clocks,
@@ -187,6 +181,9 @@ int trace_collection_add(struct trace_collection *tc,
                }
        }
 
+       g_ptr_array_add(tc->array, trace);
+       trace->collection = tc;
+
        {
                struct clock_match clock_match = {
                        .clocks = tc->clocks,
@@ -208,8 +205,8 @@ error:
        return -EPERM;
 }
 
-int trace_collection_remove(struct trace_collection *tc,
-                           struct trace_descriptor *td)
+int bt_trace_collection_remove(struct trace_collection *tc,
+                           struct bt_trace_descriptor *td)
 {
        if (!tc || !td)
                return -EINVAL;
@@ -222,7 +219,7 @@ int trace_collection_remove(struct trace_collection *tc,
 
 }
 
-void init_trace_collection(struct trace_collection *tc)
+void bt_init_trace_collection(struct trace_collection *tc)
 {
        assert(tc);
        tc->array = g_ptr_array_new();
@@ -234,10 +231,10 @@ void init_trace_collection(struct trace_collection *tc)
 }
 
 /*
- * finalize_trace_collection() closes the opened traces for read
+ * bt_finalize_trace_collection() closes the opened traces for read
  * and free the memory allocated for trace collection
  */
-void finalize_trace_collection(struct trace_collection *tc)
+void bt_finalize_trace_collection(struct trace_collection *tc)
 {
        assert(tc);
        g_ptr_array_free(tc->array, TRUE);
index 455e4407e37722be78f18ed5311cf0af7c7b5430..d5b906aa961f5639b51f9a7c9114a19c28f58f3a 100644 (file)
@@ -52,14 +52,6 @@ void bt_trace_handle_destroy(struct bt_trace_handle *th)
        g_free(th);
 }
 
-int bt_trace_handle_get_id(struct bt_trace_handle *th)
-{
-       if (!th)
-               return -1;
-
-       return th->id;
-}
-
 const char *bt_trace_handle_get_path(struct bt_context *ctx, int handle_id)
 {
        struct bt_trace_handle *handle;
index 47891e90af0945d3accf10f7d3cd0fe1351af031..816fa6600c82dac5e6bcd5340fd5c5e2914a7e19 100644 (file)
@@ -2,10 +2,6 @@ AM_CFLAGS = $(PACKAGE_CFLAGS) -I$(top_srcdir)/include
 
 SUBDIRS = lib
 
-noinst_PROGRAMS = test-bitfield
-
-test_bitfield_SOURCES = test-bitfield.c
-
 EXTRA_DIST = runall.sh ctf-traces/**
 
 check-am:
diff --git a/tests/ctf-traces/fail/fail2/metadata b/tests/ctf-traces/fail/fail2/metadata
new file mode 100644 (file)
index 0000000..456661e
Binary files /dev/null and b/tests/ctf-traces/fail/fail2/metadata differ
diff --git a/tests/ctf-traces/fail/integer-range/metadata b/tests/ctf-traces/fail/integer-range/metadata
new file mode 100644 (file)
index 0000000..3574940
--- /dev/null
@@ -0,0 +1,27 @@
+/* CTF 1.8 */
+typealias integer { size = 8; align = 8; signed = false; } := uint8_t;
+typealias integer { size = 32; align = 32; signed = false; } := uint32_t;
+
+trace {
+       /* Integer out of range */
+       major = 23452397856348975623897562893746589237465289374658923764598237645897234658723648579236;
+       minor = 1;
+       uuid = "2a6422d0-6cee-11e0-8c08-cb07d7b3a564";
+       byte_order = le;
+       packet.header := struct {
+               uint32_t magic;
+               uint8_t  uuid[16];
+       };
+};
+
+stream {
+       packet.context := struct {
+               uint32_t content_size;
+               uint32_t packet_size;
+       };
+};
+
+event {
+       name = string;
+       fields := struct { string str; };
+};
diff --git a/tests/ctf-traces/fail/lttng-modules-2.0-pre1/channel0_0 b/tests/ctf-traces/fail/lttng-modules-2.0-pre1/channel0_0
deleted file mode 100755 (executable)
index 1e78788..0000000
Binary files a/tests/ctf-traces/fail/lttng-modules-2.0-pre1/channel0_0 and /dev/null differ
diff --git a/tests/ctf-traces/fail/lttng-modules-2.0-pre1/channel0_1 b/tests/ctf-traces/fail/lttng-modules-2.0-pre1/channel0_1
deleted file mode 100755 (executable)
index 304b0f2..0000000
Binary files a/tests/ctf-traces/fail/lttng-modules-2.0-pre1/channel0_1 and /dev/null differ
diff --git a/tests/ctf-traces/fail/lttng-modules-2.0-pre1/channel0_2 b/tests/ctf-traces/fail/lttng-modules-2.0-pre1/channel0_2
deleted file mode 100755 (executable)
index abec4c0..0000000
Binary files a/tests/ctf-traces/fail/lttng-modules-2.0-pre1/channel0_2 and /dev/null differ
diff --git a/tests/ctf-traces/fail/lttng-modules-2.0-pre1/channel0_3 b/tests/ctf-traces/fail/lttng-modules-2.0-pre1/channel0_3
deleted file mode 100755 (executable)
index 1c05e1b..0000000
Binary files a/tests/ctf-traces/fail/lttng-modules-2.0-pre1/channel0_3 and /dev/null differ
diff --git a/tests/ctf-traces/fail/lttng-modules-2.0-pre1/channel0_4 b/tests/ctf-traces/fail/lttng-modules-2.0-pre1/channel0_4
deleted file mode 100755 (executable)
index 3f13678..0000000
Binary files a/tests/ctf-traces/fail/lttng-modules-2.0-pre1/channel0_4 and /dev/null differ
diff --git a/tests/ctf-traces/fail/lttng-modules-2.0-pre1/channel0_5 b/tests/ctf-traces/fail/lttng-modules-2.0-pre1/channel0_5
deleted file mode 100755 (executable)
index 90abeed..0000000
Binary files a/tests/ctf-traces/fail/lttng-modules-2.0-pre1/channel0_5 and /dev/null differ
diff --git a/tests/ctf-traces/fail/lttng-modules-2.0-pre1/channel0_6 b/tests/ctf-traces/fail/lttng-modules-2.0-pre1/channel0_6
deleted file mode 100755 (executable)
index 78854da..0000000
Binary files a/tests/ctf-traces/fail/lttng-modules-2.0-pre1/channel0_6 and /dev/null differ
diff --git a/tests/ctf-traces/fail/lttng-modules-2.0-pre1/channel0_7 b/tests/ctf-traces/fail/lttng-modules-2.0-pre1/channel0_7
deleted file mode 100755 (executable)
index cbdd0cd..0000000
Binary files a/tests/ctf-traces/fail/lttng-modules-2.0-pre1/channel0_7 and /dev/null differ
diff --git a/tests/ctf-traces/fail/packet-based-metadata/datastream b/tests/ctf-traces/fail/packet-based-metadata/datastream
deleted file mode 100644 (file)
index 13bff2e..0000000
Binary files a/tests/ctf-traces/fail/packet-based-metadata/datastream and /dev/null differ
diff --git a/tests/ctf-traces/fail/smalltrace/dummystream-fail b/tests/ctf-traces/fail/smalltrace/dummystream-fail
new file mode 100644 (file)
index 0000000..fc7e07c
--- /dev/null
@@ -0,0 +1 @@
\1füÁ*d
\ No newline at end of file
diff --git a/tests/ctf-traces/fail/smalltrace/metadata b/tests/ctf-traces/fail/smalltrace/metadata
new file mode 100644 (file)
index 0000000..86f8e0a
--- /dev/null
@@ -0,0 +1,19 @@
+/* CTF 1.8 */
+typealias integer { size = 8; align = 8; signed = false; base = 10; } := uint8_t;
+typealias integer { size = 32; align = 32; signed = false; base = hex; } := uint32_t;
+
+trace {
+       major = 0;
+       minor = 1;
+       uuid = "2a6422d0-6cee-11e0-8c08-cb07d7b3a564";
+       byte_order = le;
+       packet.header := struct {
+               uint32_t magic;
+               uint8_t  uuid[16];
+       };
+};
+
+event {
+       name = string;
+       fields := struct { string str; };
+};
diff --git a/tests/ctf-traces/succeed/smalltrace/dummystream b/tests/ctf-traces/succeed/smalltrace/dummystream
new file mode 100644 (file)
index 0000000..469cb9a
Binary files /dev/null and b/tests/ctf-traces/succeed/smalltrace/dummystream differ
diff --git a/tests/ctf-traces/succeed/smalltrace/metadata b/tests/ctf-traces/succeed/smalltrace/metadata
new file mode 100644 (file)
index 0000000..86f8e0a
--- /dev/null
@@ -0,0 +1,19 @@
+/* CTF 1.8 */
+typealias integer { size = 8; align = 8; signed = false; base = 10; } := uint8_t;
+typealias integer { size = 32; align = 32; signed = false; base = hex; } := uint32_t;
+
+trace {
+       major = 0;
+       minor = 1;
+       uuid = "2a6422d0-6cee-11e0-8c08-cb07d7b3a564";
+       byte_order = le;
+       packet.header := struct {
+               uint32_t magic;
+               uint8_t  uuid[16];
+       };
+};
+
+event {
+       name = string;
+       fields := struct { string str; };
+};
diff --git a/tests/ctf-traces/succeed/succeed3/dummystream b/tests/ctf-traces/succeed/succeed3/dummystream
new file mode 100644 (file)
index 0000000..53d735e
Binary files /dev/null and b/tests/ctf-traces/succeed/succeed3/dummystream differ
diff --git a/tests/ctf-traces/succeed/succeed3/metadata b/tests/ctf-traces/succeed/succeed3/metadata
new file mode 100644 (file)
index 0000000..c180766
--- /dev/null
@@ -0,0 +1,29 @@
+/* CTF 1.8 */
+typealias integer { size = 8; align = 8; signed = false; base = 10; } := uint8_t;
+typealias integer { size = 32; align = 32; signed = false; base = hex; } := uint32_t;
+
+trace {
+       major = 0;
+       minor = 1;
+       test = "\"";
+       test2 = "?\x20\o040?";
+       test3 = '\n';
+       uuid = "2a6422d0-6cee-11e0-8c08-cb07d7b3a564";
+       byte_order = le;
+       packet.header := struct {
+               uint32_t magic;
+               uint8_t  uuid[16];
+       };
+};
+
+stream {
+       packet.context := struct {
+               uint32_t content_size;
+               uint32_t packet_size;
+       };
+};
+
+event {
+       name = string;
+       fields := struct { string str; };
+};
diff --git a/tests/ctf-traces/succeed/succeed4/metadata b/tests/ctf-traces/succeed/succeed4/metadata
new file mode 100644 (file)
index 0000000..a3d401a
--- /dev/null
@@ -0,0 +1,31 @@
+/* CTF 1.8 */
+typealias integer { size = 8; align = 8; signed = false; } := uint8_t;
+typealias integer { size = 32; align = 32; signed = false; } := uint32_t;
+
+trace {
+       major = 0;
+       minor = 1;
+       test = 0xABC234;        /* hexadecimal */
+       test1 = 06534;          /* octal */
+       test2 = 1234;           /* decimal */
+       test3 = +1234;          /* decimal with + unary op */
+       test4 = -1234;          /* decimal (negated) */
+       uuid = "2a6422d0-6cee-11e0-8c08-cb07d7b3a564";
+       byte_order = le;
+       packet.header := struct {
+               uint32_t magic;
+               uint8_t  uuid[16];
+       };
+};
+
+stream {
+       packet.context := struct {
+               uint32_t content_size;
+               uint32_t packet_size;
+       };
+};
+
+event {
+       name = string;
+       fields := struct { string str; };
+};
index e9e264bbbb17c5756f1243f33f42b8fc0cc691d9..01831de3dfb86452bba6c3e39bf652750b37c56d 100644 (file)
@@ -8,9 +8,12 @@ test_seeks_LDADD = libtestcommon.a \
        $(top_builddir)/lib/libbabeltrace.la \
        $(top_builddir)/formats/ctf/libbabeltrace-ctf.la
 
-noinst_PROGRAMS = test-seeks
+test_bitfield_LDADD = libtestcommon.a
+
+noinst_PROGRAMS = test-seeks test-bitfield
 
 test_seeks_SOURCES = test-seeks.c
+test_bitfield_SOURCES = test-bitfield.c
 
 EXTRA_DIST = README.tap runall.sh
 
index 34503bbbcfa7aff71f304aa594b9039b39c965ea..b5522ad0a19c0b515e838b33dc76b69fbe542ee8 100755 (executable)
@@ -3,4 +3,7 @@
 # With a trace than contains empty packets
 ./test-seeks ../ctf-traces/succeed/wk-heartbeat-u/ 1351532897586558519 1351532897591331194
 # With a bigger trace
-./test-seeks ../ctf-traces/succeed/lttng-modules-2.0-pre5/ 61334174524234 61336381998396
\ No newline at end of file
+./test-seeks ../ctf-traces/succeed/lttng-modules-2.0-pre5/ 61334174524234 61336381998396
+
+# run bitfield tests
+./test-bitfield
diff --git a/tests/lib/test-bitfield.c b/tests/lib/test-bitfield.c
new file mode 100644 (file)
index 0000000..2cb7a74
--- /dev/null
@@ -0,0 +1,363 @@
+/*
+ * test-bitfield.c
+ *
+ * BabelTrace - bitfield test program
+ *
+ * Copyright 2010 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
+ *
+ * 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; under version 2 of the License.
+ *
+ * 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.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#define _GNU_SOURCE
+#include <babeltrace/bitfield.h>
+#include <time.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+#include "tap.h"
+
+unsigned int glob;
+
+/*
+ * This function is only declared to show the size of a bitfield write in
+ * objdump.
+ */
+void fct(void)
+{
+       bt_bitfield_write(&glob, unsigned int, 12, 15, 0x12345678);
+}
+
+/* Test array size, in bytes */
+#define TEST_LEN 128
+#define NR_TESTS 10
+#define SIGNED_TEST_DESC_FMT_STR "Writing and reading back 0x%X, signed"
+#define UNSIGNED_TEST_DESC_FMT_STR "Writing and reading back 0x%X, unsigned"
+#define DIAG_FMT_STR "Failed reading value written \"%s\"-wise, with start=%i" \
+       " and length=%i. Read %llX"
+
+unsigned int srcrand;
+
+#if defined(__i386) || defined(__x86_64)
+
+static inline int fls(int x)
+{
+       int r;
+       asm("bsrl %1,%0\n\t"
+           "cmovzl %2,%0"
+           : "=&r" (r) : "rm" (x), "rm" (-1));
+       return r + 1;
+}
+
+#elif defined(__PPC__)
+
+static __inline__ int fls(unsigned int x)
+{
+       int lz;
+
+       asm ("cntlzw %0,%1" : "=r" (lz) : "r" (x));
+       return 32 - lz;
+}
+
+#else
+
+static int fls(unsigned int x)
+{
+       int r = 32;
+
+       if (!x)
+               return 0;
+       if (!(x & 0xFFFF0000U)) {
+               x <<= 16;
+               r -= 16;
+       }
+       if (!(x & 0xFF000000U)) {
+               x <<= 8;
+               r -= 8;
+       }
+       if (!(x & 0xF0000000U)) {
+               x <<= 4;
+               r -= 4;
+       }
+       if (!(x & 0xC0000000U)) {
+               x <<= 2;
+               r -= 2;
+       }
+       if (!(x & 0x80000000U)) {
+               x <<= 1;
+               r -= 1;
+       }
+       return r;
+}
+
+#endif
+
+#define print_byte_array(c, len)       \
+do {                                   \
+       unsigned long i;                \
+                                       \
+       for (i = 0; i < (len); i++) {   \
+               printf("0x%X", (c)[i]); \
+               if (i != (len) - 1)     \
+                       printf(" ");    \
+       }                               \
+       printf("\n");                   \
+} while (0)
+
+#define init_byte_array(c, len, val)   \
+do {                                   \
+       unsigned long i;                \
+                                       \
+       for (i = 0; i < (len); i++)     \
+               (c)[i] = (val);         \
+} while (0)
+
+#define check_result(ref, val, buffer, typename, start, len,           \
+                    desc_fmt_str)                                      \
+({                                                                     \
+       if ((val) != (ref)) {                                           \
+               fail(desc_fmt_str, ref);                                \
+               diag(DIAG_FMT_STR, #typename, start, len, val);         \
+               printf("# ");                                           \
+               print_byte_array(buffer, TEST_LEN);                     \
+       }                                                               \
+       (val) != (ref);                                                 \
+})
+
+void run_test_unsigned(void)
+{
+       unsigned int src, nrbits;
+       union {
+               unsigned char c[TEST_LEN];
+               unsigned short s[TEST_LEN/sizeof(unsigned short)];
+               unsigned int i[TEST_LEN/sizeof(unsigned int)];
+               unsigned long l[TEST_LEN/sizeof(unsigned long)];
+               unsigned long long ll[TEST_LEN/sizeof(unsigned long long)];
+       } target;
+       unsigned long long readval;
+       unsigned int s, l;
+
+       src = srcrand;
+       nrbits = fls(src);
+
+       for (s = 0; s < CHAR_BIT * TEST_LEN; s++) {
+               for (l = nrbits; l < (CHAR_BIT * TEST_LEN) - s; l++) {
+                       init_byte_array(target.c, TEST_LEN, 0xFF);
+                       bt_bitfield_write(target.c, unsigned char, s, l, src);
+                       bt_bitfield_read(target.c, unsigned char, s, l, &readval);
+                       if (check_result(src, readval, target.c, unsigned char,
+                                         s, l, UNSIGNED_TEST_DESC_FMT_STR)) {
+                               return;
+                       }
+
+                       init_byte_array(target.c, TEST_LEN, 0xFF);
+                       bt_bitfield_write(target.s, unsigned short, s, l, src);
+                       bt_bitfield_read(target.c, unsigned char, s, l, &readval);
+                       if (check_result(src, readval, target.c, unsigned short,
+                                         s, l, UNSIGNED_TEST_DESC_FMT_STR)) {
+                               return;
+                       }
+
+                       init_byte_array(target.c, TEST_LEN, 0xFF);
+                       bt_bitfield_write(target.i, unsigned int, s, l, src);
+                       bt_bitfield_read(target.c, unsigned char, s, l, &readval);
+                       if (check_result(src, readval, target.c, unsigned int,
+                                          s, l, UNSIGNED_TEST_DESC_FMT_STR)) {
+                               return;
+                       }
+
+                       init_byte_array(target.c, TEST_LEN, 0xFF);
+                       bt_bitfield_write(target.l, unsigned long, s, l, src);
+                       bt_bitfield_read(target.c, unsigned char, s, l, &readval);
+                       if (check_result(src, readval, target.c, unsigned long,
+                                         s, l, UNSIGNED_TEST_DESC_FMT_STR)) {
+                               return;
+                       }
+
+                       init_byte_array(target.c, TEST_LEN, 0xFF);
+                       bt_bitfield_write(target.ll, unsigned long long, s, l, src);
+                       bt_bitfield_read(target.c, unsigned char, s, l, &readval);
+                       if (check_result(src, readval, target.c, unsigned long long,
+                                    s, l, UNSIGNED_TEST_DESC_FMT_STR)) {
+                               return;
+                       }
+               }
+       }
+
+       pass(UNSIGNED_TEST_DESC_FMT_STR, src);
+}
+
+void run_test_signed(void)
+{
+       int src, nrbits;
+       union {
+               signed char c[TEST_LEN];
+               short s[TEST_LEN/sizeof(short)];
+               int i[TEST_LEN/sizeof(int)];
+               long l[TEST_LEN/sizeof(long)];
+               long long ll[TEST_LEN/sizeof(long long)];
+       } target;
+       long long readval;
+       unsigned int s, l;
+
+       src = srcrand;
+       if (src & 0x80000000U)
+               nrbits = fls(~src) + 1; /* Find least significant bit conveying sign */
+       else
+               nrbits = fls(src) + 1;  /* Keep sign at 0 */
+
+       for (s = 0; s < CHAR_BIT * TEST_LEN; s++) {
+               for (l = nrbits; l < (CHAR_BIT * TEST_LEN) - s; l++) {
+                       init_byte_array(target.c, TEST_LEN, 0x0);
+                       bt_bitfield_write(target.c, signed char, s, l, src);
+                       bt_bitfield_read(target.c, signed char, s, l, &readval);
+                       if (check_result(src, readval, target.c, signed char,
+                                         s, l, SIGNED_TEST_DESC_FMT_STR)) {
+                               return;
+                       }
+
+                       init_byte_array(target.c, TEST_LEN, 0x0);
+                       bt_bitfield_write(target.s, short, s, l, src);
+                       bt_bitfield_read(target.c, signed char, s, l, &readval);
+                       if (check_result(src, readval, target.c, short,
+                                         s, l, SIGNED_TEST_DESC_FMT_STR)) {
+                               return;
+                       }
+
+                       init_byte_array(target.c, TEST_LEN, 0x0);
+                       bt_bitfield_write(target.i, int, s, l, src);
+                       bt_bitfield_read(target.c, signed char, s, l, &readval);
+                       if (check_result(src, readval, target.c, int,
+                                         s, l, SIGNED_TEST_DESC_FMT_STR)) {
+                               return;
+                       }
+
+                       init_byte_array(target.c, TEST_LEN, 0x0);
+                       bt_bitfield_write(target.l, long, s, l, src);
+                       bt_bitfield_read(target.c, signed char, s, l, &readval);
+                       if (check_result(src, readval, target.c, long,
+                                         s, l, SIGNED_TEST_DESC_FMT_STR)) {
+                               return;
+                       }
+
+                       init_byte_array(target.c, TEST_LEN, 0x0);
+                       bt_bitfield_write(target.ll, long long, s, l, src);
+                       bt_bitfield_read(target.c, signed char, s, l, &readval);
+                       if (check_result(src, readval, target.c, long long,
+                                         s, l, SIGNED_TEST_DESC_FMT_STR)) {
+                               return;
+                       }
+               }
+       }
+
+       pass(SIGNED_TEST_DESC_FMT_STR, src);
+}
+
+void run_test(void)
+{
+       int i;
+       plan_tests(NR_TESTS * 2 + 6);
+
+       srand(time(NULL));
+
+       srcrand = 0;
+       run_test_unsigned();
+       srcrand = 0;
+       run_test_signed();
+
+       srcrand = 1;
+       run_test_unsigned();
+
+       srcrand = ~0U;
+       run_test_unsigned();
+
+       srcrand = -1;
+       run_test_signed();
+
+       srcrand = (int)0x80000000U;
+       run_test_signed();
+
+       for (i = 0; i < NR_TESTS; i++) {
+               srcrand = rand();
+               run_test_unsigned();
+               run_test_signed();
+       }
+}
+
+static
+int print_encodings(unsigned long src, unsigned int shift, unsigned int len)
+{
+       union {
+               unsigned char c[8];
+               unsigned short s[4];
+               unsigned int i[2];
+               unsigned long l[2];
+               unsigned long long ll[1];
+       } target;
+       unsigned long long readval;
+
+       init_byte_array(target.c, 8, 0xFF);
+       bt_bitfield_write(target.c, unsigned char, shift, len, src);
+       printf("bytewise\n");
+       print_byte_array(target.c, 8);
+
+       init_byte_array(target.c, 8, 0xFF);
+       bt_bitfield_write(target.s, unsigned short, shift, len, src);
+       printf("shortwise\n");
+       print_byte_array(target.c, 8);
+
+       init_byte_array(target.c, 8, 0xFF);
+       bt_bitfield_write(target.i, unsigned int, shift, len, src);
+       printf("intwise\n");
+       print_byte_array(target.c, 8);
+
+       init_byte_array(target.c, 8, 0xFF);
+       bt_bitfield_write(target.l, unsigned long, shift, len, src);
+       printf("longwise\n");
+       print_byte_array(target.c, 8);
+
+       init_byte_array(target.c, 8, 0xFF);
+       bt_bitfield_write(target.ll, unsigned long long, shift, len, src);
+       printf("lluwise\n");
+       print_byte_array(target.c, 8);
+
+       bt_bitfield_read(target.c, unsigned char, shift, len, &readval);
+       printf("read: %llX\n", readval);
+       print_byte_array(target.c, 8);
+
+       return 0;
+}
+
+int main(int argc, char **argv)
+{
+       if (argc > 1) {
+               /* Print encodings */
+               unsigned long src;
+               unsigned int shift, len;
+
+               src = atoi(argv[1]);
+               if (argc > 2)
+                       shift = atoi(argv[2]);
+               else
+                       shift = 12;
+               if (argc > 3)
+                       len = atoi(argv[3]);
+               else
+                       len = 40;
+               return print_encodings(src, shift, len);
+       }
+
+       /* Run tap-formated tests */
+       run_test();
+       return exit_status();
+}
index 47bb42e216cbb1287c0c2ec9e4c5a9e017c6472f..a7b1360f97779a10b354fa4774b25644e1fb6a17 100644 (file)
@@ -32,7 +32,7 @@
 #include "common.h"
 #include "tap.h"
 
-#define NR_TESTS       23
+#define NR_TESTS       29
 
 void run_seek_begin(char *path, uint64_t expected_begin)
 {
@@ -134,6 +134,58 @@ void run_seek_last(char *path, uint64_t expected_last)
        bt_context_put(ctx);
 }
 
+void run_seek_time_at_last(char *path, uint64_t expected_last)
+{
+       struct bt_context *ctx;
+       struct bt_ctf_iter *iter;
+       struct bt_ctf_event *event;
+       struct bt_iter_pos newpos;
+       int ret;
+       uint64_t timestamp_last;
+
+       /* Open the trace */
+       ctx = create_context_with_path(path);
+       if (!ctx) {
+               plan_skip_all("Cannot create valid context");
+       }
+
+       /* Create iterator with null last and end */
+       iter = bt_ctf_iter_create(ctx, NULL, NULL);
+       if (!iter) {
+               plan_skip_all("Cannot create valid iterator");
+       }
+
+       event = bt_ctf_iter_read_event(iter);
+
+       ok(event, "Event valid at beginning");
+
+       /* Seek to last */
+       newpos.type = BT_SEEK_TIME;
+       newpos.u.seek_time = expected_last;
+       ret = bt_iter_set_pos(bt_ctf_get_iter(iter), &newpos);
+
+       ok(ret == 0, "Seek time at last retval %d", ret);
+
+       event = bt_ctf_iter_read_event(iter);
+
+       ok(event, "Event valid at last position");
+
+       timestamp_last = bt_ctf_get_timestamp(event);
+
+       ok1(timestamp_last == expected_last);
+
+       /* Try to read next event */
+       ret = bt_iter_next(bt_ctf_get_iter(iter));
+
+       ok(ret == 0, "iter next should return an error");
+
+       event = bt_ctf_iter_read_event(iter);
+
+       ok(event == 0, "Event after last should be invalid");
+
+       bt_context_put(ctx);
+}
+
 void run_seek_cycles(char *path,
                uint64_t expected_begin,
                uint64_t expected_last)
@@ -242,6 +294,7 @@ int main(int argc, char **argv)
        }
 
        run_seek_begin(path, expected_begin);
+       run_seek_time_at_last(path, expected_last);
        run_seek_last(path, expected_last);
        run_seek_cycles(path, expected_begin, expected_last);
 
index b2af65647c8a2418b6737ead0e9a6cc2dc4a840d..c10e88ab5ddbcdb8292a6dd0543e5221da2c3f5e 100755 (executable)
@@ -5,44 +5,20 @@ DIR=$(readlink -f ${TESTDIR})
 BABELTRACE_BIN=${DIR}/../converter/babeltrace
 CTF_TRACES=${DIR}/ctf-traces
 
-function print_ok ()
-{
-       # Check if we are a terminal
-       if [ -t 1 ]; then
-               echo -e "\e[1;32mOK\e[0m"
-       else
-               echo -e "OK"
-       fi
-}
-
-function print_fail ()
-{
-       # Check if we are a terminal
-       if [ -t 1 ]; then
-               echo -e "\e[1;31mFAIL\e[0m"
-       else
-               echo -e "FAIL"
-       fi
-}
-
-function test_check ()
+function test_check_success ()
 {
        if [ $? -ne 0 ] ; then
-               print_fail
                return 1
        else
-               print_ok
                return 0
        fi
 }
 
 function test_check_fail ()
 {
-       if [ $? -ne 1 ] ; then
-               print_fail
+       if [ $? -eq 0 ] ; then
                return 1
        else
-               print_ok
                return 0
        fi
 }
@@ -53,45 +29,48 @@ function run_babeltrace ()
        return $?
 }
 
-echo -e "Running test-bitfield..."
-./test-bitfield
-test_check
-if [ $? -ne 0 ]; then
-       exit 1
-fi
-
-#run babeltrace expects success
-echo -e "Running babeltrace without argument..."
-run_babeltrace
-test_check
-if [ $? -ne 0 ]; then
-       exit 1
-fi
-
-for a in ${CTF_TRACES}/succeed/*; do
-       echo -e "Running babeltrace for trace ${a}..."
-       run_babeltrace ${a}
-       test_check
-       if [ $? -ne 0 ]; then
+function print_test_result ()
+{
+       if [ $# -ne 3 ] ; then
+               echo "Invalid arguments provided"
                exit 1
        fi
-done
 
-#run babeltrace expects failure
-echo -e "Running babeltrace with bogus argument..."
+       if [ ${2} -eq 0 ] ; then
+               echo -n "ok"
+       else
+               echo -n "not ok"
+       fi
+       echo -e " "${1}" - "${3}
+}
+
+successTraces=(${CTF_TRACES}/succeed/*)
+failTraces=(${CTF_TRACES}/fail/*)
+testCount=$((2 + ${#successTraces[@]} + ${#failTraces[@]}))
+
+currentTestIndex=1
+echo -e 1..${testCount}
+
+#run babeltrace, expects success
+run_babeltrace
+test_check_success
+print_test_result $((currentTestIndex++)) $? "Running babeltrace without arguments"
+
+#run babeltrace with a bogus argument, expects failure
 run_babeltrace --bogusarg
 test_check_fail
-if [ $? -ne 0 ]; then
-       exit 1
-fi
+print_test_result $((currentTestIndex++)) $? "Running babeltrace with a bogus argument"
+
+for tracePath in ${successTraces[@]}; do
+       run_babeltrace ${tracePath}
+       test_check_success
+       print_test_result $((currentTestIndex++)) $? "Running babeltrace with trace ${tracePath}"
+done
 
-for a in ${CTF_TRACES}/fail/*; do
-       echo -e "Running babeltrace for trace ${a}..."
-       run_babeltrace ${a}
+for tracePath in ${failTraces[@]}; do
+       run_babeltrace ${tracePath}
        test_check_fail
-       if [ $? -ne 0 ]; then
-               exit 1
-       fi
+       print_test_result $((currentTestIndex++)) $? "Running babeltrace with trace ${tracePath}"
 done
 
 exit 0
diff --git a/tests/test-bitfield.c b/tests/test-bitfield.c
deleted file mode 100644 (file)
index 3bf7568..0000000
+++ /dev/null
@@ -1,371 +0,0 @@
-/*
- * test-bitfield.c
- *
- * BabelTrace - bitfield test program
- *
- * Copyright 2010 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
- *
- * 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; under version 2 of the License.
- *
- * 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.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- */
-
-#define _GNU_SOURCE
-#include <babeltrace/bitfield.h>
-#include <time.h>
-#include <stdlib.h>
-#include <stdio.h>
-
-unsigned int glob;
-
-/*
- * This function is only declared to show the size of a bitfield write in
- * objdump.
- */
-void fct(void)
-{
-       bt_bitfield_write(&glob, unsigned int, 12, 15, 0x12345678);
-}
-
-/* Test array size, in bytes */
-#define TEST_LEN 128
-#define NR_TESTS 10
-
-unsigned int srcrand;
-
-#if defined(__i386) || defined(__x86_64)
-
-static inline int fls(int x)
-{
-       int r;
-       asm("bsrl %1,%0\n\t"
-           "cmovzl %2,%0"
-           : "=&r" (r) : "rm" (x), "rm" (-1));
-       return r + 1;
-}
-
-#elif defined(__PPC__)
-
-static __inline__ int fls(unsigned int x)
-{
-       int lz;
-
-       asm ("cntlzw %0,%1" : "=r" (lz) : "r" (x));
-       return 32 - lz;
-}
-
-#else
-
-static int fls(unsigned int x)
-{
-       int r = 32;
-
-       if (!x)
-               return 0;
-       if (!(x & 0xFFFF0000U)) {
-               x <<= 16;
-               r -= 16;
-       }
-       if (!(x & 0xFF000000U)) {
-               x <<= 8;
-               r -= 8;
-       }
-       if (!(x & 0xF0000000U)) {
-               x <<= 4;
-               r -= 4;
-       }
-       if (!(x & 0xC0000000U)) {
-               x <<= 2;
-               r -= 2;
-       }
-       if (!(x & 0x80000000U)) {
-               x <<= 1;
-               r -= 1;
-       }
-       return r;
-}
-
-#endif
-
-#define print_byte_array(c, len)       \
-do {                                   \
-       unsigned long i;                \
-                                       \
-       for (i = 0; i < (len); i++) {   \
-               printf("0x%X", (c)[i]); \
-               if (i != (len) - 1)     \
-                       printf(" ");    \
-       }                               \
-       printf("\n");                   \
-} while (0)
-
-#define init_byte_array(c, len, val)   \
-do {                                   \
-       unsigned long i;                \
-                                       \
-       for (i = 0; i < (len); i++)     \
-               (c)[i] = (val);         \
-} while (0)
-
-int run_test_unsigned(void)
-{
-       unsigned int src, nrbits;
-       union {
-               unsigned char c[TEST_LEN];
-               unsigned short s[TEST_LEN/sizeof(unsigned short)];
-               unsigned int i[TEST_LEN/sizeof(unsigned int)];
-               unsigned long l[TEST_LEN/sizeof(unsigned long)];
-               unsigned long long ll[TEST_LEN/sizeof(unsigned long long)];
-       } target;
-       unsigned long long readval;
-       unsigned int s, l;
-       int err = 0;
-
-       printf("Running unsigned test with 0x%X\n", srcrand);
-
-       src = srcrand;
-       nrbits = fls(src);
-
-       for (s = 0; s < CHAR_BIT * TEST_LEN; s++) {
-               for (l = nrbits; l < (CHAR_BIT * TEST_LEN) - s; l++) {
-                       init_byte_array(target.c, TEST_LEN, 0xFF);
-                       bt_bitfield_write(target.c, unsigned char, s, l, src);
-                       bt_bitfield_read(target.c, unsigned char, s, l, &readval);
-                       if (readval != src) {
-                               printf("Error (bytewise) src %X read %llX shift %d len %d\n",
-                                      src, readval, s, l);
-                               print_byte_array(target.c, TEST_LEN);
-                               err = 1;
-                       }
-
-                       init_byte_array(target.c, TEST_LEN, 0xFF);
-                       bt_bitfield_write(target.s, unsigned short, s, l, src);
-                       bt_bitfield_read(target.c, unsigned char, s, l, &readval);
-                       if (readval != src) {
-                               printf("Error (shortwise) src %X read %llX shift %d len %d\n",
-                                      src, readval, s, l);
-                               print_byte_array(target.c, TEST_LEN);
-                               err = 1;
-                       }
-
-                       init_byte_array(target.c, TEST_LEN, 0xFF);
-                       bt_bitfield_write(target.i, unsigned int, s, l, src);
-                       bt_bitfield_read(target.c, unsigned char, s, l, &readval);
-                       if (readval != src) {
-                               printf("Error (intwise) src %X read %llX shift %d len %d\n",
-                                      src, readval, s, l);
-                               print_byte_array(target.c, TEST_LEN);
-                               err = 1;
-                       }
-
-                       init_byte_array(target.c, TEST_LEN, 0xFF);
-                       bt_bitfield_write(target.l, unsigned long, s, l, src);
-                       bt_bitfield_read(target.c, unsigned char, s, l, &readval);
-                       if (readval != src) {
-                               printf("Error (longwise) src %X read %llX shift %d len %d\n",
-                                      src, readval, s, l);
-                               print_byte_array(target.c, TEST_LEN);
-                               err = 1;
-                       }
-
-                       init_byte_array(target.c, TEST_LEN, 0xFF);
-                       bt_bitfield_write(target.ll, unsigned long long, s, l, src);
-                       bt_bitfield_read(target.c, unsigned char, s, l, &readval);
-                       if (readval != src) {
-                               printf("Error (longlongwise) src %X read %llX shift %d len %d\n",
-                                      src, readval, s, l);
-                               print_byte_array(target.c, TEST_LEN);
-                               err = 1;
-                       }
-               }
-       }
-       if (!err)
-               printf("Success!\n");
-       else
-               printf("Failed!\n");
-       return err;
-}
-
-int run_test_signed(void)
-{
-       int src, nrbits;
-       union {
-               signed char c[TEST_LEN];
-               short s[TEST_LEN/sizeof(short)];
-               int i[TEST_LEN/sizeof(int)];
-               long l[TEST_LEN/sizeof(long)];
-               long long ll[TEST_LEN/sizeof(long long)];
-       } target;
-       long long readval;
-       unsigned int s, l;
-       int err = 0;
-
-       printf("Running signed test with 0x%X\n", srcrand);
-
-       src = srcrand;
-       if (src & 0x80000000U)
-               nrbits = fls(~src) + 1; /* Find least significant bit conveying sign */
-       else
-               nrbits = fls(src) + 1;  /* Keep sign at 0 */
-
-       for (s = 0; s < 8 * TEST_LEN; s++) {
-               for (l = nrbits; l < (8 * TEST_LEN) - s; l++) {
-                       init_byte_array(target.c, TEST_LEN, 0x0);
-                       bt_bitfield_write(target.c, signed char, s, l, src);
-                       bt_bitfield_read(target.c, signed char, s, l, &readval);
-                       if (readval != src) {
-                               printf("Error (bytewise) src %X read %llX shift %d len %d\n",
-                                      src, readval, s, l);
-                               print_byte_array(target.c, TEST_LEN);
-                               err = 1;
-                       }
-
-                       init_byte_array(target.c, TEST_LEN, 0x0);
-                       bt_bitfield_write(target.s, short, s, l, src);
-                       bt_bitfield_read(target.c, signed char, s, l, &readval);
-                       if (readval != src) {
-                               printf("Error (shortwise) src %X read %llX shift %d len %d\n",
-                                      src, readval, s, l);
-                               print_byte_array(target.c, TEST_LEN);
-                               err = 1;
-                       }
-
-                       init_byte_array(target.c, TEST_LEN, 0x0);
-                       bt_bitfield_write(target.i, int, s, l, src);
-                       bt_bitfield_read(target.c, signed char, s, l, &readval);
-                       if (readval != src) {
-                               printf("Error (intwise) src %X read %llX shift %d len %d\n",
-                                      src, readval, s, l);
-                               print_byte_array(target.c, TEST_LEN);
-                               err = 1;
-                       }
-
-                       init_byte_array(target.c, TEST_LEN, 0x0);
-                       bt_bitfield_write(target.l, long, s, l, src);
-                       bt_bitfield_read(target.c, signed char, s, l, &readval);
-                       if (readval != src) {
-                               printf("Error (longwise) src %X read %llX shift %d len %d\n",
-                                      src, readval, s, l);
-                               print_byte_array(target.c, TEST_LEN);
-                               err = 1;
-                       }
-
-                       init_byte_array(target.c, TEST_LEN, 0x0);
-                       bt_bitfield_write(target.ll, long long, s, l, src);
-                       bt_bitfield_read(target.c, signed char, s, l, &readval);
-                       if (readval != src) {
-                               printf("Error (longlongwise) src %X read %llX shift %d len %d\n",
-                                      src, readval, s, l);
-                               print_byte_array(target.c, TEST_LEN);
-                               err = 1;
-                       }
-               }
-       }
-       if (!err)
-               printf("Success!\n");
-       else
-               printf("Failed!\n");
-       return err;
-}
-
-int run_test(void)
-{
-       int err = 0;
-       int i;
-
-       srand(time(NULL));
-
-       srcrand = 0;
-       err |= run_test_unsigned();
-       srcrand = 0;
-       err |= run_test_signed();
-       srcrand = 1;
-       err |= run_test_unsigned();
-       srcrand = ~0U;
-       err |= run_test_unsigned();
-       srcrand = -1;
-       err |= run_test_signed();
-       srcrand = (int)0x80000000U;
-       err |= run_test_signed();
-
-       for (i = 0; i < NR_TESTS; i++) {
-               srcrand = rand();
-               err |= run_test_unsigned();
-               err |= run_test_signed();
-       }
-       return err;
-}
-
-int main(int argc, char **argv)
-{
-       unsigned long src;
-       unsigned int shift, len;
-       int ret;
-       union {
-               unsigned char c[8];
-               unsigned short s[4];
-               unsigned int i[2];
-               unsigned long l[2];
-               unsigned long long ll[1];
-       } target;
-       unsigned long long readval;
-
-       if (argc > 1)
-               src = atoi(argv[1]);
-       else
-               src = 0x12345678;
-       if (argc > 2)
-               shift = atoi(argv[2]);
-       else
-               shift = 12;
-       if (argc > 3)
-               len = atoi(argv[3]);
-       else
-               len = 40;
-
-       target.i[0] = 0xFFFFFFFF;
-       target.i[1] = 0xFFFFFFFF;
-       bt_bitfield_write(target.c, unsigned char, shift, len, src);
-       printf("bytewise\n");
-       print_byte_array(target.c, 8);
-
-       target.i[0] = 0xFFFFFFFF;
-       target.i[1] = 0xFFFFFFFF;
-       bt_bitfield_write(target.s, unsigned short, shift, len, src);
-       printf("shortwise\n");
-       print_byte_array(target.c, 8);
-
-       target.i[0] = 0xFFFFFFFF;
-       target.i[1] = 0xFFFFFFFF;
-       bt_bitfield_write(target.i, unsigned int, shift, len, src);
-       printf("intwise\n");
-       print_byte_array(target.c, 8);
-
-       target.i[0] = 0xFFFFFFFF;
-       target.i[1] = 0xFFFFFFFF;
-       bt_bitfield_write(target.l, unsigned long, shift, len, src);
-       printf("longwise\n");
-       print_byte_array(target.c, 8);
-
-       target.i[0] = 0xFFFFFFFF;
-       target.i[1] = 0xFFFFFFFF;
-       bt_bitfield_write(target.ll, unsigned long long, shift, len, src);
-       printf("lluwise\n");
-       print_byte_array(target.c, 8);
-
-       bt_bitfield_read(target.c, unsigned char, shift, len, &readval);
-       printf("read: %llX\n", readval);
-
-       ret = run_test();
-
-       return ret;
-}
index 494210827ff80ab301479b6aa4537d49c24684b7..c9b973bfa13a3d3719c9bdf1d07259c1d7880fa8 100644 (file)
 #include <inttypes.h>
 
 static
-struct definition *_array_definition_new(struct declaration *declaration,
+struct bt_definition *_array_definition_new(struct bt_declaration *declaration,
                        struct definition_scope *parent_scope,
                        GQuark field_name, int index, const char *root_name);
 static
-void _array_definition_free(struct definition *definition);
+void _array_definition_free(struct bt_definition *definition);
 
-int array_rw(struct stream_pos *pos, struct definition *definition)
+int bt_array_rw(struct bt_stream_pos *pos, struct bt_definition *definition)
 {
        struct definition_array *array_definition =
                container_of(definition, struct definition_array, p);
@@ -49,7 +49,7 @@ int array_rw(struct stream_pos *pos, struct definition *definition)
 
        /* No need to align, because the first field will align itself. */
        for (i = 0; i < array_declaration->len; i++) {
-               struct definition *field =
+               struct bt_definition *field =
                        g_ptr_array_index(array_definition->elems, i);
                ret = generic_rw(pos, field);
                if (ret)
@@ -59,30 +59,30 @@ int array_rw(struct stream_pos *pos, struct definition *definition)
 }
 
 static
-void _array_declaration_free(struct declaration *declaration)
+void _array_declaration_free(struct bt_declaration *declaration)
 {
        struct declaration_array *array_declaration =
                container_of(declaration, struct declaration_array, p);
 
-       free_declaration_scope(array_declaration->scope);
-       declaration_unref(array_declaration->elem);
+       bt_free_declaration_scope(array_declaration->scope);
+       bt_declaration_unref(array_declaration->elem);
        g_free(array_declaration);
 }
 
 struct declaration_array *
-       array_declaration_new(size_t len,
-                             struct declaration *elem_declaration,
+       bt_array_declaration_new(size_t len,
+                             struct bt_declaration *elem_declaration,
                              struct declaration_scope *parent_scope)
 {
        struct declaration_array *array_declaration;
-       struct declaration *declaration;
+       struct bt_declaration *declaration;
 
        array_declaration = g_new(struct declaration_array, 1);
        declaration = &array_declaration->p;
        array_declaration->len = len;
-       declaration_ref(elem_declaration);
+       bt_declaration_ref(elem_declaration);
        array_declaration->elem = elem_declaration;
-       array_declaration->scope = new_declaration_scope(parent_scope);
+       array_declaration->scope = bt_new_declaration_scope(parent_scope);
        declaration->id = CTF_TYPE_ARRAY;
        declaration->alignment = elem_declaration->alignment;
        declaration->declaration_free = _array_declaration_free;
@@ -93,8 +93,8 @@ struct declaration_array *
 }
 
 static
-struct definition *
-       _array_definition_new(struct declaration *declaration,
+struct bt_definition *
+       _array_definition_new(struct bt_declaration *declaration,
                              struct definition_scope *parent_scope,
                              GQuark field_name, int index, const char *root_name)
 {
@@ -105,7 +105,7 @@ struct definition *
        int i;
 
        array = g_new(struct definition_array, 1);
-       declaration_ref(&array_declaration->p);
+       bt_declaration_ref(&array_declaration->p);
        array->p.declaration = declaration;
        array->declaration = array_declaration;
        array->p.ref = 1;
@@ -115,9 +115,9 @@ struct definition *
         */
        array->p.index = root_name ? INT_MAX : index;
        array->p.name = field_name;
-       array->p.path = new_definition_path(parent_scope, field_name, root_name);
-       array->p.scope = new_definition_scope(parent_scope, field_name, root_name);
-       ret = register_field_definition(field_name, &array->p,
+       array->p.path = bt_new_definition_path(parent_scope, field_name, root_name);
+       array->p.scope = bt_new_definition_scope(parent_scope, field_name, root_name);
+       ret = bt_register_field_definition(field_name, &array->p,
                                        parent_scope);
        assert(!ret);
        array->string = NULL;
@@ -142,7 +142,7 @@ struct definition *
        array->elems = g_ptr_array_sized_new(array_declaration->len);
        g_ptr_array_set_size(array->elems, array_declaration->len);
        for (i = 0; i < array_declaration->len; i++) {
-               struct definition **field;
+               struct bt_definition **field;
                GString *str;
                GQuark name;
 
@@ -151,7 +151,7 @@ struct definition *
                name = g_quark_from_string(str->str);
                (void) g_string_free(str, TRUE);
 
-               field = (struct definition **) &g_ptr_array_index(array->elems, i);
+               field = (struct bt_definition **) &g_ptr_array_index(array->elems, i);
                *field = array_declaration->elem->definition_new(array_declaration->elem,
                                          array->p.scope,
                                          name, i, NULL);
@@ -163,20 +163,20 @@ struct definition *
 
 error:
        for (i--; i >= 0; i--) {
-               struct definition *field;
+               struct bt_definition *field;
 
                field = g_ptr_array_index(array->elems, i);
                field->declaration->definition_free(field);
        }
        (void) g_ptr_array_free(array->elems, TRUE);
-       free_definition_scope(array->p.scope);
-       declaration_unref(array->p.declaration);
+       bt_free_definition_scope(array->p.scope);
+       bt_declaration_unref(array->p.declaration);
        g_free(array);
        return NULL;
 }
 
 static
-void _array_definition_free(struct definition *definition)
+void _array_definition_free(struct bt_definition *definition)
 {
        struct definition_array *array =
                container_of(definition, struct definition_array, p);
@@ -186,26 +186,26 @@ void _array_definition_free(struct definition *definition)
                (void) g_string_free(array->string, TRUE);
        if (array->elems) {
                for (i = 0; i < array->elems->len; i++) {
-                       struct definition *field;
+                       struct bt_definition *field;
 
                        field = g_ptr_array_index(array->elems, i);
                        field->declaration->definition_free(field);
                }
                (void) g_ptr_array_free(array->elems, TRUE);
        }
-       free_definition_scope(array->p.scope);
-       declaration_unref(array->p.declaration);
+       bt_free_definition_scope(array->p.scope);
+       bt_declaration_unref(array->p.declaration);
        g_free(array);
 }
 
-uint64_t array_len(struct definition_array *array)
+uint64_t bt_array_len(struct definition_array *array)
 {
        if (!array->elems)
                return array->string->len;
        return array->elems->len;
 }
 
-struct definition *array_index(struct definition_array *array, uint64_t i)
+struct bt_definition *bt_array_index(struct definition_array *array, uint64_t i)
 {
        if (!array->elems)
                return NULL;
@@ -214,7 +214,7 @@ struct definition *array_index(struct definition_array *array, uint64_t i)
        return g_ptr_array_index(array->elems, i);
 }
 
-int get_array_len(const struct definition *field)
+int bt_get_array_len(const struct bt_definition *field)
 {
        struct definition_array *array_definition;
        struct declaration_array *array_declaration;
@@ -225,11 +225,11 @@ int get_array_len(const struct definition *field)
        return array_declaration->len;
 }
 
-GString *get_char_array(const struct definition *field)
+GString *bt_get_char_array(const struct bt_definition *field)
 {
        struct definition_array *array_definition;
        struct declaration_array *array_declaration;
-       struct declaration *elem;
+       struct bt_declaration *elem;
 
        array_definition = container_of(field, struct definition_array, p);
        array_declaration = array_definition->declaration;
index ca0143d4f5a53849136b7195bde96c2a62b93240..8394e1b35b70b4e2c58b2a9d9ed97d1293eb2c3c 100644 (file)
 #endif
 
 static
-struct definition *_enum_definition_new(struct declaration *declaration,
+struct bt_definition *_enum_definition_new(struct bt_declaration *declaration,
                                        struct definition_scope *parent_scope,
                                        GQuark field_name, int index,
                                        const char *root_name);
 static
-void _enum_definition_free(struct definition *definition);
+void _enum_definition_free(struct bt_definition *definition);
 
 static
 void enum_range_set_free(void *ptr)
@@ -124,7 +124,7 @@ void enum_val_free(void *ptr)
  * Returns a GArray or NULL.
  * Caller must release the GArray with g_array_unref().
  */
-GArray *enum_uint_to_quark_set(const struct declaration_enum *enum_declaration,
+GArray *bt_enum_uint_to_quark_set(const struct declaration_enum *enum_declaration,
                               uint64_t v)
 {
        struct enum_range_to_quark *iter;
@@ -171,7 +171,7 @@ GArray *enum_uint_to_quark_set(const struct declaration_enum *enum_declaration,
  * Returns a GArray or NULL.
  * Caller must release the GArray with g_array_unref().
  */
-GArray *enum_int_to_quark_set(const struct declaration_enum *enum_declaration,
+GArray *bt_enum_int_to_quark_set(const struct declaration_enum *enum_declaration,
                              int64_t v)
 {
        struct enum_range_to_quark *iter;
@@ -215,7 +215,7 @@ GArray *enum_int_to_quark_set(const struct declaration_enum *enum_declaration,
 }
 
 static
-void enum_unsigned_insert_value_to_quark_set(struct declaration_enum *enum_declaration,
+void bt_enum_unsigned_insert_value_to_quark_set(struct declaration_enum *enum_declaration,
                         uint64_t v, GQuark q)
 {
        uint64_t *valuep;
@@ -241,7 +241,7 @@ void enum_unsigned_insert_value_to_quark_set(struct declaration_enum *enum_decla
 }
 
 static
-void enum_signed_insert_value_to_quark_set(struct declaration_enum *enum_declaration,
+void bt_enum_signed_insert_value_to_quark_set(struct declaration_enum *enum_declaration,
                        int64_t v, GQuark q)
 {
        int64_t *valuep;
@@ -266,7 +266,7 @@ void enum_signed_insert_value_to_quark_set(struct declaration_enum *enum_declara
        }
 }
 
-GArray *enum_quark_to_range_set(const struct declaration_enum *enum_declaration,
+GArray *bt_enum_quark_to_range_set(const struct declaration_enum *enum_declaration,
                                GQuark q)
 {
        return g_hash_table_lookup(enum_declaration->table.quark_to_range_set,
@@ -274,7 +274,7 @@ GArray *enum_quark_to_range_set(const struct declaration_enum *enum_declaration,
 }
 
 static
-void enum_signed_insert_range_to_quark(struct declaration_enum *enum_declaration,
+void bt_enum_signed_insert_range_to_quark(struct declaration_enum *enum_declaration,
                         int64_t start, int64_t end, GQuark q)
 {
        struct enum_range_to_quark *rtoq;
@@ -287,7 +287,7 @@ void enum_signed_insert_range_to_quark(struct declaration_enum *enum_declaration
 }
 
 static
-void enum_unsigned_insert_range_to_quark(struct declaration_enum *enum_declaration,
+void bt_enum_unsigned_insert_range_to_quark(struct declaration_enum *enum_declaration,
                         uint64_t start, uint64_t end, GQuark q)
 {
        struct enum_range_to_quark *rtoq;
@@ -299,14 +299,14 @@ void enum_unsigned_insert_range_to_quark(struct declaration_enum *enum_declarati
        rtoq->quark = q;
 }
 
-void enum_signed_insert(struct declaration_enum *enum_declaration,
+void bt_enum_signed_insert(struct declaration_enum *enum_declaration,
                         int64_t start, int64_t end, GQuark q)
 {
        GArray *array;
        struct enum_range *range;
 
        if (start == end) {
-               enum_signed_insert_value_to_quark_set(enum_declaration, start, q);
+               bt_enum_signed_insert_value_to_quark_set(enum_declaration, start, q);
        } else {
                if (start > end) {
                        uint64_t tmp;
@@ -315,7 +315,7 @@ void enum_signed_insert(struct declaration_enum *enum_declaration,
                        start = end;
                        end = tmp;
                }
-               enum_signed_insert_range_to_quark(enum_declaration, start, end, q);
+               bt_enum_signed_insert_range_to_quark(enum_declaration, start, end, q);
        }
 
        array = g_hash_table_lookup(enum_declaration->table.quark_to_range_set,
@@ -333,7 +333,7 @@ void enum_signed_insert(struct declaration_enum *enum_declaration,
        range->end._signed = end;
 }
 
-void enum_unsigned_insert(struct declaration_enum *enum_declaration,
+void bt_enum_unsigned_insert(struct declaration_enum *enum_declaration,
                          uint64_t start, uint64_t end, GQuark q)
 {
        GArray *array;
@@ -341,7 +341,7 @@ void enum_unsigned_insert(struct declaration_enum *enum_declaration,
 
 
        if (start == end) {
-               enum_unsigned_insert_value_to_quark_set(enum_declaration, start, q);
+               bt_enum_unsigned_insert_value_to_quark_set(enum_declaration, start, q);
        } else {
                if (start > end) {
                        uint64_t tmp;
@@ -350,7 +350,7 @@ void enum_unsigned_insert(struct declaration_enum *enum_declaration,
                        start = end;
                        end = tmp;
                }
-               enum_unsigned_insert_range_to_quark(enum_declaration, start, end, q);
+               bt_enum_unsigned_insert_range_to_quark(enum_declaration, start, end, q);
        }
 
        array = g_hash_table_lookup(enum_declaration->table.quark_to_range_set,
@@ -368,13 +368,13 @@ void enum_unsigned_insert(struct declaration_enum *enum_declaration,
        range->end._unsigned = end;
 }
 
-size_t enum_get_nr_enumerators(struct declaration_enum *enum_declaration)
+size_t bt_enum_get_nr_enumerators(struct declaration_enum *enum_declaration)
 {
        return g_hash_table_size(enum_declaration->table.quark_to_range_set);
 }
 
 static
-void _enum_declaration_free(struct declaration *declaration)
+void _enum_declaration_free(struct bt_declaration *declaration)
 {
        struct declaration_enum *enum_declaration =
                container_of(declaration, struct declaration_enum, p);
@@ -386,12 +386,12 @@ void _enum_declaration_free(struct declaration *declaration)
                g_free(iter);
        }
        g_hash_table_destroy(enum_declaration->table.quark_to_range_set);
-       declaration_unref(&enum_declaration->integer_declaration->p);
+       bt_declaration_unref(&enum_declaration->integer_declaration->p);
        g_free(enum_declaration);
 }
 
 struct declaration_enum *
-       enum_declaration_new(struct declaration_integer *integer_declaration)
+       bt_enum_declaration_new(struct declaration_integer *integer_declaration)
 {
        struct declaration_enum *enum_declaration;
 
@@ -405,7 +405,7 @@ struct declaration_enum *
        enum_declaration->table.quark_to_range_set = g_hash_table_new_full(g_direct_hash,
                                                        g_direct_equal,
                                                        NULL, enum_range_set_free);
-       declaration_ref(&integer_declaration->p);
+       bt_declaration_ref(&integer_declaration->p);
        enum_declaration->integer_declaration = integer_declaration;
        enum_declaration->p.id = CTF_TYPE_ENUM;
        enum_declaration->p.alignment = 1;
@@ -417,8 +417,8 @@ struct declaration_enum *
 }
 
 static
-struct definition *
-       _enum_definition_new(struct declaration *declaration,
+struct bt_definition *
+       _enum_definition_new(struct bt_declaration *declaration,
                             struct definition_scope *parent_scope,
                             GQuark field_name, int index,
                             const char *root_name)
@@ -426,11 +426,11 @@ struct definition *
        struct declaration_enum *enum_declaration =
                container_of(declaration, struct declaration_enum, p);
        struct definition_enum *_enum;
-       struct definition *definition_integer_parent;
+       struct bt_definition *definition_integer_parent;
        int ret;
 
        _enum = g_new(struct definition_enum, 1);
-       declaration_ref(&enum_declaration->p);
+       bt_declaration_ref(&enum_declaration->p);
        _enum->p.declaration = declaration;
        _enum->declaration = enum_declaration;
        _enum->p.ref = 1;
@@ -440,10 +440,10 @@ struct definition *
         */
        _enum->p.index = root_name ? INT_MAX : index;
        _enum->p.name = field_name;
-       _enum->p.path = new_definition_path(parent_scope, field_name, root_name);
-       _enum->p.scope = new_definition_scope(parent_scope, field_name, root_name);
+       _enum->p.path = bt_new_definition_path(parent_scope, field_name, root_name);
+       _enum->p.scope = bt_new_definition_scope(parent_scope, field_name, root_name);
        _enum->value = NULL;
-       ret = register_field_definition(field_name, &_enum->p,
+       ret = bt_register_field_definition(field_name, &_enum->p,
                                        parent_scope);
        assert(!ret);
        definition_integer_parent =
@@ -456,14 +456,14 @@ struct definition *
 }
 
 static
-void _enum_definition_free(struct definition *definition)
+void _enum_definition_free(struct bt_definition *definition)
 {
        struct definition_enum *_enum =
                container_of(definition, struct definition_enum, p);
 
-       definition_unref(&_enum->integer->p);
-       free_definition_scope(_enum->p.scope);
-       declaration_unref(_enum->p.declaration);
+       bt_definition_unref(&_enum->integer->p);
+       bt_free_definition_scope(_enum->p.scope);
+       bt_declaration_unref(_enum->p.declaration);
        if (_enum->value)
                g_array_unref(_enum->value);
        g_free(_enum);
index 028749bc92a177f91237283797a234a65fd21284..3b61f8faf0a3ec16b0b95b6544cd058cdabd008e 100644 (file)
 #include <babeltrace/endian.h>
 
 static
-struct definition *_float_definition_new(struct declaration *declaration,
+struct bt_definition *_float_definition_new(struct bt_declaration *declaration,
                                   struct definition_scope *parent_scope,
                                   GQuark field_name, int index,
                                   const char *root_name);
 static
-void _float_definition_free(struct definition *definition);
+void _float_definition_free(struct bt_definition *definition);
 
 static
-void _float_declaration_free(struct declaration *declaration)
+void _float_declaration_free(struct bt_declaration *declaration)
 {
        struct declaration_float *float_declaration =
                container_of(declaration, struct declaration_float, p);
 
-       declaration_unref(&float_declaration->exp->p);
-       declaration_unref(&float_declaration->mantissa->p);
-       declaration_unref(&float_declaration->sign->p);
+       bt_declaration_unref(&float_declaration->exp->p);
+       bt_declaration_unref(&float_declaration->mantissa->p);
+       bt_declaration_unref(&float_declaration->sign->p);
        g_free(float_declaration);
 }
 
 struct declaration_float *
-       float_declaration_new(size_t mantissa_len,
+       bt_float_declaration_new(size_t mantissa_len,
                       size_t exp_len, int byte_order, size_t alignment)
 {
        struct declaration_float *float_declaration;
-       struct declaration *declaration;
+       struct bt_declaration *declaration;
 
        float_declaration = g_new(struct declaration_float, 1);
        declaration = &float_declaration->p;
@@ -68,21 +68,21 @@ struct declaration_float *
        declaration->ref = 1;
        float_declaration->byte_order = byte_order;
 
-       float_declaration->sign = integer_declaration_new(1,
+       float_declaration->sign = bt_integer_declaration_new(1,
                                                byte_order, false, 1, 2,
                                                CTF_STRING_NONE, NULL);
-       float_declaration->mantissa = integer_declaration_new(mantissa_len - 1,
+       float_declaration->mantissa = bt_integer_declaration_new(mantissa_len - 1,
                                                byte_order, false, 1, 10,
                                                CTF_STRING_NONE, NULL);
-       float_declaration->exp = integer_declaration_new(exp_len,
+       float_declaration->exp = bt_integer_declaration_new(exp_len,
                                                byte_order, true, 1, 10,
                                                CTF_STRING_NONE, NULL);
        return float_declaration;
 }
 
 static
-struct definition *
-       _float_definition_new(struct declaration *declaration,
+struct bt_definition *
+       _float_definition_new(struct bt_declaration *declaration,
                              struct definition_scope *parent_scope,
                              GQuark field_name, int index,
                              const char *root_name)
@@ -90,14 +90,14 @@ struct definition *
        struct declaration_float *float_declaration =
                container_of(declaration, struct declaration_float, p);
        struct definition_float *_float;
-       struct definition *tmp;
+       struct bt_definition *tmp;
 
        _float = g_new(struct definition_float, 1);
-       declaration_ref(&float_declaration->p);
+       bt_declaration_ref(&float_declaration->p);
        _float->p.declaration = declaration;
        _float->declaration = float_declaration;
-       _float->p.scope = new_definition_scope(parent_scope, field_name, root_name);
-       _float->p.path = new_definition_path(parent_scope, field_name, root_name);
+       _float->p.scope = bt_new_definition_scope(parent_scope, field_name, root_name);
+       _float->p.path = bt_new_definition_path(parent_scope, field_name, root_name);
        if (float_declaration->byte_order == LITTLE_ENDIAN) {
                tmp = float_declaration->mantissa->p.definition_new(&float_declaration->mantissa->p,
                        _float->p.scope, g_quark_from_static_string("mantissa"), 0, NULL);
@@ -130,7 +130,7 @@ struct definition *
        if (parent_scope) {
                int ret;
 
-               ret = register_field_definition(field_name, &_float->p,
+               ret = bt_register_field_definition(field_name, &_float->p,
                                                parent_scope);
                assert(!ret);
        }
@@ -138,15 +138,15 @@ struct definition *
 }
 
 static
-void _float_definition_free(struct definition *definition)
+void _float_definition_free(struct bt_definition *definition)
 {
        struct definition_float *_float =
                container_of(definition, struct definition_float, p);
 
-       definition_unref(&_float->sign->p);
-       definition_unref(&_float->exp->p);
-       definition_unref(&_float->mantissa->p);
-       free_definition_scope(_float->p.scope);
-       declaration_unref(_float->p.declaration);
+       bt_definition_unref(&_float->sign->p);
+       bt_definition_unref(&_float->exp->p);
+       bt_definition_unref(&_float->mantissa->p);
+       bt_free_definition_scope(_float->p.scope);
+       bt_declaration_unref(_float->p.declaration);
        g_free(_float);
 }
index 337641d7a3123018f14fc3f933285da8d35484ad..73d4f2a40116141e173b4cea0532b4cfd0b7b433 100644 (file)
 #include <stdint.h>
 
 static
-struct definition *_integer_definition_new(struct declaration *declaration,
+struct bt_definition *_integer_definition_new(struct bt_declaration *declaration,
                               struct definition_scope *parent_scope,
                               GQuark field_name, int index,
                               const char *root_name);
 static
-void _integer_definition_free(struct definition *definition);
+void _integer_definition_free(struct bt_definition *definition);
 
 static
-void _integer_declaration_free(struct declaration *declaration)
+void _integer_declaration_free(struct bt_declaration *declaration)
 {
        struct declaration_integer *integer_declaration =
                container_of(declaration, struct declaration_integer, p);
@@ -49,7 +49,7 @@ void _integer_declaration_free(struct declaration *declaration)
 }
 
 struct declaration_integer *
-       integer_declaration_new(size_t len, int byte_order,
+       bt_integer_declaration_new(size_t len, int byte_order,
                         int signedness, size_t alignment, int base,
                         enum ctf_string_encoding encoding,
                         struct ctf_clock *clock)
@@ -73,8 +73,8 @@ struct declaration_integer *
 }
 
 static
-struct definition *
-       _integer_definition_new(struct declaration *declaration,
+struct bt_definition *
+       _integer_definition_new(struct bt_declaration *declaration,
                                struct definition_scope *parent_scope,
                                GQuark field_name, int index,
                                const char *root_name)
@@ -85,7 +85,7 @@ struct definition *
        int ret;
 
        integer = g_new(struct definition_integer, 1);
-       declaration_ref(&integer_declaration->p);
+       bt_declaration_ref(&integer_declaration->p);
        integer->p.declaration = declaration;
        integer->declaration = integer_declaration;
        integer->p.ref = 1;
@@ -95,27 +95,27 @@ struct definition *
         */
        integer->p.index = root_name ? INT_MAX : index;
        integer->p.name = field_name;
-       integer->p.path = new_definition_path(parent_scope, field_name,
+       integer->p.path = bt_new_definition_path(parent_scope, field_name,
                                        root_name);
        integer->p.scope = NULL;
        integer->value._unsigned = 0;
-       ret = register_field_definition(field_name, &integer->p,
+       ret = bt_register_field_definition(field_name, &integer->p,
                                        parent_scope);
        assert(!ret);
        return &integer->p;
 }
 
 static
-void _integer_definition_free(struct definition *definition)
+void _integer_definition_free(struct bt_definition *definition)
 {
        struct definition_integer *integer =
                container_of(definition, struct definition_integer, p);
 
-       declaration_unref(integer->p.declaration);
+       bt_declaration_unref(integer->p.declaration);
        g_free(integer);
 }
 
-enum ctf_string_encoding get_int_encoding(const struct definition *field)
+enum ctf_string_encoding bt_get_int_encoding(const struct bt_definition *field)
 {
        struct definition_integer *integer_definition;
        const struct declaration_integer *integer_declaration;
@@ -126,7 +126,7 @@ enum ctf_string_encoding get_int_encoding(const struct definition *field)
        return integer_declaration->encoding;
 }
 
-int get_int_base(const struct definition *field)
+int bt_get_int_base(const struct bt_definition *field)
 {
        struct definition_integer *integer_definition;
        const struct declaration_integer *integer_declaration;
@@ -137,7 +137,7 @@ int get_int_base(const struct definition *field)
        return integer_declaration->base;
 }
 
-size_t get_int_len(const struct definition *field)
+size_t bt_get_int_len(const struct bt_definition *field)
 {
        struct definition_integer *integer_definition;
        const struct declaration_integer *integer_declaration;
@@ -148,7 +148,7 @@ size_t get_int_len(const struct definition *field)
        return integer_declaration->len;
 }
 
-int get_int_byte_order(const struct definition *field)
+int bt_get_int_byte_order(const struct bt_definition *field)
 {
        struct definition_integer *integer_definition;
        const struct declaration_integer *integer_declaration;
@@ -159,7 +159,7 @@ int get_int_byte_order(const struct definition *field)
        return integer_declaration->byte_order;
 }
 
-int get_int_signedness(const struct definition *field)
+int bt_get_int_signedness(const struct bt_definition *field)
 {
        struct definition_integer *integer_definition;
        const struct declaration_integer *integer_declaration;
@@ -170,7 +170,7 @@ int get_int_signedness(const struct definition *field)
        return integer_declaration->signedness;
 }
 
-uint64_t get_unsigned_int(const struct definition *field)
+uint64_t bt_get_unsigned_int(const struct bt_definition *field)
 {
        struct definition_integer *integer_definition;
        const struct declaration_integer *integer_declaration;
@@ -186,7 +186,7 @@ uint64_t get_unsigned_int(const struct definition *field)
        return (uint64_t)integer_definition->value._signed;
 }
 
-int64_t get_signed_int(const struct definition *field)
+int64_t bt_get_signed_int(const struct bt_definition *field)
 {
        struct definition_integer *integer_definition;
        const struct declaration_integer *integer_declaration;
index 0e84b1d18ceb092fe28af8c45ce1eb8a9fcba23c..6c61ef7a0c55b70761cbf98f1830eb3553d0ae3a 100644 (file)
 #include <inttypes.h>
 
 static
-struct definition *_sequence_definition_new(struct declaration *declaration,
+struct bt_definition *_sequence_definition_new(struct bt_declaration *declaration,
                                        struct definition_scope *parent_scope,
                                        GQuark field_name, int index,
                                        const char *root_name);
 static
-void _sequence_definition_free(struct definition *definition);
+void _sequence_definition_free(struct bt_definition *definition);
 
-int sequence_rw(struct stream_pos *pos, struct definition *definition)
+int bt_sequence_rw(struct bt_stream_pos *pos, struct bt_definition *definition)
 {
        struct definition_sequence *sequence_definition =
                container_of(definition, struct definition_sequence, p);
@@ -62,7 +62,7 @@ int sequence_rw(struct stream_pos *pos, struct definition *definition)
                g_ptr_array_set_size(sequence_definition->elems, len);
 
        for (i = oldlen; i < len; i++) {
-               struct definition **field;
+               struct bt_definition **field;
                GString *str;
                GQuark name;
 
@@ -71,15 +71,15 @@ int sequence_rw(struct stream_pos *pos, struct definition *definition)
                name = g_quark_from_string(str->str);
                (void) g_string_free(str, TRUE);
 
-               field = (struct definition **) &g_ptr_array_index(sequence_definition->elems, i);
+               field = (struct bt_definition **) &g_ptr_array_index(sequence_definition->elems, i);
                *field = sequence_declaration->elem->definition_new(sequence_declaration->elem,
                                          sequence_definition->p.scope,
                                          name, i, NULL);
        }
        for (i = 0; i < len; i++) {
-               struct definition **field;
+               struct bt_definition **field;
 
-               field = (struct definition **) &g_ptr_array_index(sequence_definition->elems, i);
+               field = (struct bt_definition **) &g_ptr_array_index(sequence_definition->elems, i);
                ret = generic_rw(pos, *field);
                if (ret)
                        return ret;
@@ -88,34 +88,34 @@ int sequence_rw(struct stream_pos *pos, struct definition *definition)
 }
 
 static
-void _sequence_declaration_free(struct declaration *declaration)
+void _sequence_declaration_free(struct bt_declaration *declaration)
 {
        struct declaration_sequence *sequence_declaration =
                container_of(declaration, struct declaration_sequence, p);
 
-       free_declaration_scope(sequence_declaration->scope);
+       bt_free_declaration_scope(sequence_declaration->scope);
        g_array_free(sequence_declaration->length_name, TRUE);
-       declaration_unref(sequence_declaration->elem);
+       bt_declaration_unref(sequence_declaration->elem);
        g_free(sequence_declaration);
 }
 
 struct declaration_sequence *
-       sequence_declaration_new(const char *length,
-                         struct declaration *elem_declaration,
+       bt_sequence_declaration_new(const char *length,
+                         struct bt_declaration *elem_declaration,
                          struct declaration_scope *parent_scope)
 {
        struct declaration_sequence *sequence_declaration;
-       struct declaration *declaration;
+       struct bt_declaration *declaration;
 
        sequence_declaration = g_new(struct declaration_sequence, 1);
        declaration = &sequence_declaration->p;
 
        sequence_declaration->length_name = g_array_new(FALSE, TRUE, sizeof(GQuark));
-       append_scope_path(length, sequence_declaration->length_name);
+       bt_append_scope_path(length, sequence_declaration->length_name);
 
-       declaration_ref(elem_declaration);
+       bt_declaration_ref(elem_declaration);
        sequence_declaration->elem = elem_declaration;
-       sequence_declaration->scope = new_declaration_scope(parent_scope);
+       sequence_declaration->scope = bt_new_declaration_scope(parent_scope);
        declaration->id = CTF_TYPE_SEQUENCE;
        declaration->alignment = elem_declaration->alignment;
        declaration->declaration_free = _sequence_declaration_free;
@@ -126,7 +126,7 @@ struct declaration_sequence *
 }
 
 static
-struct definition *_sequence_definition_new(struct declaration *declaration,
+struct bt_definition *_sequence_definition_new(struct bt_declaration *declaration,
                                struct definition_scope *parent_scope,
                                GQuark field_name, int index,
                                const char *root_name)
@@ -134,11 +134,11 @@ struct definition *_sequence_definition_new(struct declaration *declaration,
        struct declaration_sequence *sequence_declaration =
                container_of(declaration, struct declaration_sequence, p);
        struct definition_sequence *sequence;
-       struct definition *len_parent;
+       struct bt_definition *len_parent;
        int ret;
 
        sequence = g_new(struct definition_sequence, 1);
-       declaration_ref(&sequence_declaration->p);
+       bt_declaration_ref(&sequence_declaration->p);
        sequence->p.declaration = declaration;
        sequence->declaration = sequence_declaration;
        sequence->p.ref = 1;
@@ -148,12 +148,12 @@ struct definition *_sequence_definition_new(struct declaration *declaration,
         */
        sequence->p.index = root_name ? INT_MAX : index;
        sequence->p.name = field_name;
-       sequence->p.path = new_definition_path(parent_scope, field_name, root_name);
-       sequence->p.scope = new_definition_scope(parent_scope, field_name, root_name);
-       ret = register_field_definition(field_name, &sequence->p,
+       sequence->p.path = bt_new_definition_path(parent_scope, field_name, root_name);
+       sequence->p.scope = bt_new_definition_scope(parent_scope, field_name, root_name);
+       ret = bt_register_field_definition(field_name, &sequence->p,
                                        parent_scope);
        assert(!ret);
-       len_parent = lookup_path_definition(sequence->p.scope->scope_path,
+       len_parent = bt_lookup_path_definition(sequence->p.scope->scope_path,
                                            sequence_declaration->length_name,
                                            parent_scope);
        if (!len_parent) {
@@ -166,7 +166,7 @@ struct definition *_sequence_definition_new(struct declaration *declaration,
                printf("[error] Sequence length field should be unsigned.\n");
                goto error;
        }
-       definition_ref(len_parent);
+       bt_definition_ref(len_parent);
 
        sequence->string = NULL;
        sequence->elems = NULL;
@@ -191,43 +191,43 @@ struct definition *_sequence_definition_new(struct declaration *declaration,
        return &sequence->p;
 
 error:
-       free_definition_scope(sequence->p.scope);
-       declaration_unref(&sequence_declaration->p);
+       bt_free_definition_scope(sequence->p.scope);
+       bt_declaration_unref(&sequence_declaration->p);
        g_free(sequence);
        return NULL;
 }
 
 static
-void _sequence_definition_free(struct definition *definition)
+void _sequence_definition_free(struct bt_definition *definition)
 {
        struct definition_sequence *sequence =
                container_of(definition, struct definition_sequence, p);
-       struct definition *len_definition = &sequence->length->p;
+       struct bt_definition *len_definition = &sequence->length->p;
        uint64_t i;
 
        if (sequence->string)
                (void) g_string_free(sequence->string, TRUE);
        if (sequence->elems) {
                for (i = 0; i < sequence->elems->len; i++) {
-                       struct definition *field;
+                       struct bt_definition *field;
 
                        field = g_ptr_array_index(sequence->elems, i);
                        field->declaration->definition_free(field);
                }
                (void) g_ptr_array_free(sequence->elems, TRUE);
        }
-       definition_unref(len_definition);
-       free_definition_scope(sequence->p.scope);
-       declaration_unref(sequence->p.declaration);
+       bt_definition_unref(len_definition);
+       bt_free_definition_scope(sequence->p.scope);
+       bt_declaration_unref(sequence->p.declaration);
        g_free(sequence);
 }
 
-uint64_t sequence_len(struct definition_sequence *sequence)
+uint64_t bt_sequence_len(struct definition_sequence *sequence)
 {
        return sequence->length->value._unsigned;
 }
 
-struct definition *sequence_index(struct definition_sequence *sequence, uint64_t i)
+struct bt_definition *bt_sequence_index(struct definition_sequence *sequence, uint64_t i)
 {
        if (!sequence->elems)
                return NULL;
index 4860740616ae97631c1a0c61ffd6f61a10ef8220..5bbba98c8c047c7cb574126b97191a6b5d23f9de 100644 (file)
 #include <babeltrace/types.h>
 
 static
-struct definition *_string_definition_new(struct declaration *declaration,
+struct bt_definition *_string_definition_new(struct bt_declaration *declaration,
                                struct definition_scope *parent_scope,
                                GQuark field_name, int index,
                                const char *root_name);
 static
-void _string_definition_free(struct definition *definition);
+void _string_definition_free(struct bt_definition *definition);
 
 static
-void _string_declaration_free(struct declaration *declaration)
+void _string_declaration_free(struct bt_declaration *declaration)
 {
        struct declaration_string *string_declaration =
                container_of(declaration, struct declaration_string, p);
@@ -48,7 +48,7 @@ void _string_declaration_free(struct declaration *declaration)
 }
 
 struct declaration_string *
-       string_declaration_new(enum ctf_string_encoding encoding)
+       bt_string_declaration_new(enum ctf_string_encoding encoding)
 {
        struct declaration_string *string_declaration;
 
@@ -64,8 +64,8 @@ struct declaration_string *
 }
 
 static
-struct definition *
-       _string_definition_new(struct declaration *declaration,
+struct bt_definition *
+       _string_definition_new(struct bt_declaration *declaration,
                               struct definition_scope *parent_scope,
                               GQuark field_name, int index,
                               const char *root_name)
@@ -76,7 +76,7 @@ struct definition *
        int ret;
 
        string = g_new(struct definition_string, 1);
-       declaration_ref(&string_declaration->p);
+       bt_declaration_ref(&string_declaration->p);
        string->p.declaration = declaration;
        string->declaration = string_declaration;
        string->p.ref = 1;
@@ -86,30 +86,30 @@ struct definition *
         */
        string->p.index = root_name ? INT_MAX : index;
        string->p.name = field_name;
-       string->p.path = new_definition_path(parent_scope, field_name,
+       string->p.path = bt_new_definition_path(parent_scope, field_name,
                                        root_name);
        string->p.scope = NULL;
        string->value = NULL;
        string->len = 0;
        string->alloc_len = 0;
-       ret = register_field_definition(field_name, &string->p,
+       ret = bt_register_field_definition(field_name, &string->p,
                                        parent_scope);
        assert(!ret);
        return &string->p;
 }
 
 static
-void _string_definition_free(struct definition *definition)
+void _string_definition_free(struct bt_definition *definition)
 {
        struct definition_string *string =
                container_of(definition, struct definition_string, p);
 
-       declaration_unref(string->p.declaration);
+       bt_declaration_unref(string->p.declaration);
        g_free(string->value);
        g_free(string);
 }
 
-enum ctf_string_encoding get_string_encoding(const struct definition *field)
+enum ctf_string_encoding bt_get_string_encoding(const struct bt_definition *field)
 {
        struct definition_string *string_definition;
        const struct declaration_string *string_declaration;
@@ -120,7 +120,7 @@ enum ctf_string_encoding get_string_encoding(const struct definition *field)
        return string_declaration->encoding;
 }
 
-char *get_string(const struct definition *field)
+char *bt_get_string(const struct bt_definition *field)
 {
        struct definition_string *string_definition =
                container_of(field, struct definition_string, p);
index 138da167509ae25c8cf0f218b4ca5ccfeaf63978..b9fb6799b938dad37f6788c5bb14cafda8fa571d 100644 (file)
 #endif
 
 static
-struct definition *_struct_definition_new(struct declaration *declaration,
+struct bt_definition *_struct_definition_new(struct bt_declaration *declaration,
                                struct definition_scope *parent_scope,
                                GQuark field_name, int index,
                                const char *root_name);
 static
-void _struct_definition_free(struct definition *definition);
+void _struct_definition_free(struct bt_definition *definition);
 
-int struct_rw(struct stream_pos *ppos, struct definition *definition)
+int bt_struct_rw(struct bt_stream_pos *ppos, struct bt_definition *definition)
 {
        struct definition_struct *struct_definition =
                container_of(definition, struct definition_struct, p);
@@ -51,7 +51,7 @@ int struct_rw(struct stream_pos *ppos, struct definition *definition)
        int ret;
 
        for (i = 0; i < struct_definition->fields->len; i++) {
-               struct definition *field =
+               struct bt_definition *field =
                        g_ptr_array_index(struct_definition->fields, i);
                ret = generic_rw(ppos, field);
                if (ret)
@@ -61,31 +61,31 @@ int struct_rw(struct stream_pos *ppos, struct definition *definition)
 }
 
 static
-void _struct_declaration_free(struct declaration *declaration)
+void _struct_declaration_free(struct bt_declaration *declaration)
 {
        struct declaration_struct *struct_declaration =
                container_of(declaration, struct declaration_struct, p);
        unsigned long i;
 
-       free_declaration_scope(struct_declaration->scope);
+       bt_free_declaration_scope(struct_declaration->scope);
        g_hash_table_destroy(struct_declaration->fields_by_name);
 
        for (i = 0; i < struct_declaration->fields->len; i++) {
                struct declaration_field *declaration_field =
                        &g_array_index(struct_declaration->fields,
                                       struct declaration_field, i);
-               declaration_unref(declaration_field->declaration);
+               bt_declaration_unref(declaration_field->declaration);
        }
        g_array_free(struct_declaration->fields, true);
        g_free(struct_declaration);
 }
 
 struct declaration_struct *
-       struct_declaration_new(struct declaration_scope *parent_scope,
+       bt_struct_declaration_new(struct declaration_scope *parent_scope,
                               uint64_t min_align)
 {
        struct declaration_struct *struct_declaration;
-       struct declaration *declaration;
+       struct bt_declaration *declaration;
 
        struct_declaration = g_new(struct declaration_struct, 1);
        declaration = &struct_declaration->p;
@@ -94,7 +94,7 @@ struct declaration_struct *
        struct_declaration->fields = g_array_sized_new(FALSE, TRUE,
                                                sizeof(struct declaration_field),
                                                DEFAULT_NR_STRUCT_FIELDS);
-       struct_declaration->scope = new_declaration_scope(parent_scope);
+       struct_declaration->scope = bt_new_declaration_scope(parent_scope);
        declaration->id = CTF_TYPE_STRUCT;
        declaration->alignment = max(1, min_align);
        declaration->declaration_free = _struct_declaration_free;
@@ -105,8 +105,8 @@ struct declaration_struct *
 }
 
 static
-struct definition *
-       _struct_definition_new(struct declaration *declaration,
+struct bt_definition *
+       _struct_definition_new(struct bt_declaration *declaration,
                               struct definition_scope *parent_scope,
                               GQuark field_name, int index,
                               const char *root_name)
@@ -118,7 +118,7 @@ struct definition *
        int ret;
 
        _struct = g_new(struct definition_struct, 1);
-       declaration_ref(&struct_declaration->p);
+       bt_declaration_ref(&struct_declaration->p);
        _struct->p.declaration = declaration;
        _struct->declaration = struct_declaration;
        _struct->p.ref = 1;
@@ -128,10 +128,10 @@ struct definition *
         */
        _struct->p.index = root_name ? INT_MAX : index;
        _struct->p.name = field_name;
-       _struct->p.path = new_definition_path(parent_scope, field_name, root_name);
-       _struct->p.scope = new_definition_scope(parent_scope, field_name, root_name);
+       _struct->p.path = bt_new_definition_path(parent_scope, field_name, root_name);
+       _struct->p.scope = bt_new_definition_scope(parent_scope, field_name, root_name);
 
-       ret = register_field_definition(field_name, &_struct->p,
+       ret = bt_register_field_definition(field_name, &_struct->p,
                                        parent_scope);
        assert(!ret || ret == -EPERM);
 
@@ -141,8 +141,8 @@ struct definition *
                struct declaration_field *declaration_field =
                        &g_array_index(struct_declaration->fields,
                                       struct declaration_field, i);
-               struct definition **field =
-                       (struct definition **) &g_ptr_array_index(_struct->fields, i);
+               struct bt_definition **field =
+                       (struct bt_definition **) &g_ptr_array_index(_struct->fields, i);
 
                *field = declaration_field->declaration->definition_new(declaration_field->declaration,
                                                          _struct->p.scope,
@@ -154,17 +154,17 @@ struct definition *
 
 error:
        for (i--; i >= 0; i--) {
-               struct definition *field = g_ptr_array_index(_struct->fields, i);
-               definition_unref(field);
+               struct bt_definition *field = g_ptr_array_index(_struct->fields, i);
+               bt_definition_unref(field);
        }
-       free_definition_scope(_struct->p.scope);
-       declaration_unref(&struct_declaration->p);
+       bt_free_definition_scope(_struct->p.scope);
+       bt_declaration_unref(&struct_declaration->p);
        g_free(_struct);
        return NULL;
 }
 
 static
-void _struct_definition_free(struct definition *definition)
+void _struct_definition_free(struct bt_definition *definition)
 {
        struct definition_struct *_struct =
                container_of(definition, struct definition_struct, p);
@@ -172,18 +172,18 @@ void _struct_definition_free(struct definition *definition)
 
        assert(_struct->fields->len == _struct->declaration->fields->len);
        for (i = 0; i < _struct->fields->len; i++) {
-               struct definition *field = g_ptr_array_index(_struct->fields, i);
-               definition_unref(field);
+               struct bt_definition *field = g_ptr_array_index(_struct->fields, i);
+               bt_definition_unref(field);
        }
-       free_definition_scope(_struct->p.scope);
-       declaration_unref(_struct->p.declaration);
+       bt_free_definition_scope(_struct->p.scope);
+       bt_declaration_unref(_struct->p.declaration);
        g_ptr_array_free(_struct->fields, TRUE);
        g_free(_struct);
 }
 
-void struct_declaration_add_field(struct declaration_struct *struct_declaration,
+void bt_struct_declaration_add_field(struct declaration_struct *struct_declaration,
                           const char *field_name,
-                          struct declaration *field_declaration)
+                          struct bt_declaration *field_declaration)
 {
        struct declaration_field *field;
        unsigned long index;
@@ -192,7 +192,7 @@ void struct_declaration_add_field(struct declaration_struct *struct_declaration,
        index = struct_declaration->fields->len - 1;    /* last field (new) */
        field = &g_array_index(struct_declaration->fields, struct declaration_field, index);
        field->name = g_quark_from_string(field_name);
-       declaration_ref(field_declaration);
+       bt_declaration_ref(field_declaration);
        field->declaration = field_declaration;
        /* Keep index in hash rather than pointer, because array can relocate */
        g_hash_table_insert(struct_declaration->fields_by_name,
@@ -207,12 +207,12 @@ void struct_declaration_add_field(struct declaration_struct *struct_declaration,
 }
 
 /*
- * struct_declaration_lookup_field_index - returns field index
+ * bt_struct_declaration_lookup_field_index - returns field index
  *
  * Returns the index of a field in a structure, or -1 if it does not
  * exist.
  */
-int struct_declaration_lookup_field_index(struct declaration_struct *struct_declaration,
+int bt_struct_declaration_lookup_field_index(struct declaration_struct *struct_declaration,
                                       GQuark field_name)
 {
        gpointer index;
@@ -230,7 +230,7 @@ int struct_declaration_lookup_field_index(struct declaration_struct *struct_decl
  * field returned only valid as long as the field structure is not appended to.
  */
 struct declaration_field *
-       struct_declaration_get_field_from_index(struct declaration_struct *struct_declaration,
+       bt_struct_declaration_get_field_from_index(struct declaration_struct *struct_declaration,
                                         int index)
 {
        if (index < 0)
@@ -241,8 +241,8 @@ struct declaration_field *
 /*
  * field returned only valid as long as the field structure is not appended to.
  */
-struct definition *
-struct_definition_get_field_from_index(struct definition_struct *_struct,
+struct bt_definition *
+bt_struct_definition_get_field_from_index(struct definition_struct *_struct,
                                        int index)
 {
        if (index < 0)
@@ -250,7 +250,7 @@ struct_definition_get_field_from_index(struct definition_struct *_struct,
        return g_ptr_array_index(_struct->fields, index);
 }
 
-uint64_t struct_declaration_len(struct declaration_struct *struct_declaration)
+uint64_t bt_struct_declaration_len(struct declaration_struct *struct_declaration)
 {
        return struct_declaration->fields->len;
 }
index 55990271dccb153a9d0562f23edd672db4c37a26..0d1a89d1946c0146e08ba28ffafcb09fabfa84fc 100644 (file)
@@ -51,21 +51,21 @@ GQuark prefix_quark(const char *prefix, GQuark quark)
 }
 
 static
-struct declaration *
-       lookup_declaration_scope(GQuark declaration_name,
+struct bt_declaration *
+       bt_lookup_declaration_scope(GQuark declaration_name,
                struct declaration_scope *scope)
 {
        return g_hash_table_lookup(scope->typedef_declarations,
                                   (gconstpointer) (unsigned long) declaration_name);
 }
 
-struct declaration *lookup_declaration(GQuark declaration_name,
+struct bt_declaration *bt_lookup_declaration(GQuark declaration_name,
                struct declaration_scope *scope)
 {
-       struct declaration *declaration;
+       struct bt_declaration *declaration;
 
        while (scope) {
-               declaration = lookup_declaration_scope(declaration_name,
+               declaration = bt_lookup_declaration_scope(declaration_name,
                                                       scope);
                if (declaration)
                        return declaration;
@@ -74,25 +74,25 @@ struct declaration *lookup_declaration(GQuark declaration_name,
        return NULL;
 }
 
-int register_declaration(GQuark name, struct declaration *declaration,
+int bt_register_declaration(GQuark name, struct bt_declaration *declaration,
                struct declaration_scope *scope)
 {
        if (!name)
                return -EPERM;
 
        /* Only lookup in local scope */
-       if (lookup_declaration_scope(name, scope))
+       if (bt_lookup_declaration_scope(name, scope))
                return -EEXIST;
 
        g_hash_table_insert(scope->typedef_declarations,
                            (gpointer) (unsigned long) name,
                            declaration);
-       declaration_ref(declaration);
+       bt_declaration_ref(declaration);
        return 0;
 }
 
 static
-struct definition *
+struct bt_definition *
        lookup_field_definition_scope(GQuark field_name,
                struct definition_scope *scope)
 {
@@ -158,7 +158,7 @@ end:
 }
 
 static struct definition_scope *
-       get_definition_scope(const struct definition *definition)
+       get_definition_scope(const struct bt_definition *definition)
 {
        return definition->scope;
 }
@@ -183,12 +183,12 @@ static struct definition_scope *
  * lookup_path: the path leading to the enum we want to look for.
  * scope: the definition scope containing the variant definition.
  */
-struct definition *
-       lookup_path_definition(GArray *cur_path,
+struct bt_definition *
+       bt_lookup_path_definition(GArray *cur_path,
                               GArray *lookup_path,
                               struct definition_scope *scope)
 {
-       struct definition *definition, *lookup_definition;
+       struct bt_definition *definition, *lookup_definition;
        GQuark last;
        int index;
 
@@ -262,7 +262,7 @@ lookup:
        return NULL;
 }
 
-int register_field_definition(GQuark field_name, struct definition *definition,
+int bt_register_field_definition(GQuark field_name, struct bt_definition *definition,
                struct definition_scope *scope)
 {
        if (!scope || !field_name)
@@ -279,12 +279,12 @@ int register_field_definition(GQuark field_name, struct definition *definition,
        return 0;
 }
 
-void declaration_ref(struct declaration *declaration)
+void bt_declaration_ref(struct bt_declaration *declaration)
 {
        declaration->ref++;
 }
 
-void declaration_unref(struct declaration *declaration)
+void bt_declaration_unref(struct bt_declaration *declaration)
 {
        if (!declaration)
                return;
@@ -292,12 +292,12 @@ void declaration_unref(struct declaration *declaration)
                declaration->declaration_free(declaration);
 }
 
-void definition_ref(struct definition *definition)
+void bt_definition_ref(struct bt_definition *definition)
 {
        definition->ref++;
 }
 
-void definition_unref(struct definition *definition)
+void bt_definition_unref(struct bt_definition *definition)
 {
        if (!definition)
                return;
@@ -306,27 +306,27 @@ void definition_unref(struct definition *definition)
 }
 
 struct declaration_scope *
-       new_declaration_scope(struct declaration_scope *parent_scope)
+       bt_new_declaration_scope(struct declaration_scope *parent_scope)
 {
        struct declaration_scope *scope = g_new(struct declaration_scope, 1);
 
        scope->typedef_declarations = g_hash_table_new_full(g_direct_hash,
                                        g_direct_equal, NULL,
-                                       (GDestroyNotify) declaration_unref);
+                                       (GDestroyNotify) bt_declaration_unref);
        scope->struct_declarations = g_hash_table_new_full(g_direct_hash,
                                        g_direct_equal, NULL,
-                                       (GDestroyNotify) declaration_unref);
+                                       (GDestroyNotify) bt_declaration_unref);
        scope->variant_declarations = g_hash_table_new_full(g_direct_hash,
                                        g_direct_equal, NULL,
-                                       (GDestroyNotify) declaration_unref);
+                                       (GDestroyNotify) bt_declaration_unref);
        scope->enum_declarations = g_hash_table_new_full(g_direct_hash,
                                        g_direct_equal, NULL,
-                                       (GDestroyNotify) declaration_unref);
+                                       (GDestroyNotify) bt_declaration_unref);
        scope->parent_scope = parent_scope;
        return scope;
 }
 
-void free_declaration_scope(struct declaration_scope *scope)
+void bt_free_declaration_scope(struct declaration_scope *scope)
 {
        g_hash_table_destroy(scope->enum_declarations);
        g_hash_table_destroy(scope->variant_declarations);
@@ -336,20 +336,20 @@ void free_declaration_scope(struct declaration_scope *scope)
 }
 
 static
-struct declaration_struct *lookup_struct_declaration_scope(GQuark struct_name,
+struct declaration_struct *bt_lookup_struct_declaration_scope(GQuark struct_name,
                                             struct declaration_scope *scope)
 {
        return g_hash_table_lookup(scope->struct_declarations,
                                   (gconstpointer) (unsigned long) struct_name);
 }
 
-struct declaration_struct *lookup_struct_declaration(GQuark struct_name,
+struct declaration_struct *bt_lookup_struct_declaration(GQuark struct_name,
                                       struct declaration_scope *scope)
 {
        struct declaration_struct *declaration;
 
        while (scope) {
-               declaration = lookup_struct_declaration_scope(struct_name, scope);
+               declaration = bt_lookup_struct_declaration_scope(struct_name, scope);
                if (declaration)
                        return declaration;
                scope = scope->parent_scope;
@@ -357,7 +357,7 @@ struct declaration_struct *lookup_struct_declaration(GQuark struct_name,
        return NULL;
 }
 
-int register_struct_declaration(GQuark struct_name,
+int bt_register_struct_declaration(GQuark struct_name,
        struct declaration_struct *struct_declaration,
        struct declaration_scope *scope)
 {
@@ -368,24 +368,24 @@ int register_struct_declaration(GQuark struct_name,
                return -EPERM;
 
        /* Only lookup in local scope */
-       if (lookup_struct_declaration_scope(struct_name, scope))
+       if (bt_lookup_struct_declaration_scope(struct_name, scope))
                return -EEXIST;
 
        g_hash_table_insert(scope->struct_declarations,
                            (gpointer) (unsigned long) struct_name,
                            struct_declaration);
-       declaration_ref(&struct_declaration->p);
+       bt_declaration_ref(&struct_declaration->p);
 
        /* Also add in typedef/typealias scopes */
        prefix_name = prefix_quark("struct ", struct_name);
-       ret = register_declaration(prefix_name, &struct_declaration->p, scope);
+       ret = bt_register_declaration(prefix_name, &struct_declaration->p, scope);
        assert(!ret);
        return 0;
 }
 
 static
 struct declaration_untagged_variant *
-       lookup_variant_declaration_scope(GQuark variant_name,
+       bt_lookup_variant_declaration_scope(GQuark variant_name,
                struct declaration_scope *scope)
 {
        return g_hash_table_lookup(scope->variant_declarations,
@@ -393,13 +393,13 @@ struct declaration_untagged_variant *
 }
 
 struct declaration_untagged_variant *
-       lookup_variant_declaration(GQuark variant_name,
+       bt_lookup_variant_declaration(GQuark variant_name,
                struct declaration_scope *scope)
 {
        struct declaration_untagged_variant *declaration;
 
        while (scope) {
-               declaration = lookup_variant_declaration_scope(variant_name, scope);
+               declaration = bt_lookup_variant_declaration_scope(variant_name, scope);
                if (declaration)
                        return declaration;
                scope = scope->parent_scope;
@@ -407,7 +407,7 @@ struct declaration_untagged_variant *
        return NULL;
 }
 
-int register_variant_declaration(GQuark variant_name,
+int bt_register_variant_declaration(GQuark variant_name,
                struct declaration_untagged_variant *untagged_variant_declaration,
                struct declaration_scope *scope)
 {
@@ -418,17 +418,17 @@ int register_variant_declaration(GQuark variant_name,
                return -EPERM;
 
        /* Only lookup in local scope */
-       if (lookup_variant_declaration_scope(variant_name, scope))
+       if (bt_lookup_variant_declaration_scope(variant_name, scope))
                return -EEXIST;
 
        g_hash_table_insert(scope->variant_declarations,
                            (gpointer) (unsigned long) variant_name,
                            untagged_variant_declaration);
-       declaration_ref(&untagged_variant_declaration->p);
+       bt_declaration_ref(&untagged_variant_declaration->p);
 
        /* Also add in typedef/typealias scopes */
        prefix_name = prefix_quark("variant ", variant_name);
-       ret = register_declaration(prefix_name,
+       ret = bt_register_declaration(prefix_name,
                        &untagged_variant_declaration->p, scope);
        assert(!ret);
        return 0;
@@ -436,7 +436,7 @@ int register_variant_declaration(GQuark variant_name,
 
 static
 struct declaration_enum *
-       lookup_enum_declaration_scope(GQuark enum_name,
+       bt_lookup_enum_declaration_scope(GQuark enum_name,
                struct declaration_scope *scope)
 {
        return g_hash_table_lookup(scope->enum_declarations,
@@ -444,13 +444,13 @@ struct declaration_enum *
 }
 
 struct declaration_enum *
-       lookup_enum_declaration(GQuark enum_name,
+       bt_lookup_enum_declaration(GQuark enum_name,
                struct declaration_scope *scope)
 {
        struct declaration_enum *declaration;
 
        while (scope) {
-               declaration = lookup_enum_declaration_scope(enum_name, scope);
+               declaration = bt_lookup_enum_declaration_scope(enum_name, scope);
                if (declaration)
                        return declaration;
                scope = scope->parent_scope;
@@ -458,7 +458,7 @@ struct declaration_enum *
        return NULL;
 }
 
-int register_enum_declaration(GQuark enum_name,
+int bt_register_enum_declaration(GQuark enum_name,
                struct declaration_enum *enum_declaration,
                struct declaration_scope *scope)
 {
@@ -469,23 +469,23 @@ int register_enum_declaration(GQuark enum_name,
                return -EPERM;
 
        /* Only lookup in local scope */
-       if (lookup_enum_declaration_scope(enum_name, scope))
+       if (bt_lookup_enum_declaration_scope(enum_name, scope))
                return -EEXIST;
 
        g_hash_table_insert(scope->enum_declarations,
                            (gpointer) (unsigned long) enum_name,
                            enum_declaration);
-       declaration_ref(&enum_declaration->p);
+       bt_declaration_ref(&enum_declaration->p);
 
        /* Also add in typedef/typealias scopes */
        prefix_name = prefix_quark("enum ", enum_name);
-       ret = register_declaration(prefix_name, &enum_declaration->p, scope);
+       ret = bt_register_declaration(prefix_name, &enum_declaration->p, scope);
        assert(!ret);
        return 0;
 }
 
 static struct definition_scope *
-       _new_definition_scope(struct definition_scope *parent_scope,
+       _bt_new_definition_scope(struct definition_scope *parent_scope,
                              int scope_path_len)
 {
        struct definition_scope *scope = g_new(struct definition_scope, 1);
@@ -499,7 +499,7 @@ static struct definition_scope *
        return scope;
 }
 
-GQuark new_definition_path(struct definition_scope *parent_scope,
+GQuark bt_new_definition_path(struct definition_scope *parent_scope,
                           GQuark field_name, const char *root_name)
 {
        GQuark path;
@@ -540,20 +540,20 @@ GQuark new_definition_path(struct definition_scope *parent_scope,
 }
 
 struct definition_scope *
-       new_definition_scope(struct definition_scope *parent_scope,
+       bt_new_definition_scope(struct definition_scope *parent_scope,
                             GQuark field_name, const char *root_name)
 {
        struct definition_scope *scope;
 
        if (root_name) {
-               scope = _new_definition_scope(parent_scope, 0);
-               append_scope_path(root_name, scope->scope_path);
+               scope = _bt_new_definition_scope(parent_scope, 0);
+               bt_append_scope_path(root_name, scope->scope_path);
        } else {
                int scope_path_len = 1;
 
                assert(parent_scope);
                scope_path_len += parent_scope->scope_path->len;
-               scope = _new_definition_scope(parent_scope, scope_path_len);
+               scope = _bt_new_definition_scope(parent_scope, scope_path_len);
                memcpy(scope->scope_path->data, parent_scope->scope_path->data,
                       sizeof(GQuark) * (scope_path_len - 1));
                g_array_index(scope->scope_path, GQuark, scope_path_len - 1) =
@@ -574,7 +574,7 @@ struct definition_scope *
 /*
  * in: path (dot separated), out: q (GArray of GQuark)
  */
-void append_scope_path(const char *path, GArray *q)
+void bt_append_scope_path(const char *path, GArray *q)
 {
        const char *ptrbegin, *ptrend = path;
        GQuark quark;
@@ -605,14 +605,14 @@ void append_scope_path(const char *path, GArray *q)
        }
 }
 
-void free_definition_scope(struct definition_scope *scope)
+void bt_free_definition_scope(struct definition_scope *scope)
 {
        g_array_free(scope->scope_path, TRUE);
        g_hash_table_destroy(scope->definitions);
        g_free(scope);
 }
 
-struct definition *lookup_definition(const struct definition *definition,
+struct bt_definition *bt_lookup_definition(const struct bt_definition *definition,
                                     const char *field_name)
 {
        struct definition_scope *scope = get_definition_scope(definition);
@@ -624,14 +624,14 @@ struct definition *lookup_definition(const struct definition *definition,
                                             scope);
 }
 
-struct definition_integer *lookup_integer(const struct definition *definition,
+struct definition_integer *bt_lookup_integer(const struct bt_definition *definition,
                                          const char *field_name,
                                          int signedness)
 {
-       struct definition *lookup;
+       struct bt_definition *lookup;
        struct definition_integer *lookup_integer;
 
-       lookup = lookup_definition(definition, field_name);
+       lookup = bt_lookup_definition(definition, field_name);
        if (!lookup)
                return NULL;
        if (lookup->declaration->id != CTF_TYPE_INTEGER)
@@ -642,14 +642,14 @@ struct definition_integer *lookup_integer(const struct definition *definition,
        return lookup_integer;
 }
 
-struct definition_enum *lookup_enum(const struct definition *definition,
+struct definition_enum *bt_lookup_enum(const struct bt_definition *definition,
                                    const char *field_name,
                                    int signedness)
 {
-       struct definition *lookup;
+       struct bt_definition *lookup;
        struct definition_enum *lookup_enum;
 
-       lookup = lookup_definition(definition, field_name);
+       lookup = bt_lookup_definition(definition, field_name);
        if (!lookup)
                return NULL;
        if (lookup->declaration->id != CTF_TYPE_ENUM)
@@ -660,19 +660,19 @@ struct definition_enum *lookup_enum(const struct definition *definition,
        return lookup_enum;
 }
 
-struct definition *lookup_variant(const struct definition *definition,
+struct bt_definition *bt_lookup_variant(const struct bt_definition *definition,
                                  const char *field_name)
 {
-       struct definition *lookup;
-       struct definition_variant *lookup_variant;
+       struct bt_definition *lookup;
+       struct definition_variant *bt_lookup_variant;
 
-       lookup = lookup_definition(definition, field_name);
+       lookup = bt_lookup_definition(definition, field_name);
        if (!lookup)
                return NULL;
        if (lookup->declaration->id != CTF_TYPE_VARIANT)
                return NULL;
-       lookup_variant = container_of(lookup, struct definition_variant, p);
-       lookup = variant_get_current_field(lookup_variant);
+       bt_lookup_variant = container_of(lookup, struct definition_variant, p);
+       lookup = bt_variant_get_current_field(bt_lookup_variant);
        assert(lookup);
        return lookup;
 }
index 55b4b1f058820c0c7089202dc029478d31a0e96b..1f0dc6aafa37ab187c8f97f112c1fd15b6a2d44f 100644 (file)
 #include <errno.h>
 
 static
-struct definition *_variant_definition_new(struct declaration *declaration,
+struct bt_definition *_variant_definition_new(struct bt_declaration *declaration,
                                struct definition_scope *parent_scope,
                                GQuark field_name, int index,
                                const char *root_name);
 static
-void _variant_definition_free(struct definition *definition);
+void _variant_definition_free(struct bt_definition *definition);
 
-int variant_rw(struct stream_pos *ppos, struct definition *definition)
+int bt_variant_rw(struct bt_stream_pos *ppos, struct bt_definition *definition)
 {
        struct definition_variant *variant_definition =
                container_of(definition, struct definition_variant, p);
-       struct definition *field;
+       struct bt_definition *field;
 
-       field = variant_get_current_field(variant_definition);
+       field = bt_variant_get_current_field(variant_definition);
        return generic_rw(ppos, field);
 }
 
 static
-void _untagged_variant_declaration_free(struct declaration *declaration)
+void _untagged_variant_declaration_free(struct bt_declaration *declaration)
 {
        struct declaration_untagged_variant *untagged_variant_declaration =
                container_of(declaration, struct declaration_untagged_variant, p);
        unsigned long i;
 
-       free_declaration_scope(untagged_variant_declaration->scope);
+       bt_free_declaration_scope(untagged_variant_declaration->scope);
        g_hash_table_destroy(untagged_variant_declaration->fields_by_tag);
 
        for (i = 0; i < untagged_variant_declaration->fields->len; i++) {
                struct declaration_field *declaration_field =
                        &g_array_index(untagged_variant_declaration->fields,
                                       struct declaration_field, i);
-               declaration_unref(declaration_field->declaration);
+               bt_declaration_unref(declaration_field->declaration);
        }
        g_array_free(untagged_variant_declaration->fields, true);
        g_free(untagged_variant_declaration);
 }
 
-struct declaration_untagged_variant *untagged_variant_declaration_new(
+struct declaration_untagged_variant *bt_untagged_bt_variant_declaration_new(
                                      struct declaration_scope *parent_scope)
 {
        struct declaration_untagged_variant *untagged_variant_declaration;
-       struct declaration *declaration;
+       struct bt_declaration *declaration;
 
        untagged_variant_declaration = g_new(struct declaration_untagged_variant, 1);
        declaration = &untagged_variant_declaration->p;
@@ -82,7 +82,7 @@ struct declaration_untagged_variant *untagged_variant_declaration_new(
        untagged_variant_declaration->fields = g_array_sized_new(FALSE, TRUE,
                                                 sizeof(struct declaration_field),
                                                 DEFAULT_NR_STRUCT_FIELDS);
-       untagged_variant_declaration->scope = new_declaration_scope(parent_scope);
+       untagged_variant_declaration->scope = bt_new_declaration_scope(parent_scope);
        declaration->id = CTF_TYPE_UNTAGGED_VARIANT;
        declaration->alignment = 1;
        declaration->declaration_free = _untagged_variant_declaration_free;
@@ -93,28 +93,28 @@ struct declaration_untagged_variant *untagged_variant_declaration_new(
 }
 
 static
-void _variant_declaration_free(struct declaration *declaration)
+void _variant_declaration_free(struct bt_declaration *declaration)
 {
        struct declaration_variant *variant_declaration =
                container_of(declaration, struct declaration_variant, p);
 
-       declaration_unref(&variant_declaration->untagged_variant->p);
+       bt_declaration_unref(&variant_declaration->untagged_variant->p);
        g_array_free(variant_declaration->tag_name, TRUE);
        g_free(variant_declaration);
 }
 
 struct declaration_variant *
-       variant_declaration_new(struct declaration_untagged_variant *untagged_variant, const char *tag)
+       bt_variant_declaration_new(struct declaration_untagged_variant *untagged_variant, const char *tag)
 {
        struct declaration_variant *variant_declaration;
-       struct declaration *declaration;
+       struct bt_declaration *declaration;
 
        variant_declaration = g_new(struct declaration_variant, 1);
        declaration = &variant_declaration->p;
        variant_declaration->untagged_variant = untagged_variant;
-       declaration_ref(&untagged_variant->p);
+       bt_declaration_ref(&untagged_variant->p);
        variant_declaration->tag_name = g_array_new(FALSE, TRUE, sizeof(GQuark));
-       append_scope_path(tag, variant_declaration->tag_name);
+       bt_append_scope_path(tag, variant_declaration->tag_name);
        declaration->id = CTF_TYPE_VARIANT;
        declaration->alignment = 1;
        declaration->declaration_free = _variant_declaration_free;
@@ -130,7 +130,7 @@ struct declaration_variant *
  */
 static
 int check_enum_tag(struct definition_variant *variant,
-                  struct definition *enum_tag)
+                  struct bt_definition *enum_tag)
 {
        struct definition_enum *_enum =
                container_of(enum_tag, struct definition_enum, p);
@@ -144,14 +144,14 @@ int check_enum_tag(struct definition_variant *variant,
         * variant choice map to an enumerator too. We then validate that the
         * number of enumerators equals the number of variant choices.
         */
-       if (variant->declaration->untagged_variant->fields->len != enum_get_nr_enumerators(enum_declaration))
+       if (variant->declaration->untagged_variant->fields->len != bt_enum_get_nr_enumerators(enum_declaration))
                return -EPERM;
 
        for (i = 0; i < variant->declaration->untagged_variant->fields->len; i++) {
                struct declaration_field *field_declaration =
                        &g_array_index(variant->declaration->untagged_variant->fields,
                                       struct declaration_field, i);
-               if (!enum_quark_to_range_set(enum_declaration, field_declaration->name)) {
+               if (!bt_enum_quark_to_range_set(enum_declaration, field_declaration->name)) {
                        missing_field = 1;
                        break;
                }
@@ -172,8 +172,8 @@ int check_enum_tag(struct definition_variant *variant,
 
 
 static
-struct definition *
-       _variant_definition_new(struct declaration *declaration,
+struct bt_definition *
+       _variant_definition_new(struct bt_declaration *declaration,
                                struct definition_scope *parent_scope,
                                GQuark field_name, int index,
                                const char *root_name)
@@ -185,7 +185,7 @@ struct definition *
        int ret;
 
        variant = g_new(struct definition_variant, 1);
-       declaration_ref(&variant_declaration->p);
+       bt_declaration_ref(&variant_declaration->p);
        variant->p.declaration = declaration;
        variant->declaration = variant_declaration;
        variant->p.ref = 1;
@@ -195,29 +195,29 @@ struct definition *
         */
        variant->p.index = root_name ? INT_MAX : index;
        variant->p.name = field_name;
-       variant->p.path = new_definition_path(parent_scope, field_name, root_name);
-       variant->p.scope = new_definition_scope(parent_scope, field_name, root_name);
+       variant->p.path = bt_new_definition_path(parent_scope, field_name, root_name);
+       variant->p.scope = bt_new_definition_scope(parent_scope, field_name, root_name);
 
-       ret = register_field_definition(field_name, &variant->p,
+       ret = bt_register_field_definition(field_name, &variant->p,
                                        parent_scope);
        assert(!ret);
 
-       variant->enum_tag = lookup_path_definition(variant->p.scope->scope_path,
+       variant->enum_tag = bt_lookup_path_definition(variant->p.scope->scope_path,
                                                   variant_declaration->tag_name,
                                                   parent_scope);
                                              
        if (!variant->enum_tag
            || check_enum_tag(variant, variant->enum_tag) < 0)
                goto error;
-       definition_ref(variant->enum_tag);
+       bt_definition_ref(variant->enum_tag);
        variant->fields = g_ptr_array_sized_new(variant_declaration->untagged_variant->fields->len);
        g_ptr_array_set_size(variant->fields, variant_declaration->untagged_variant->fields->len);
        for (i = 0; i < variant_declaration->untagged_variant->fields->len; i++) {
                struct declaration_field *declaration_field =
                        &g_array_index(variant_declaration->untagged_variant->fields,
                                       struct declaration_field, i);
-               struct definition **field =
-                       (struct definition **) &g_ptr_array_index(variant->fields, i);
+               struct bt_definition **field =
+                       (struct bt_definition **) &g_ptr_array_index(variant->fields, i);
 
                /*
                 * All child definition are at index 0, because they are
@@ -232,14 +232,14 @@ struct definition *
        variant->current_field = NULL;
        return &variant->p;
 error:
-       free_definition_scope(variant->p.scope);
-       declaration_unref(&variant_declaration->p);
+       bt_free_definition_scope(variant->p.scope);
+       bt_declaration_unref(&variant_declaration->p);
        g_free(variant);
        return NULL;
 }
 
 static
-void _variant_definition_free(struct definition *definition)
+void _variant_definition_free(struct bt_definition *definition)
 {
        struct definition_variant *variant =
                container_of(definition, struct definition_variant, p);
@@ -247,19 +247,19 @@ void _variant_definition_free(struct definition *definition)
 
        assert(variant->fields->len == variant->declaration->untagged_variant->fields->len);
        for (i = 0; i < variant->fields->len; i++) {
-               struct definition *field = g_ptr_array_index(variant->fields, i);
-               definition_unref(field);
+               struct bt_definition *field = g_ptr_array_index(variant->fields, i);
+               bt_definition_unref(field);
        }
-       definition_unref(variant->enum_tag);
-       free_definition_scope(variant->p.scope);
-       declaration_unref(variant->p.declaration);
+       bt_definition_unref(variant->enum_tag);
+       bt_free_definition_scope(variant->p.scope);
+       bt_declaration_unref(variant->p.declaration);
        g_ptr_array_free(variant->fields, TRUE);
        g_free(variant);
 }
 
-void untagged_variant_declaration_add_field(struct declaration_untagged_variant *untagged_variant_declaration,
+void bt_untagged_variant_declaration_add_field(struct declaration_untagged_variant *untagged_variant_declaration,
                            const char *field_name,
-                           struct declaration *field_declaration)
+                           struct bt_declaration *field_declaration)
 {
        struct declaration_field *field;
        unsigned long index;
@@ -268,7 +268,7 @@ void untagged_variant_declaration_add_field(struct declaration_untagged_variant
        index = untagged_variant_declaration->fields->len - 1;  /* last field (new) */
        field = &g_array_index(untagged_variant_declaration->fields, struct declaration_field, index);
        field->name = g_quark_from_string(field_name);
-       declaration_ref(field_declaration);
+       bt_declaration_ref(field_declaration);
        field->declaration = field_declaration;
        /* Keep index in hash rather than pointer, because array can relocate */
        g_hash_table_insert(untagged_variant_declaration->fields_by_tag,
@@ -282,7 +282,7 @@ void untagged_variant_declaration_add_field(struct declaration_untagged_variant
 }
 
 struct declaration_field *
-untagged_variant_declaration_get_field_from_tag(struct declaration_untagged_variant *untagged_variant_declaration, GQuark tag)
+bt_untagged_variant_declaration_get_field_from_tag(struct declaration_untagged_variant *untagged_variant_declaration, GQuark tag)
 {
        gpointer index;
        gboolean found;
@@ -301,7 +301,7 @@ untagged_variant_declaration_get_field_from_tag(struct declaration_untagged_vari
 /*
  * field returned only valid as long as the field structure is not appended to.
  */
-struct definition *variant_get_current_field(struct definition_variant *variant)
+struct bt_definition *bt_variant_get_current_field(struct definition_variant *variant)
 {
        struct definition_enum *_enum =
                container_of(variant->enum_tag, struct definition_enum, p);
This page took 0.268445 seconds and 4 git commands to generate.