Skip to content

Commit

Permalink
WTF
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin Newton committed Jan 15, 2025
1 parent 39e2eb0 commit 54ba1f8
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 65 deletions.
124 changes: 62 additions & 62 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,30 +22,30 @@ jobs:
fail-fast: false
matrix:
include:
- wheel: "linux-3.12"
os: ubuntu-latest
CIBW_BUILD: "cp312-*"
- wheel: "linux-3.13"
os: ubuntu-latest
CIBW_BUILD: "cp313-*"
- wheel: "linux-3.13t"
os: ubuntu-latest
CIBW_BUILD: "cp313t-*"
CIBW_ENABLE: "cpython-freethreading"
# - wheel: "linux-3.12"
# os: ubuntu-latest
# CIBW_BUILD: "cp312-*"
# - wheel: "linux-3.13"
# os: ubuntu-latest
# CIBW_BUILD: "cp313-*"
# - wheel: "linux-3.13t"
# os: ubuntu-latest
# CIBW_BUILD: "cp313t-*"
# CIBW_ENABLE: "cpython-freethreading"
- wheel: "windows-3.13"
os: windows-latest
CIBW_BUILD: "cp313-*"
CIBW_BUILD: "cp313-win_amd64"
- wheel: "windows-3.13t"
os: windows-latest
CIBW_BUILD: "cp313t-*"
CIBW_BUILD: "cp313t-win_amd64"
CIBW_ENABLE: "cpython-freethreading"
- wheel: "macos-3.13"
os: macos-latest
CIBW_BUILD: "cp313-*"
- wheel: "macos-3.13t"
os: macos-latest
CIBW_BUILD: "cp313t-*"
CIBW_ENABLE: "cpython-freethreading"
# - wheel: "macos-3.13t"
# os: macos-latest
# CIBW_BUILD: "cp313t-*"
# CIBW_ENABLE: "cpython-freethreading"

runs-on: ${{ matrix.os }}

Expand All @@ -66,7 +66,7 @@ jobs:
env:
CIBW_BUILD: ${{ matrix.CIBW_BUILD }}
CIBW_ENABLE: ${{ matrix.CIBW_ENABLE }}
CIBW_TEST_COMMAND: python -m ft_utils.tests.test_run_all
CIBW_TEST_COMMAND: python -m ft_utils.tests.test_weave

- name: Upload Python wheels
uses: actions/upload-artifact@v4
Expand All @@ -75,48 +75,48 @@ jobs:
path: wheelhouse/*.whl


deadsnakes:
strategy:
fail-fast: false
matrix:
include:
- wheel: "linux-3.14"
python-version: "3.14-dev"
nogil: false
- wheel: "linux-3.14t"
python-version: "3.14-dev"
nogil: true

runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Python
uses: deadsnakes/[email protected]
with:
python-version: ${{ matrix.python-version }}
nogil: ${{ matrix.nogil }}

- name: Install build dependencies
run: python -m pip install --upgrade setuptools wheel

- name: Build Python wheels
run: python setup.py bdist_wheel

- name: Install wheels
run: python -m pip install build/dist/*.whl

- name: Test Python wheels
run: |
mkdir test_dir
cd test_dir
python -V
python -m ft_utils.tests.test_run_all
- name: Upload Python wheels
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.wheel }}.zip
path: build/dist/*.whl
# deadsnakes:
# strategy:
# fail-fast: false
# matrix:
# include:
# - wheel: "linux-3.14"
# python-version: "3.14-dev"
# nogil: false
# - wheel: "linux-3.14t"
# python-version: "3.14-dev"
# nogil: true

# runs-on: ubuntu-latest

# steps:
# - name: Checkout code
# uses: actions/checkout@v4

# - name: Set up Python
# uses: deadsnakes/[email protected]
# with:
# python-version: ${{ matrix.python-version }}
# nogil: ${{ matrix.nogil }}

# - name: Install build dependencies
# run: python -m pip install --upgrade setuptools wheel

# - name: Build Python wheels
# run: python setup.py bdist_wheel

# - name: Install wheels
# run: python -m pip install build/dist/*.whl

# - name: Test Python wheels
# run: |
# mkdir test_dir
# cd test_dir
# python -V
# python -m ft_utils.tests.test_run_all

# - name: Upload Python wheels
# uses: actions/upload-artifact@v4
# with:
# name: ${{ matrix.wheel }}.zip
# path: build/dist/*.whl
19 changes: 18 additions & 1 deletion _weave.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@
==============================
*/

void* wvls_current_thread() {
#ifdef _WIN32
return GetCurrentFiber();
#else
return NULL;
#endif
}

#ifdef _WIN32

int wvls_ensure_fiber() {
Expand Down Expand Up @@ -41,6 +49,7 @@ int wvls_key_create(wvls_key_t* key, wvls_destructor_t destructor) {
return GetLastError();
}

fprintf(stderr, "[%p][%-24s] creating key %lu\n", wvls_current_thread(), "wvls_key_create", *key);
return 0;
}

Expand Down Expand Up @@ -91,6 +100,7 @@ int wvls_set_value(wvls_key_t key, void* value) {
return GetLastError();
}

fprintf(stderr, "[%p][%-24s] setting key %lu to %p\n", wvls_current_thread(), "wvls_set_value", key, value);
return 0;
}

Expand All @@ -103,7 +113,9 @@ void* wvls_get_value(wvls_key_t key) {
return NULL;
}

return FlsGetValue(key);
void* value = FlsGetValue(key);
fprintf(stderr, "[%p][%-24s] getting key %lu with value %p\n", wvls_current_thread(), "wvls_get_value", key, value);
return value;
}

#else /* POSIX */
Expand Down Expand Up @@ -163,13 +175,17 @@ void wvls_destructors_invoke(void* arg) {
}
node = previous;
while (node) {
fprintf(stderr, "[%p][%-24s] invoking destructor for %p\n", wvls_current_thread(), "wvls_destructors_invoke", node);
if (node->destructor && node->wvls_variable_ptr) {
node->destructor(*(node->wvls_variable_ptr));
}
wvls_destructor_node_t* temp = node;
node = node->next;
fprintf(stderr, "[%p][%-24s] freeing node %p\n", wvls_current_thread(), "wvls_destructors_invoke", temp);
free(temp);
}

fprintf(stderr, "[%p][%-24s] done\n", wvls_current_thread(), "wvls_destructors_invoke");
}

static void init_wvls_destructor_key() {
Expand Down Expand Up @@ -199,6 +215,7 @@ void register_wvls_destructor(
abort();
}

fprintf(stderr, "[%p][%-24s] inserting node %p\n", wvls_current_thread(), "register_wvls_destructor", node);
node->wvls_variable_ptr = wvls_variable_ptr;
node->destructor = destructor;
node->next = head;
Expand Down
9 changes: 7 additions & 2 deletions test_weave.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,19 @@ def setUp(self):

def test_register_destructor_1(self):
def thread_func():
print("thread starting!", file=sys.stderr)
register_destructor_1()
pass
print("thread ending!", file=sys.stderr)

print("thread spawning", file=sys.stderr)
t = threading.Thread(target=thread_func)
t.start()
t.join()
print("thread joined", file=sys.stderr)
self.assertEqual(get_destructor_called_1(), 1)


"""
def test_unregister_destructor_1(self):
register_destructor_1()
self.assertEqual(1, unregister_destructor_1())
Expand Down Expand Up @@ -130,7 +135,7 @@ def thread_func():
for t in threads:
t.join()
self.assertEqual(get_destructor_called_1(), num_threads)

"""

if __name__ == "__main__":
unittest.main()

0 comments on commit 54ba1f8

Please sign in to comment.