Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
L
LabComm
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Anders Blomdell
LabComm
Commits
2f426104
Commit
2f426104
authored
10 years ago
by
Sven Gestegård Robertz
Browse files
Options
Downloads
Patches
Plain Diff
handling of typedefs implemented in C
parent
266c6d58
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
examples/user_types/example_decoder.c
+5
-0
5 additions, 0 deletions
examples/user_types/example_decoder.c
lib/c/2014/labcomm_decoder.c
+87
-1
87 additions, 1 deletion
lib/c/2014/labcomm_decoder.c
lib/c/2014/labcomm_type_signature.h
+18
-52
18 additions, 52 deletions
lib/c/2014/labcomm_type_signature.h
with
110 additions
and
53 deletions
examples/user_types/example_decoder.c
+
5
−
0
View file @
2f426104
...
...
@@ -20,6 +20,10 @@ static void handle_test_theSecondInt(int *v,void *context) {
printf
(
"Got theSecondInt. (%d)
\n
"
,
*
v
);
}
static
void
handle_typedef
(
struct
labcomm_raw_typedef
*
v
,
void
*
context
)
{
printf
(
"Got typedef. (%d) %s
\n
"
,
v
->
index
,
v
->
name
);
}
static
void
handle_test_twoLines
(
test_twoLines
*
v
,
void
*
context
)
{
printf
(
"Got twoLines. (%d,%d) -> (%d,%d), (%d,%d) -> (%d,%d)
\n
"
,
v
->
l1
.
start
.
x
.
val
,
v
->
l1
.
start
.
y
.
val
,
v
->
l1
.
end
.
x
.
val
,
v
->
l1
.
end
.
y
.
val
,
...
...
@@ -49,6 +53,7 @@ int main(int argc, char *argv[]) {
labcomm_decoder_register_test_theFirstInt
(
decoder
,
handle_test_theFirstInt
,
context
);
labcomm_decoder_register_test_theSecondInt
(
decoder
,
handle_test_theSecondInt
,
context
);
labcomm_decoder_register_test_twoLines
(
decoder
,
handle_test_twoLines
,
context
);
labcomm_decoder_register_labcomm_typedef
(
decoder
,
handle_typedef
,
context
);
printf
(
"Decoding:
\n
"
);
labcomm_decoder_run
(
decoder
);
...
...
This diff is collapsed.
Click to expand it.
lib/c/2014/labcomm_decoder.c
+
87
−
1
View file @
2f426104
...
...
@@ -443,7 +443,11 @@ int labcomm_decoder_decode_one(struct labcomm_decoder *d)
}
else
if
(
remote_index
==
LABCOMM_SAMPLE_REF
)
{
result
=
decode_sample_def_or_ref
(
d
,
LABCOMM_SAMPLE_REF
);
}
else
if
(
remote_index
==
LABCOMM_TYPE_DEF
)
{
result
=
decode_and_handle
(
d
,
d
,
remote_index
);
if
(
result
==
-
ENOENT
)
{
printf
(
"*** no handler for typedef..."
);
result
=
decode_type_def
(
d
,
LABCOMM_TYPE_DEF
);
}
}
else
if
(
remote_index
==
LABCOMM_TYPE_BINDING
)
{
result
=
decode_type_binding
(
d
,
LABCOMM_TYPE_BINDING
);
}
else
if
(
remote_index
==
LABCOMM_PRAGMA
)
{
...
...
@@ -525,6 +529,88 @@ int labcomm_internal_decoder_ioctl(struct labcomm_decoder *d,
return
result
;
}
#ifndef LABCOMM_NO_TYPEDECL
//// Code for allowing user code to handle typedefs
//// (should perhaps be moved to another file)
static
void
decode_raw_typedef
(
struct
labcomm_reader
*
r
,
void
(
*
handle
)(
struct
labcomm_raw_typedef
*
v
,
void
*
context
),
void
*
context
)
{
struct
labcomm_raw_typedef
v
;
v
.
index
=
labcomm_read_packed32
(
r
);
if
(
r
->
error
<
0
)
{
goto
out
;
}
v
.
name
=
labcomm_read_string
(
r
);
if
(
r
->
error
<
0
)
{
goto
free_name
;
}
v
.
length
=
labcomm_read_packed32
(
r
);
if
(
r
->
error
<
0
)
{
goto
free_name
;
}
int
i
;
v
.
signature_data
=
labcomm_memory_alloc
(
r
->
memory
,
1
,
v
.
length
);
if
(
v
.
signature_data
)
{
for
(
i
=
0
;
i
<
v
.
length
;
i
++
)
{
v
.
signature_data
[
i
]
=
labcomm_read_byte
(
r
);
if
(
r
->
error
<
0
)
{
goto
free_sig
;
}
}
handle
(
&
v
,
context
);
}
free_sig:
labcomm_memory_free
(
r
->
memory
,
1
,
v
.
signature_data
);
free_name:
labcomm_memory_free
(
r
->
memory
,
1
,
v
.
name
);
out:
return
;
}
int
labcomm_decoder_register_labcomm_typedef
(
struct
labcomm_decoder
*
d
,
void
(
*
handler
)(
struct
labcomm_raw_typedef
*
v
,
void
*
context
),
void
*
context
)
{
int
tag
=
LABCOMM_TYPE_DEF
;
struct
sample_entry
*
entry
;
int
*
remote_to_local
;
labcomm_scheduler_data_lock
(
d
->
scheduler
);
entry
=
LABCOMM_SIGNATURE_ARRAY_REF
(
d
->
memory
,
d
->
local
,
struct
sample_entry
,
tag
);
if
(
entry
==
NULL
)
{
tag
=
-
ENOMEM
;
goto
unlock
;
}
entry
->
remote_index
=
LABCOMM_TYPE_DEF
;
entry
->
signature
=
NULL
;
entry
->
decode
=
(
labcomm_decoder_function
)
decode_raw_typedef
;
entry
->
handler
=
(
labcomm_handler_function
)
handler
;
entry
->
context
=
context
;
remote_to_local
=
LABCOMM_SIGNATURE_ARRAY_REF
(
d
->
memory
,
d
->
remote_to_local
,
int
,
tag
);
*
remote_to_local
=
tag
;
unlock:
labcomm_scheduler_data_unlock
(
d
->
scheduler
);
return
tag
;
}
//// End typedef handling
#endif
int
labcomm_internal_decoder_register
(
struct
labcomm_decoder
*
d
,
const
struct
labcomm_signature
*
signature
,
...
...
This diff is collapsed.
Click to expand it.
lib/c/2014/labcomm_type_signature.h
+
18
−
52
View file @
2f426104
...
...
@@ -61,67 +61,33 @@ struct labcomm_signature {
#endif
};
#if 0
/*
* Signature entry
/* a struct for "raw" typedefs, to be used as an intermediate representation
* between decoder and signature parser
*/
#ifdef USE_UNIONS
/* Useful for C99 and up (or GCC without -pedantic) */
#define LABCOMM_SIGDEF_BYTES_OR_SIGNATURE \
union { \
char *bytes; \
struct labcomm_signature* signature; \
} u;
#define LABCOMM_SIGDEF_BYTES(l, b) { l, .u.bytes=b }
#define LABCOMM_SIGDEF_SIGNATURE(s) { 0, .u.signature=&s } // addressof, as s is pointing at the sig struct, not directly the the sig_bytes[]
#define LABCOMM_SIGDEF_END { -1, .u.bytes=0 }
#else
#define LABCOMM_SIGDEF_BYTES_OR_SIGNATURE \
struct { \
char *bytes; \
struct labcomm_signature *signature; \
} u;
#define LABCOMM_SIGDEF_BYTES(l, b) { l, { b, 0 } }
#define LABCOMM_SIGDEF_SIGNATURE(s) { 0, { 0, &s } }
#define LABCOMM_SIGDEF_END { -1, { 0, 0 } }
#endif
struct
labcomm_signature_data
{
int
length
;
LABCOMM_SIGDEF_BYTES_OR_SIGNATURE
};
struct
labcomm_signature
{
int
type
;
struct
labcomm_raw_typedef
{
char
*
name
;
int
(
*
encoded_size
)(
struct
labcomm_signature
*
,
void
*
);
// void * == encoded_sample *
struct
{
int
size
;
unsigned
char
*
data
;
}
flat
;
struct
{
int
size
;
struct
labcomm_signature_data
*
data
;
}
tree
;
int
index
;
#ifdef LABCOMM_EXPERIMENTAL_CACHED_ENCODED_SIZE
int
cached_encoded_size
;
// -1 if not initialized or type is variable size
#endif
int
length
;
char
*
signature_data
;
};
#endif
/*
* functions
*/
/* register a handler for typedefs
*/
int
labcomm_decoder_register_labcomm_typedef
(
struct
labcomm_decoder
*
d
,
void
(
*
handler
)(
struct
labcomm_raw_typedef
*
v
,
void
*
context
),
void
*
context
);
/* Dump signature bytes on stdout
*/
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment