Skip to content

Commit 54284f4

Browse files
committed
Shenanigans.
1 parent 2e3d47a commit 54284f4

File tree

6 files changed

+61
-75
lines changed

6 files changed

+61
-75
lines changed

.github/workflows/build.yml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,6 @@ env:
1313
SKBUILD_CMAKE_BUILD_TYPE: "Release"
1414
CIBW_SKIP: >
1515
pp*
16-
<<<<<<< HEAD
17-
PYTHONMALLOC: "malloc"
18-
PYTHONDEVMODE: "1"
19-
HATCH_VERBOSE: "1"
20-
=======
21-
>>>>>>> b9b43de5bfda018d39bedd5d278e1e1db3c8bf58
2216
2317
jobs:
2418
binary-wheels-standard:

.github/workflows/memory_check.yml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,10 @@ jobs:
2929
with:
3030
python-version: 3.12
3131

32-
<<<<<<< HEAD
33-
- name: Install Hatch
34-
run: pip install hatch
35-
=======
3632
- name: Install Pytest
3733
run: |
3834
pip install pytest pytest-asyncio pytest-memray
3935
shell: bash
40-
>>>>>>> b9b43de5bfda018d39bedd5d278e1e1db3c8bf58
4136

4237
- name: Build view.py
4338
run: pip install .[full]

.github/workflows/tests.yml

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -37,22 +37,11 @@ jobs:
3737
with:
3838
python-version: ${{ matrix.python-version }}
3939

40-
<<<<<<< HEAD
41-
- name: Install Hatch
42-
run: pip install hatch
43-
44-
- name: Build project
45-
run: pip install .[full]
46-
47-
- name: Run tests
48-
run: hatch run test:no-cov
49-
=======
50-
- name: Install Pytest
40+
- name: Install Pytest
5141
run: pip install pytest pytest-asyncio
52-
42+
5343
- name: Build view.py
5444
run: pip install .[full]
5545

5646
- name: Run tests
5747
run: pytest -x
58-
>>>>>>> b9b43de5bfda018d39bedd5d278e1e1db3c8bf58

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ __pycache__/
88
# LSP
99
.vscode/
1010
compile_flags.txt
11+
pyawaitable.h
1112

1213
# View Configurations
1314
view.toml

src/_view/app.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ new(PyTypeObject *tp, PyObject *args, PyObject *kwds)
184184
self->server_errors[i] = NULL;
185185

186186
self->has_path_params = false;
187+
self->error_type = NULL;
187188

188189
return (PyObject *) self;
189190
}
@@ -230,6 +231,8 @@ lifespan(PyObject *awaitable, PyObject *result)
230231
result,
231232
"type"
232233
);
234+
if (tp == NULL)
235+
return PyErr_BadASGI();
233236
const char *type = PyUnicode_AsUTF8(tp);
234237

235238
bool is_startup = !strcmp(
@@ -1191,6 +1194,7 @@ register_error(ViewApp *self, PyObject *args)
11911194
}
11921195

11931196
self->error_type = Py_NewRef(type);
1197+
printf("a self->error_type: %p\n", self->error_type);
11941198
Py_RETURN_NONE;
11951199
}
11961200

src/_view/errors.c

Lines changed: 54 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ finalize_err_cb(PyObject *awaitable, PyObject *result)
329329
PyObject *raw_path;
330330
const char *method_str;
331331
route *r;
332-
int is_http;
332+
long is_http;
333333

334334
if (
335335
PyAwaitable_UnpackValues(
@@ -767,75 +767,78 @@ route_error(
767767
)
768768
return -1;
769769

770-
int is_http;
770+
long is_http;
771771

772772
if (PyAwaitable_UnpackIntValues(awaitable, &is_http) < 0)
773773
return -1;
774774

775-
if (PyErr_GivenExceptionMatches(err, self->error_type))
776-
{
777-
PyObject *status_obj = PyObject_GetAttrString(
778-
err,
779-
"status"
780-
);
781-
if (!status_obj)
782-
return -2;
775+
if (self->error_type != NULL)
776+
// Under general cirumstances, error_type should never
777+
// be NULL. But, we might as well support it.
778+
if (PyErr_GivenExceptionMatches(err, self->error_type))
779+
{
780+
PyObject *status_obj = PyObject_GetAttrString(
781+
err,
782+
"status"
783+
);
784+
if (!status_obj)
785+
return -2;
783786

784-
PyObject *msg_obj = PyObject_GetAttrString(
785-
err,
786-
"message"
787-
);
787+
PyObject *msg_obj = PyObject_GetAttrString(
788+
err,
789+
"message"
790+
);
788791

789-
if (!msg_obj)
790-
{
791-
Py_DECREF(status_obj);
792-
return -2;
793-
}
792+
if (!msg_obj)
793+
{
794+
Py_DECREF(status_obj);
795+
return -2;
796+
}
794797

795-
int status = PyLong_AsLong(status_obj);
796-
if ((status == -1) && PyErr_Occurred())
797-
{
798-
Py_DECREF(status_obj);
799-
Py_DECREF(msg_obj);
800-
return -2;
801-
}
798+
int status = PyLong_AsLong(status_obj);
799+
if ((status == -1) && PyErr_Occurred())
800+
{
801+
Py_DECREF(status_obj);
802+
Py_DECREF(msg_obj);
803+
return -2;
804+
}
802805

803-
const char *message = NULL;
806+
const char *message = NULL;
804807

805-
if (msg_obj != Py_None)
806-
{
807-
message = PyUnicode_AsUTF8(msg_obj);
808-
if (!message)
808+
if (msg_obj != Py_None)
809+
{
810+
message = PyUnicode_AsUTF8(msg_obj);
811+
if (!message)
812+
{
813+
Py_DECREF(status_obj);
814+
Py_DECREF(msg_obj);
815+
return -2;
816+
}
817+
}
818+
819+
if (
820+
fire_error(
821+
self,
822+
awaitable,
823+
status,
824+
r,
825+
NULL,
826+
message,
827+
method_str,
828+
is_http
829+
) < 0
830+
)
809831
{
810832
Py_DECREF(status_obj);
811833
Py_DECREF(msg_obj);
812834
return -2;
813835
}
814-
}
815836

816-
if (
817-
fire_error(
818-
self,
819-
awaitable,
820-
status,
821-
r,
822-
NULL,
823-
message,
824-
method_str,
825-
is_http
826-
) < 0
827-
)
828-
{
829837
Py_DECREF(status_obj);
830838
Py_DECREF(msg_obj);
831-
return -2;
839+
return 0;
832840
}
833841

834-
Py_DECREF(status_obj);
835-
Py_DECREF(msg_obj);
836-
return 0;
837-
}
838-
839842
if (!is_http)
840843
{
841844
// send a websocket error code

0 commit comments

Comments
 (0)