Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
B
binary_c-python
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Izzard, Robert Dr (Maths & Physics)
binary_c-python
Commits
1e84834a
Commit
1e84834a
authored
5 years ago
by
Izzard, Robert Dr (Maths & Physics)
Browse files
Options
Downloads
Patches
Plain Diff
cleanup the new ALPHA_ARGS: free memory, replace magic numbers with macros
parent
6e62fee3
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/binary_c_macros.h
+15
-0
15 additions, 0 deletions
src/binary_c_macros.h
src/memory/free_tmpstore.c
+13
-1
13 additions, 1 deletion
src/memory/free_tmpstore.c
src/setup/parse_arguments.c
+14
-10
14 additions, 10 deletions
src/setup/parse_arguments.c
with
42 additions
and
11 deletions
src/binary_c_macros.h
+
15
−
0
View file @
1e84834a
...
...
@@ -1008,5 +1008,20 @@
#define NOVA_TYPE_HYDROGEN 0
#define NOVA_TYPE_HELIUM 1
/*
* Number of letters in the (English) alphabet
*/
#define NUMBER_OF_LETTERS_IN_THE_ALPHABET 26
/*
* Number of alphabetical cases
*/
#define NUMBER_OF_ALPHABETICAL_CASES 2
/*
* Alpha-args parameters list size (see parse_arguments.c)
*/
#define ALPHA_ARGS_SIZE \
(NUMBER_OF_LETTERS_IN_THE_ALPHABET * NUMBER_OF_ALPHABETICAL_CASES)
#endif
/* BINARY_MACROS_H */
This diff is collapsed.
Click to expand it.
src/memory/free_tmpstore.c
+
13
−
1
View file @
1e84834a
...
...
@@ -71,7 +71,7 @@ void free_tmpstore(struct tmpstore_t * RESTRICT const tmpstore)
#endif
#ifdef WTTS_LOG
{
int
i
;
unsigned
int
i
;
for
(
i
=
0
;
i
<=
1
;
i
++
)
{
Safe_fclose
(
tmpstore
->
fp_star
[
i
]);
...
...
@@ -92,6 +92,18 @@ void free_tmpstore(struct tmpstore_t * RESTRICT const tmpstore)
Safe_free
(
tmpstore
->
rinterpolate_data
);
}
#ifdef ALPHA_ARGS
{
unsigned
int
i
;
for
(
i
=
0
;
i
<
ALPHA_ARGS_SIZE
;
i
++
)
{
Safe_free
(
tmpstore
->
cmd_line_args_alpha
[
i
]);
}
Safe_free
(
tmpstore
->
cmd_line_args_alpha
);
Safe_free
(
tmpstore
->
cmd_line_args_alpha_count
);
}
#endif
/*
* Free the memory in tmpstore, but don't set it
* to NULL
...
...
This diff is collapsed.
Click to expand it.
src/setup/parse_arguments.c
+
14
−
10
View file @
1e84834a
...
...
@@ -71,29 +71,31 @@ void parse_arguments(const int start,
* between 0 and 51 (inclusive).
*/
tmpstore
->
cmd_line_args_alpha
=
Malloc
(
sizeof
(
struct
cmd_line_arg_t
*
)
*
26
*
2
);
Malloc
(
sizeof
(
struct
cmd_line_arg_t
*
)
*
ALPHA_ARGS_SIZE
);
/*
* Set all counts to zero
*/
tmpstore
->
cmd_line_args_alpha_count
=
Calloc
(
26
*
2
,
sizeof
(
unsigned
int
));
tmpstore
->
cmd_line_args_alpha_count
=
Calloc
(
ALPHA_ARGS_SIZE
,
sizeof
(
unsigned
int
));
unsigned
int
u
;
for
(
u
=
0
;
u
<
2
;
u
++
)
for
(
u
=
0
;
u
<
NUMBER_OF_ALPHABETICAL_CASES
;
u
++
)
{
/*
* u = 0 -> lower case
* u = 1 -> upper case
*/
unsigned
int
a
;
const
unsigned
int
offset
=
u
==
0
?
97
:
65
;
for
(
a
=
0
;
a
<
26
;
a
++
)
const
unsigned
int
offset
=
(
const
unsigned
int
)
(
u
==
0
?
'a'
:
'A'
);
for
(
a
=
0
;
a
<
NUMBER_OF_LETTERS_IN_THE_ALPHABET
;
a
++
)
{
/*
* Hence the char that is the first letter
*/
unsigned
char
c
=
offset
+
a
;
const
unsigned
int
index
=
a
+
u
*
26
;
const
unsigned
char
c
=
offset
+
a
;
const
unsigned
int
index
=
a
+
u
*
NUMBER_OF_LETTERS_IN_THE_ALPHABET
;
Aprint
(
"allocate alpha structure %d (char %d = %c = %c)
\n
"
,
a
,
(
int
)
c
,
...
...
@@ -207,9 +209,11 @@ void parse_arguments(const int start,
/*
* First character is a letter: use the alpha map
*/
const
unsigned
int
u
=
ASCII_lower_case
(
arg
[
0
])
?
0
:
1
;
const
unsigned
int
offset
=
u
==
0
?
97
:
65
;
const
unsigned
int
index
=
arg
[
0
]
-
offset
+
26
*
u
;
const
unsigned
int
u
=
ASCII_lower_case
(
arg
[
0
])
==
TRUE
?
0
:
1
;
const
unsigned
int
offset
=
(
const
unsigned
int
)
u
==
0
?
'a'
:
'A'
;
const
unsigned
int
index
=
arg
[
0
]
-
offset
+
NUMBER_OF_LETTERS_IN_THE_ALPHABET
*
u
;
arg_count
=
stardata
->
tmpstore
->
cmd_line_args_alpha_count
[
index
];
cmd_line_args
=
stardata
->
tmpstore
->
cmd_line_args_alpha
[
index
];
...
...
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