projects
/
babeltrace.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Move scanner allocation/free outside of ctf_open_trace_metadata_read
[babeltrace.git]
/
formats
/
ctf
/
ctf.c
diff --git
a/formats/ctf/ctf.c
b/formats/ctf/ctf.c
index 515bbe1a2c256aea19efefc3c1af9bfe35ac82d9..139689b39b381bc7d3b6c31fd47c9802fbc8d59b 100644
(file)
--- a/
formats/ctf/ctf.c
+++ b/
formats/ctf/ctf.c
@@
-887,9
+887,12
@@
void ctf_packet_seek(struct bt_stream_pos *stream_pos, size_t index, int whence)
return;
}
assert(pos->cur_index < pos->packet_index->len);
return;
}
assert(pos->cur_index < pos->packet_index->len);
- if (index > 0) {
+ packet_index = &g_array_index(pos->packet_index,
+ struct packet_index, pos->cur_index);
+ if (pos->cur_index > 0) {
prev_index = &g_array_index(pos->packet_index,
prev_index = &g_array_index(pos->packet_index,
- struct packet_index, index - 1);
+ struct packet_index,
+ pos->cur_index - 1);
}
ctf_update_current_packet_index(&file_stream->parent,
prev_index, packet_index);
}
ctf_update_current_packet_index(&file_stream->parent,
prev_index, packet_index);
@@
-1198,9
+1201,9
@@
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 bt_stream_pos *pos, size_t index,
static
int ctf_open_trace_metadata_read(struct ctf_trace *td,
void (*packet_seek)(struct bt_stream_pos *pos, size_t index,
- int whence), FILE *metadata_fp)
+ int whence), FILE *metadata_fp,
+ struct ctf_scanner *scanner)
{
{
- struct ctf_scanner *scanner;
struct ctf_file_stream *metadata_stream;
FILE *fp;
char *buf = NULL;
struct ctf_file_stream *metadata_stream;
FILE *fp;
char *buf = NULL;
@@
-1247,7
+1250,7
@@
int ctf_open_trace_metadata_read(struct ctf_trace *td,
if (ret) {
/* Warn about empty metadata */
fprintf(stderr, "[warning] Empty metadata.\n");
if (ret) {
/* Warn about empty metadata */
fprintf(stderr, "[warning] Empty metadata.\n");
- goto end
_packet_read
;
+ goto end;
}
td->metadata_string = buf;
td->metadata_packetized = 1;
}
td->metadata_string = buf;
td->metadata_packetized = 1;
@@
-1263,18
+1266,12
@@
int ctf_open_trace_metadata_read(struct ctf_trace *td,
fprintf(stderr, "[warning] Ill-shapen or missing \"/* CTF x.y\" header for text-only metadata.\n");
if (check_version(major, minor) < 0) {
ret = -EINVAL;
fprintf(stderr, "[warning] Ill-shapen or missing \"/* CTF x.y\" header for text-only metadata.\n");
if (check_version(major, minor) < 0) {
ret = -EINVAL;
- goto end
_packet_read
;
+ goto end;
}
rewind(fp);
}
}
rewind(fp);
}
- scanner = ctf_scanner_alloc(fp);
- if (!scanner) {
- fprintf(stderr, "[error] Error allocating scanner\n");
- ret = -ENOMEM;
- goto end_scanner_alloc;
- }
- ret = ctf_scanner_append_ast(scanner);
+ ret = ctf_scanner_append_ast(scanner, fp);
if (ret) {
fprintf(stderr, "[error] Error creating AST\n");
goto end;
if (ret) {
fprintf(stderr, "[error] Error creating AST\n");
goto end;
@@
-1300,9
+1297,6
@@
int ctf_open_trace_metadata_read(struct ctf_trace *td,
goto end;
}
end:
goto end;
}
end:
- ctf_scanner_free(scanner);
-end_scanner_alloc:
-end_packet_read:
if (fp) {
closeret = fclose(fp);
if (closeret) {
if (fp) {
closeret = fclose(fp);
if (closeret) {
@@
-1808,7
+1802,6
@@
static
int import_stream_packet_index(struct ctf_trace *td,
struct ctf_file_stream *file_stream)
{
int import_stream_packet_index(struct ctf_trace *td,
struct ctf_file_stream *file_stream)
{
- struct ctf_stream_declaration *stream;
struct ctf_stream_pos *pos;
struct ctf_packet_index ctf_index;
struct ctf_packet_index_file_hdr index_hdr;
struct ctf_stream_pos *pos;
struct ctf_packet_index ctf_index;
struct ctf_packet_index_file_hdr index_hdr;
@@
-1849,6
+1842,7
@@
int import_stream_packet_index(struct ctf_trace *td,
while (fread(&ctf_index, index_hdr.packet_index_len, 1,
pos->index_fp) == 1) {
uint64_t stream_id;
while (fread(&ctf_index, index_hdr.packet_index_len, 1,
pos->index_fp) == 1) {
uint64_t stream_id;
+ struct ctf_stream_declaration *stream = NULL;
memset(&index, 0, sizeof(index));
index.offset = be64toh(ctf_index.offset);
memset(&index, 0, sizeof(index));
index.offset = be64toh(ctf_index.offset);
@@
-1868,7
+1862,9
@@
int import_stream_packet_index(struct ctf_trace *td,
}
file_stream->parent.stream_id = stream_id;
}
file_stream->parent.stream_id = stream_id;
- stream = g_ptr_array_index(td->streams, stream_id);
+ if (stream_id < td->streams->len) {
+ stream = g_ptr_array_index(td->streams, stream_id);
+ }
if (!stream) {
fprintf(stderr, "[error] Stream %" PRIu64
" is not declared in metadata.\n",
if (!stream) {
fprintf(stderr, "[error] Stream %" PRIu64
" is not declared in metadata.\n",
@@
-2040,6
+2036,7
@@
int ctf_open_trace_read(struct ctf_trace *td,
void (*packet_seek)(struct bt_stream_pos *pos, size_t index,
int whence), FILE *metadata_fp)
{
void (*packet_seek)(struct bt_stream_pos *pos, size_t index,
int whence), FILE *metadata_fp)
{
+ struct ctf_scanner *scanner;
int ret, closeret;
struct dirent *dirent;
struct dirent *diriter;
int ret, closeret;
struct dirent *dirent;
struct dirent *diriter;
@@
-2069,8
+2066,15
@@
int ctf_open_trace_read(struct ctf_trace *td,
/*
* Keep the metadata file separate.
*/
/*
* Keep the metadata file separate.
*/
-
- ret = ctf_open_trace_metadata_read(td, packet_seek, metadata_fp);
+ scanner = ctf_scanner_alloc();
+ if (!scanner) {
+ fprintf(stderr, "[error] Error allocating scanner\n");
+ ret = -ENOMEM;
+ goto error_metadata;
+ }
+ ret = ctf_open_trace_metadata_read(td, packet_seek, metadata_fp,
+ scanner);
+ ctf_scanner_free(scanner);
if (ret) {
fprintf(stderr, "[warning] Unable to open trace metadata for path \"%s\".\n", path);
goto error_metadata;
if (ret) {
fprintf(stderr, "[warning] Unable to open trace metadata for path \"%s\".\n", path);
goto error_metadata;
@@
-2280,8
+2284,16
@@
int ctf_open_mmap_trace_read(struct ctf_trace *td,
{
int ret;
struct bt_mmap_stream *mmap_info;
{
int ret;
struct bt_mmap_stream *mmap_info;
+ struct ctf_scanner *scanner;
- ret = ctf_open_trace_metadata_read(td, ctf_packet_seek, metadata_fp);
+ scanner = ctf_scanner_alloc();
+ if (!scanner) {
+ fprintf(stderr, "[error] Error allocating scanner\n");
+ ret = -ENOMEM;
+ goto error_scanner_alloc;
+ }
+ ret = ctf_open_trace_metadata_read(td, ctf_packet_seek, metadata_fp,
+ scanner);
if (ret) {
goto error;
}
if (ret) {
goto error;
}
@@
-2297,10
+2309,12
@@
int ctf_open_mmap_trace_read(struct ctf_trace *td,
goto error;
}
}
goto error;
}
}
-
+ ctf_scanner_free(scanner);
return 0;
error:
return 0;
error:
+ ctf_scanner_free(scanner);
+error_scanner_alloc:
return ret;
}
return ret;
}
This page took
0.032887 seconds
and
4
git commands to generate.