Skip to content

Commit e69c367

Browse files
committed
Add docs site and GitHub Pages deployment
1 parent 41e96e9 commit e69c367

25 files changed

Lines changed: 7141 additions & 85 deletions

‎.github/workflows/pages.yml‎

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
name: Deploy docs site to GitHub Pages
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
workflow_dispatch:
8+
9+
permissions:
10+
contents: read
11+
pages: write
12+
id-token: write
13+
14+
concurrency:
15+
group: pages
16+
cancel-in-progress: true
17+
18+
jobs:
19+
build:
20+
runs-on: ubuntu-latest
21+
steps:
22+
- name: Checkout repository
23+
uses: actions/checkout@v4
24+
25+
- name: Configure GitHub Pages
26+
uses: actions/configure-pages@v5
27+
28+
- name: Setup Node.js
29+
uses: actions/setup-node@v4
30+
with:
31+
node-version: 20
32+
cache: npm
33+
cache-dependency-path: site/package-lock.json
34+
35+
- name: Install dependencies
36+
working-directory: site
37+
run: npm ci
38+
39+
- name: Build site
40+
working-directory: site
41+
env:
42+
GITHUB_ACTIONS: 'true'
43+
GITHUB_REPOSITORY: ${{ github.repository }}
44+
run: npm run build
45+
46+
- name: Upload build artifact
47+
uses: actions/upload-pages-artifact@v3
48+
with:
49+
path: site/dist
50+
51+
deploy:
52+
needs: build
53+
runs-on: ubuntu-latest
54+
environment:
55+
name: github-pages
56+
url: ${{ steps.deployment.outputs.page_url }}
57+
steps:
58+
- name: Deploy to GitHub Pages
59+
id: deployment
60+
uses: actions/deploy-pages@v4

‎README.md‎

Lines changed: 79 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -1,126 +1,120 @@
1-
21
# Array Macros for Dynamic Arrays
32

4-
A set of macros for managing dynamic arrays in C. These macros simplify operations like creation, resizing, and memory management.
5-
6-
---
7-
8-
## Declaring the Array Type
3+
Lightweight macro helpers for dynamic arrays in C with safer edge-case handling and better strict-C portability.
94

10-
Before using the macros, you need to declare the array type globally using the `generate_array_type(type)` macro. This should be placed in the global header scope to define the array type structure for the specified type `type`.
5+
## Declare an array type
116

127
```c
138
generate_array_type(int);
149
```
1510
16-
This declares a dynamic array type for `int`. You can use any valid C type, such as `float`, `double`, or custom structs.
11+
This creates `Array(int)` and `Slice(int)`.
1712
18-
---
13+
## API safety tiers
1914
20-
## Macros
15+
Use checked macros by default. Keep unchecked macros only for compatibility or explicitly performance-focused paths where preconditions are guaranteed.
2116
22-
### **`array_make(T, size)`**
23-
Creates a dynamic array of type `T` with an initial size.
17+
## Checked APIs (recommended)
2418
25-
**Usage:**
26-
```c
27-
Array(int) myArray = array_make(int, 10);
28-
```
19+
- `array_make(T, size)`: allocate array with initial capacity (`size` can be `0`).
20+
- `array_free(arr)`: free array memory.
21+
- `array_reserve(arr, min_capacity)`: ensure capacity, returns `bool` and may update `arr` after `realloc`.
22+
- `array_try_push(arr, value)`: append one value, returns `bool`.
23+
- `array_try_at(arr, idx, out_ptr)`: bounds-checked access, returns `bool`.
24+
- `array_try_slice_t(T, arr, low, high, out_slice)`: bounds-checked slice creation, returns `bool`.
25+
- `array_back_ptr(arr)`: pointer to last element or `NULL` when empty.
26+
- `array_length(arr)`: element count.
27+
- `array_is_empty(arr)`: true if `count == 0`.
28+
- `array_length_or0(arr)`: safe length for nullable arrays.
29+
- `array_is_empty_or_true(arr)`: safe empty check for nullable arrays.
30+
- `array_start(arr)`: pointer to first element.
2931
30-
### **`array_free(arr)`**
31-
Frees the memory of the array.
32+
## Compatibility APIs (unchecked)
3233
33-
**Usage:**
34-
```c
35-
array_free(myArray);
36-
```
34+
These are kept for compatibility and speed-focused code paths:
3735
38-
### **`array_push(arr, value)`**
39-
Appends a value to the end of the array, resizing if necessary.
36+
- `array_push(arr, value)`: delegates to `array_try_push` and ignores failure.
37+
- `array_at(arr, idx)`: unchecked index access.
38+
- `array_end(arr)`: unchecked last-element pointer (invalid on empty arrays).
39+
- `array_end_unchecked(arr)`: explicit unchecked alias.
40+
- `slice_from_array_t(T, arr, low, high)`: unchecked slice creation.
4041
41-
**Usage:**
42-
```c
43-
array_push(myArray, 42);
44-
```
42+
## Portability notes
4543
46-
### **`array_start(arr)`**
47-
Returns a pointer to the first element of the array.
44+
- Strict C11/C17 path: use `array_for_each_t(T, arr, it)` and typed slice macros.
45+
- GNU/Clang convenience path: if `typeof` is supported, `array_for_each(arr, it)` is available.
4846
49-
**Usage:**
50-
```c
51-
int *start = array_start(myArray);
52-
```
53-
54-
### **`array_end(arr)`**
55-
Returns a pointer to the last element of the array.
47+
## Example (safe usage)
5648
57-
**Usage:**
5849
```c
59-
int *end = array_end(myArray);
60-
```
50+
#include <stdio.h>
51+
#include "array.h"
6152
62-
### **`array_at(arr, idx)`**
63-
Accesses the element at a specific index.
53+
generate_array_type(int);
6454
65-
**Usage:**
66-
```c
67-
int value = array_at(myArray, 2);
68-
```
55+
int main(void)
56+
{
57+
Array(int) values = array_make(int, 0);
58+
int *at0 = NULL;
6959
70-
### **`array_length(arr)`**
71-
Returns the number of elements in the array.
60+
if (!values) return 1;
61+
if (!array_try_push(values, 10)) return 1;
62+
if (!array_try_push(values, 20)) return 1;
7263
73-
**Usage:**
74-
```c
75-
usize length = array_length(myArray);
76-
```
64+
if (array_try_at(values, 0, &at0))
65+
{
66+
printf("first=%d\n", *at0);
67+
}
7768
78-
### **`array_for_each(arr, el)`**
79-
Iterates over each element in the array.
69+
array_for_each_t(int, values, it)
70+
{
71+
printf("%d\n", *it);
72+
}
8073
81-
**Usage:**
82-
```c
83-
array_for_each(myArray, el)
84-
{
85-
printf("%d\n", *el);
74+
array_free(values);
75+
return 0;
8676
}
8777
```
8878

89-
---
79+
## Edge-case behavior
9080

91-
## Example
81+
- Zero-capacity arrays grow correctly on first push.
82+
- Allocation/growth arithmetic is overflow-checked.
83+
- Reallocation failures do not discard existing array data.
84+
- `array_try_slice_t` rejects invalid ranges (`low > high` or `high > count`).
85+
- `array_try_at` and `array_try_slice_t` return `false` when output pointers are `NULL`.
9286

93-
```c
94-
#include <stdio.h>
95-
#include <stdlib.h>
87+
## Documentation
9688

97-
// Assuming macros are included
89+
Canonical Markdown docs live in `docs/`:
9890

99-
// Declare the array type globally
100-
generate_array_type(int);
91+
- [Overview](./docs/overview.md)
92+
- [Quickstart](./docs/quickstart.md)
93+
- [API Reference](./docs/api-reference.md)
94+
- [Examples](./docs/examples.md)
10195

102-
int main()
103-
{
104-
Array(int) myArray = array_make(int, 5); // Create array
96+
## Website (Vite + React + Tailwind)
10597

106-
array_push(myArray, 10); // Add values
107-
array_push(myArray, 20);
108-
array_push(myArray, 30);
98+
The project website lives in `site/` and renders the Markdown docs above.
10999

110-
array_for_each(myArray, el) // Print values
111-
{
112-
printf("%d\n", *el);
113-
}
100+
Run locally:
114101

115-
array_free(myArray); // Free memory
116-
return 0;
117-
}
102+
```sh
103+
cd site
104+
npm install
105+
npm run dev
118106
```
119107

120-
---
108+
Production build:
109+
110+
```sh
111+
cd site
112+
npm run build
113+
```
121114

122-
## Notes
115+
## GitHub Pages deployment
123116

124-
- Ensure sufficient memory when resizing arrays.
125-
- Handle memory allocation failures with error handling.
126-
- Always free arrays with `array_free` to prevent memory leaks.
117+
- Workflow file: `.github/workflows/pages.yml`
118+
- Trigger: push to `main` (or manual `workflow_dispatch`)
119+
- Output: `site/dist` uploaded as GitHub Pages artifact
120+
- Expected URL after deploy: `https://airbus5717.github.io/arraylist/`

0 commit comments

Comments
 (0)