Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
cs24-22fa
project03
Commits
13fa6bbe
Commit
13fa6bbe
authored
4 years ago
by
Caleb C. Sander
Browse files
Options
Download
Email Patches
Plain Diff
Add clang-format
parent
6c942fb0
master
No related merge requests found
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
.clang-format
+19
-0
.clang-format
.githooks/pre-commit
+12
-0
.githooks/pre-commit
src/mm-explicit.c
+3
-8
src/mm-explicit.c
src/mm-implicit.c
+3
-8
src/mm-implicit.c
with
37 additions
and
16 deletions
+37
-16
.clang-format
0 → 100644
View file @
13fa6bbe
---
# We'll use defaults from the Google style, but with 4 columns indentation.
BasedOnStyle: Google
# Never allow single-line functions
AllowShortFunctionsOnASingleLine: None
# Put "else" on a new line
BreakBeforeBraces: Custom
BraceWrapping:
BeforeElse: true
# Allow lines up to 90 characters
ColumnLimit: 90
# Indent each block by 4 spaces
IndentWidth: 4
TabWidth: 4
# Require 1 space before a comment on the same line
SpacesBeforeTrailingComments: 1
# Put a space after a cast, e.g. `(void) arg;`
SpaceAfterCStyleCast: true
---
This diff is collapsed.
Click to expand it.
.githooks/pre-commit
0 → 100755
View file @
13fa6bbe
#!/bin/bash
if
loc
=
"
$(
type
-p
"clang-format"
)
"
&&
[[
-x
$loc
]]
;
then
for
name
in
$(
git diff
--cached
--name-only
--diff-filter
=
ACM
)
;
do
if
echo
$name
|
grep
-Eq
"
\.
[ch]$"
;
then
echo
"Formatting
${
name
}
..."
clang-format
-i
$name
fi
done
else
echo
"You do not have clang-format installed; so, we were unable to unify the formatting in your files."
fi
This diff is collapsed.
Click to expand it.
src/mm-explicit.c
View file @
13fa6bbe
...
...
@@ -6,8 +6,8 @@
#include <stdint.h>
#include "mm.h"
#include "memlib.h"
#include "mm.h"
/** The required alignment of heap payloads */
const
size_t
ALIGNMENT
=
2
*
sizeof
(
size_t
);
...
...
@@ -54,11 +54,8 @@ static bool is_allocated(block_t *block) {
*/
static
block_t
*
find_fit
(
size_t
size
)
{
// Traverse the blocks in the heap using the implicit list
for
(
block_t
*
curr
=
mm_heap_first
;
mm_heap_last
!=
NULL
&&
curr
<=
mm_heap_last
;
curr
=
(
void
*
)
curr
+
get_size
(
curr
)
)
{
for
(
block_t
*
curr
=
mm_heap_first
;
mm_heap_last
!=
NULL
&&
curr
<=
mm_heap_last
;
curr
=
(
void
*
)
curr
+
get_size
(
curr
))
{
// If the block is free and large enough for the allocation, return it
if
(
!
is_allocated
(
curr
)
&&
get_size
(
curr
)
>=
size
)
{
return
curr
;
...
...
@@ -72,7 +69,6 @@ static block_t *block_from_payload(void *ptr) {
return
ptr
-
offsetof
(
block_t
,
payload
);
}
/**
* mm_init - Initializes the allocator state
*/
...
...
@@ -157,5 +153,4 @@ void *mm_calloc(size_t nmemb, size_t size) {
* mm_checkheap - So simple, it doesn't need a checker!
*/
void
mm_checkheap
(
void
)
{
}
This diff is collapsed.
Click to expand it.
src/mm-implicit.c
View file @
13fa6bbe
...
...
@@ -7,8 +7,8 @@
#include <stdint.h>
#include "mm.h"
#include "memlib.h"
#include "mm.h"
/** The required alignment of heap payloads */
const
size_t
ALIGNMENT
=
2
*
sizeof
(
size_t
);
...
...
@@ -55,11 +55,8 @@ static bool is_allocated(block_t *block) {
*/
static
block_t
*
find_fit
(
size_t
size
)
{
// Traverse the blocks in the heap using the implicit list
for
(
block_t
*
curr
=
mm_heap_first
;
mm_heap_last
!=
NULL
&&
curr
<=
mm_heap_last
;
curr
=
(
void
*
)
curr
+
get_size
(
curr
)
)
{
for
(
block_t
*
curr
=
mm_heap_first
;
mm_heap_last
!=
NULL
&&
curr
<=
mm_heap_last
;
curr
=
(
void
*
)
curr
+
get_size
(
curr
))
{
// If the block is free and large enough for the allocation, return it
if
(
!
is_allocated
(
curr
)
&&
get_size
(
curr
)
>=
size
)
{
return
curr
;
...
...
@@ -73,7 +70,6 @@ static block_t *block_from_payload(void *ptr) {
return
ptr
-
offsetof
(
block_t
,
payload
);
}
/**
* mm_init - Initializes the allocator state
*/
...
...
@@ -158,5 +154,4 @@ void *mm_calloc(size_t nmemb, size_t size) {
* mm_checkheap - So simple, it doesn't need a checker!
*/
void
mm_checkheap
(
void
)
{
}
This diff is collapsed.
Click to expand it.
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
Menu
Projects
Groups
Snippets
Help