Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
asn1c
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
asn1c
Commits
a67d1106
Commit
a67d1106
authored
Nov 05, 2017
by
Lev Walkin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
name clashes using generic hashing
parent
adfcde29
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
42 additions
and
26 deletions
+42
-26
libasn1compiler/asn1c_naming.c
libasn1compiler/asn1c_naming.c
+42
-26
No files found.
libasn1compiler/asn1c_naming.c
View file @
a67d1106
...
@@ -3,6 +3,7 @@
...
@@ -3,6 +3,7 @@
#include "asn1c_misc.h"
#include "asn1c_misc.h"
#include "asn1c_misc.h"
#include "asn1c_misc.h"
#include <asn1_buffer.h>
#include <asn1_buffer.h>
#include <genhash.h>
struct
intl_name
{
struct
intl_name
{
asn1p_expr_t
*
expr
;
asn1p_expr_t
*
expr
;
...
@@ -10,18 +11,13 @@ struct intl_name {
...
@@ -10,18 +11,13 @@ struct intl_name {
const
char
*
name
;
const
char
*
name
;
TQ_ENTRY
(
struct
intl_name
)
next
;
TQ_ENTRY
(
struct
intl_name
)
next
;
};
};
static
TQ_HEAD
(
struct
intl_name
)
used_names
;
void
genhash_t
*
used_names_hash
;
c_name_clash_finder_init
()
{
TQ_INIT
(
&
used_names
);
}
void
static
void
c_name_clash_finder_destroy
(
)
{
name_entry_destroy
(
void
*
np
)
{
struct
intl_name
*
n
;
struct
intl_name
*
n
=
np
;
while
((
n
=
TQ_REMOVE
(
&
used_names
,
next
)))
{
union
{
union
{
const
char
*
c_buf
;
const
char
*
c_buf
;
char
*
nc_buf
;
char
*
nc_buf
;
...
@@ -32,32 +28,47 @@ c_name_clash_finder_destroy() {
...
@@ -32,32 +28,47 @@ c_name_clash_finder_destroy() {
const_cast
.
c_buf
=
n
->
name
;
const_cast
.
c_buf
=
n
->
name
;
free
(
const_cast
.
nc_buf
);
free
(
const_cast
.
nc_buf
);
free
(
n
);
free
(
n
);
}
}
void
c_name_clash_finder_init
()
{
assert
(
used_names_hash
==
NULL
);
used_names_hash
=
genhash_new
(
cmpf_string
,
hashf_string
,
NULL
,
name_entry_destroy
);
assert
(
used_names_hash
);
}
void
c_name_clash_finder_destroy
()
{
genhash_destroy
(
used_names_hash
);
used_names_hash
=
NULL
;
}
}
static
void
static
void
register_global_name
(
asn1p_expr_t
*
expr
,
const
char
*
name
)
{
register_global_name
(
asn1p_expr_t
*
expr
,
const
char
*
name
)
{
struct
intl_name
*
n
;
struct
intl_name
*
n
;
TQ_FOR
(
n
,
&
used_names
,
next
)
{
n
=
genhash_get
(
used_names_hash
,
(
const
void
*
)
name
);
if
(
strcmp
(
n
->
name
,
name
)
==
0
)
{
if
(
n
)
{
if
(
!
(
expr
->
_mark
&
TM_NAMEGIVEN
)
&&
expr
!=
n
->
expr
)
{
if
(
!
(
expr
->
_mark
&
TM_NAMEGIVEN
)
&&
(
expr
!=
n
->
expr
)
)
{
n
->
clashes_with
=
expr
;
n
->
clashes_with
=
expr
;
expr
->
ref_cnt
++
;
expr
->
ref_cnt
++
;
return
;
return
;
}
}
}
}
}
if
(
expr
->
_mark
&
TM_NAMEGIVEN
)
if
(
expr
->
_mark
&
TM_NAMEGIVEN
)
return
;
return
;
char
*
name_copy
=
strdup
(
name
);
n
=
calloc
(
1
,
sizeof
(
*
n
));
n
=
calloc
(
1
,
sizeof
(
*
n
));
assert
(
n
);
assert
(
n
);
n
->
expr
=
expr
;
n
->
expr
=
expr
;
expr
->
ref_cnt
++
;
expr
->
ref_cnt
++
;
n
->
name
=
strdup
(
name
);
n
->
name
=
name_copy
;
TQ_ADD
(
&
used_names
,
n
,
next
);
int
ret
=
genhash_add
(
used_names_hash
,
name_copy
,
n
);
assert
(
ret
==
0
);
}
}
int
int
...
@@ -66,7 +77,10 @@ c_name_clash(arg_t *arg) {
...
@@ -66,7 +77,10 @@ c_name_clash(arg_t *arg) {
size_t
n_clashes
=
0
;
size_t
n_clashes
=
0
;
const
size_t
max_clashes
=
5
;
const
size_t
max_clashes
=
5
;
TQ_FOR
(
n
,
&
used_names
,
next
)
{
genhash_iter_t
iter
;
genhash_iter_init
(
&
iter
,
used_names_hash
,
0
);
while
(
genhash_iter
(
&
iter
,
NULL
,
(
void
*
)
&
n
))
{
if
(
n
->
clashes_with
)
{
if
(
n
->
clashes_with
)
{
if
(
n_clashes
++
>
max_clashes
)
continue
;
if
(
n_clashes
++
>
max_clashes
)
continue
;
FATAL
(
FATAL
(
...
@@ -81,6 +95,8 @@ c_name_clash(arg_t *arg) {
...
@@ -81,6 +95,8 @@ c_name_clash(arg_t *arg) {
}
}
}
}
genhash_iter_done
(
&
iter
);
if
(
n_clashes
>
max_clashes
)
{
if
(
n_clashes
>
max_clashes
)
{
FATAL
(
"... %zu more name clashes not shown"
,
n_clashes
-
max_clashes
);
FATAL
(
"... %zu more name clashes not shown"
,
n_clashes
-
max_clashes
);
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment