Skip to content

Commit

Permalink
Merge branch 'sysprog21:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
zoo868e authored Feb 26, 2024
2 parents d94e268 + bbd4243 commit 2569288
Show file tree
Hide file tree
Showing 13 changed files with 51 additions and 28 deletions.
19 changes: 19 additions & 0 deletions .ci/check-newline.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env bash

set -e -u -o pipefail

ret=0
show=0
# Reference: https://medium.com/@alexey.inkin/how-to-force-newline-at-end-of-files-and-why-you-should-do-it-fdf76d1d090e
while IFS= read -rd '' f; do
if file --mime-encoding "$f" | grep -qv binary; then
tail -c1 < "$f" | read -r _ || show=1
if [ $show -eq 1 ]; then
echo "Warning: No newline at end of file $f"
ret=1
show=0
fi
fi
done < <(git ls-files -z src tests/arch-test-target)

exit $ret
3 changes: 2 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,6 @@ jobs:
- name: coding convention
run: |
sudo apt-get install -q -y clang-format-14
sh .ci/check-format.sh
.ci/check-newline.sh
.ci/check-format.sh
shell: bash
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
lab0-c is freely redistributable under the two-clause BSD License:

Copyright (C) 2017 Carnegie Mellon University.
Copyright (C) 2018-2023 National Cheng Kung University, Taiwan.
Copyright (C) 2018-2024 National Cheng Kung University, Taiwan.
All rights reserved.

Redistribution and use in source and binary forms, with or without
Expand Down
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ $ make valgrind
* Use `$ make clean` or `$ rm /tmp/qtest.*` to clean the temporary files created by target valgrind

Extra options can be recognized by make:
* `VERBOSE`: control the build verbosity. If `VERBOSE=1`, echo eacho command in build process.
* `VERBOSE`: control the build verbosity. If `VERBOSE=1`, echo each command in build process.
* `SANITIZER`: enable sanitizer(s) directed build. At the moment, AddressSanitizer is supported.

## Using `qtest`
Expand Down Expand Up @@ -116,7 +116,7 @@ Trace files
## Debugging Facilities

Before using GDB debug `qtest`, there are some routine instructions need to do. The script `scripts/debug.py` covers these instructions and provides basic debug function.
```
```shell
$ scripts/debug.py -h
usage: debug.py [-h] [-d | -a]

Expand All @@ -126,7 +126,7 @@ optional arguments:
-a, --analyze Analyze the core dump file
```
* Enter GDB without interruption by **SIGALRM**.
```
```shell
$ scripts/debug.py -d
Reading symbols from lab0-c/qtest...done.
Signal Stop Print Pass to program Description
Expand All @@ -138,13 +138,13 @@ cmd>

The core dump file was created in the working directory of the `qtest`.
* Allow the core dumps by using shell built-in command **ulimit** to set core file size.
```
```shell
$ ulimit -c unlimited
$ ulimit -c
unlimited
```
* Enter GDB and analyze
```
```shell
$ scripts/debug.py -a
Reading symbols from lab0-c/qtest...done.
[New LWP 9424]
Expand All @@ -167,7 +167,7 @@ cmd>
A small web server is already integrated within the `qtest` command line interpreter,
and you may use it by running the `web` command in its prompt.
```
```shell
$ ./qtest
cmd> web
listen on port 9999, fd is 3
Expand Down
2 changes: 1 addition & 1 deletion queue.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ struct list_head *q_new()
}

/* Free all storage used by queue */
void q_free(struct list_head *l) {}
void q_free(struct list_head *head) {}

/* Insert an element at head of queue */
bool q_insert_head(struct list_head *head, char *s)
Expand Down
10 changes: 5 additions & 5 deletions report.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ void set_verblevel(int level)
verblevel = level;
}

bool set_logfile(char *file_name)
bool set_logfile(const char *file_name)
{
logfile = fopen(file_name, "w");
return logfile != NULL;
Expand Down Expand Up @@ -161,7 +161,7 @@ void report_noreturn(int level, char *fmt, ...)
/* Functions denoting failures */

/* Need to be able to print without using malloc */
static void fail_fun(char *format, char *msg)
static void fail_fun(const char *format, const char *msg)
{
snprintf(fail_buf, sizeof(fail_buf), format, msg);
/* Tack on return */
Expand Down Expand Up @@ -209,7 +209,7 @@ static void check_exceed(size_t new_bytes)
}

/* Call malloc & exit if fails */
void *malloc_or_fail(size_t bytes, char *fun_name)
void *malloc_or_fail(size_t bytes, const char *fun_name)
{
check_exceed(bytes);
void *p = malloc(bytes);
Expand All @@ -228,7 +228,7 @@ void *malloc_or_fail(size_t bytes, char *fun_name)
}

/* Call calloc returns NULL & exit if fails */
void *calloc_or_fail(size_t cnt, size_t bytes, char *fun_name)
void *calloc_or_fail(size_t cnt, size_t bytes, const char *fun_name)
{
check_exceed(cnt * bytes);
void *p = calloc(cnt, bytes);
Expand All @@ -246,7 +246,7 @@ void *calloc_or_fail(size_t cnt, size_t bytes, char *fun_name)
return p;
}

char *strsave_or_fail(char *s, char *fun_name)
char *strsave_or_fail(const char *s, const char *fun_name)
{
if (!s)
return NULL;
Expand Down
8 changes: 4 additions & 4 deletions report.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ typedef enum { MSG_WARN, MSG_ERROR, MSG_FATAL, N_MSG } message_t;
/* Buffer sizes */
#define MAX_CHAR 512

bool set_logfile(char *file_name);
bool set_logfile(const char *file_name);

extern int verblevel;
void set_verblevel(int level);
Expand All @@ -27,13 +27,13 @@ void report(int verblevel, char *fmt, ...);
void report_noreturn(int verblevel, char *fmt, ...);

/* Attempt to call malloc. Fail when returns NULL */
void *malloc_or_fail(size_t bytes, char *fun_name);
void *malloc_or_fail(size_t bytes, const char *fun_name);

/* Attempt to call calloc. Fail when returns NULL */
void *calloc_or_fail(size_t cnt, size_t bytes, char *fun_name);
void *calloc_or_fail(size_t cnt, size_t bytes, const char *fun_name);

/* Attempt to save string. Fail when malloc returns NULL */
char *strsave_or_fail(char *s, char *fun_name);
char *strsave_or_fail(const char *s, const char *fun_name);

/* Free block, as from malloc, or strsave */
void free_block(void *b, size_t len);
Expand Down
2 changes: 1 addition & 1 deletion scripts/debug.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,4 @@ def main(argv):
print("ERROR: qtest is not exist")
exit(1)

main(args)
main(args)
2 changes: 1 addition & 1 deletion scripts/kirby.raw
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@
⎺⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽ 
⎺⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎺ 
⎽⎼⎽⎽⎽⎽⎽⎺ 
[?25h
[?25h
5 changes: 4 additions & 1 deletion scripts/pre-commit.hook
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ CPPCHECK_suppresses="--inline-suppr harness.c \
--suppress=nullPointerRedundantCheck:report.c \
--suppress=nullPointerRedundantCheck:harness.c \
--suppress=nullPointer:queue.c \
--suppress=nullPointer:qtest.c"
--suppress=nullPointer:qtest.c \
--suppress=returnDanglingLifetime:report.c \
--suppress=constParameterCallback:console.c \
--suppress=constParameterPointer:console.c"
CPPCHECK_OPTS="-I. --enable=all --error-exitcode=1 --force $CPPCHECK_suppresses $CPPCHECK_unmatched ."

RETURN=0
Expand Down
10 changes: 5 additions & 5 deletions scripts/pre-push.hook
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ YELLOW='\033[1;33m'
NC='\033[0m' # No Color

# Validate repository
# commit c2084e68866b7eaabd95f671319d3ee01e923b32 (HEAD -> master)
# Author: Jim Huang <jserv[email protected]>
# Date: Tue Jan 24 14:59:36 2023 +0800
# commit 3ed17237af5b1ead6c394df5099bc2bc1f8392df (HEAD -> bump-copyright-year)
# Author: Jim Huang <jserv@ccns.ncku.edu.tw>
# Date: Tue Feb 20 03:59:49 2024 +0800
# Bump copyright year
commit=$(git rev-list -n 1 --grep '^Bump copyright' 0e922a9b7da49726c91f1d7176bd5fa0cada97be...HEAD)
if [ x"$commit" != x"c2084e68866b7eaabd95f671319d3ee01e923b32" ] ; then
commit=$(git rev-list --skip 1 --grep '^Bump copyright' 1aca5b98471765db50c91e03298e49bf7c08cdbc...HEAD)
if [ x"$commit" != x"3ed17237af5b1ead6c394df5099bc2bc1f8392df" ] ; then
echo -e "${RED}ERROR${NC}: This repository is insane."
echo -e "Make sure you did fork from https://github.com/sysprog21/lab0-c recently."
echo ""
Expand Down
2 changes: 1 addition & 1 deletion traces/trace-03-ops.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ reverse
rh z
rh r
rh r
rh n
rh n
2 changes: 1 addition & 1 deletion traces/trace-06-ops.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ rh a
rh b
rh c
rh a
rh a
rh a

0 comments on commit 2569288

Please sign in to comment.