Skip to content

Commit c2da1c6

Browse files
committed
Switch to multi phase init
1 parent 74ac546 commit c2da1c6

File tree

17 files changed

+184
-277
lines changed

17 files changed

+184
-277
lines changed

.clang-format

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
DisableFormat: true

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ a.py
2727
# Logs
2828
*.log
2929
vgcore.*
30-
valgrind.txt
30+
valgrind.txt*
3131

3232
# JavaScript
3333
node_modules/

include/view/backport.h

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,17 @@
33

44
#include <Python.h>
55

6+
#if PY_MAJOR_VERSION != 3
7+
#error "this file assumes python 3"
8+
#endif
9+
610
#ifndef _PyObject_Vectorcall
711
#define VIEW_NEEDS_VECTORCALL
8-
PyObject* _PyObject_VectorcallBackport(
9-
PyObject* obj,
10-
PyObject** args,
12+
PyObject * _PyObject_VectorcallBackport(
13+
PyObject *obj,
14+
PyObject **args,
1115
size_t nargsf,
12-
PyObject* kwargs
16+
PyObject *kwargs
1317
);
1418

1519
#define PyObject_CallNoArgs(o) PyObject_CallObject(o, NULL)
@@ -18,19 +22,19 @@ PyObject* _PyObject_VectorcallBackport(
1822
#endif
1923

2024
#if PY_VERSION_HEX < 0x030c0000
21-
PyObject* PyErr_GetRaisedException(void);
22-
void PyErr_SetRaisedException(PyObject* err);
25+
PyObject * PyErr_GetRaisedException(void);
26+
void PyErr_SetRaisedException(PyObject *err);
2327
#endif
2428

2529
#ifndef Py_NewRef
2630
#define VIEW_NEEDS_NEWREF
27-
PyObject* Py_NewRef_Backport(PyObject* o);
31+
PyObject * Py_NewRef_Backport(PyObject *o);
2832
#define Py_NewRef Py_NewRef_Backport
2933
#endif
3034

3135
#ifndef Py_XNewRef
3236
#define VIEW_NEEDS_XNEWREF
33-
PyObject* Py_XNewRef_Backport(PyObject* o);
37+
PyObject * Py_XNewRef_Backport(PyObject *o);
3438
#define Py_XNewRef Py_XNewRef_Backport
3539
#endif
3640

@@ -40,7 +44,25 @@ PyObject* Py_XNewRef_Backport(PyObject* o);
4044

4145
#if PY_MINOR_VERSION == 8
4246
#define PyObject_CallOneArg(func, val) \
43-
PyObject_Vectorcall(func, (PyObject*[]) { val }, 1, NULL)
47+
PyObject_Vectorcall(func, (PyObject *[]) { val }, 1, NULL)
48+
#endif
49+
50+
#if PY_MINOR_VERSION < 13
51+
static int
52+
PyModule_Add(PyObject *module, const char *name, PyObject *value)
53+
{
54+
if (value == NULL)
55+
{
56+
return -1;
57+
}
58+
if (PyModule_AddObject(module, name, value) < 0)
59+
{
60+
Py_DECREF(value);
61+
return -1;
62+
}
63+
return 0;
64+
}
65+
4466
#endif
4567

4668
#endif

include/view/context.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44
#include <Python.h> // PyObject, PyTypeObject
55

66
extern PyTypeObject ContextType;
7-
PyObject* context_from_data(PyObject* app, PyObject* scope);
7+
PyObject * context_from_data(PyObject *app, PyObject *scope);
88

99
#endif

include/view/inputs.h

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,49 +5,51 @@
55

66
#include <view/typecodes.h> // type_info
77

8-
typedef struct _app_parsers {
9-
PyObject* query;
10-
PyObject* json;
8+
typedef struct _app_parsers
9+
{
10+
PyObject *query;
11+
PyObject *json;
1112
} app_parsers;
1213

13-
int body_inc_buf(PyObject* awaitable, PyObject* result);
14+
int body_inc_buf(PyObject *awaitable, PyObject *result);
1415

15-
PyObject* query_parser(
16-
app_parsers* parsers,
17-
const char* data
16+
PyObject * query_parser(
17+
app_parsers *parsers,
18+
const char *data
1819
);
1920

20-
typedef struct _route_input {
21+
typedef struct _route_input
22+
{
2123
int route_data; // If this is above 0, assume all other items are undefined.
22-
type_info** types;
24+
type_info **types;
2325
Py_ssize_t types_size;
24-
PyObject* df;
25-
PyObject** validators;
26+
PyObject *df;
27+
PyObject **validators;
2628
Py_ssize_t validators_size;
27-
char* name;
29+
char *name;
2830
bool is_body;
2931
} route_input;
3032

31-
PyObject* build_data_input(
33+
PyObject * build_data_input(
3234
int num,
33-
PyObject* app,
34-
PyObject* scope,
35-
PyObject* receive,
36-
PyObject* send
35+
PyObject *app,
36+
PyObject *scope,
37+
PyObject *receive,
38+
PyObject *send
3739
);
3840

3941
typedef struct _ViewApp ViewApp; // Including "app.h" is a circular dependency
4042

41-
PyObject** generate_params(
42-
ViewApp* app,
43-
app_parsers* parsers,
44-
const char* data,
45-
PyObject* query,
46-
route_input** inputs,
43+
PyObject ** generate_params(
44+
ViewApp *app,
45+
app_parsers *parsers,
46+
const char *data,
47+
PyObject *query,
48+
route_input **inputs,
4749
Py_ssize_t inputs_size,
48-
PyObject* scope,
49-
PyObject* receive,
50-
PyObject* send
50+
PyObject *scope,
51+
PyObject *receive,
52+
PyObject *send
5153
);
5254

5355
#endif

include/view/map.h

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,28 @@
33

44
#include <Python.h> // Py_ssize_t
55

6-
typedef void (* map_free_func)(void*);
7-
typedef void (* map_print_func)(void*);
6+
typedef void (* map_free_func)(void *);
7+
typedef void (* map_print_func)(void *);
88

9-
typedef struct STRUCT_MAP_PAIR {
10-
char* key;
11-
void* value;
9+
typedef struct STRUCT_MAP_PAIR
10+
{
11+
char *key;
12+
void *value;
1213
} pair;
1314

14-
typedef struct STRUCT_MAP {
15+
typedef struct STRUCT_MAP
16+
{
1517
Py_ssize_t len;
1618
Py_ssize_t capacity;
17-
pair** items;
19+
pair **items;
1820
map_free_func dealloc;
1921
} map;
2022

21-
void* map_get(map* m, const char* key);
22-
map* map_new(Py_ssize_t inital_capacity, map_free_func dealloc);
23-
void map_set(map* m, const char* key, void* value);
24-
void map_free(map* m);
25-
map* map_copy(map* m);
26-
void print_map(map* m, map_print_func pr);
23+
void * map_get(map *m, const char *key);
24+
map * map_new(Py_ssize_t inital_capacity, map_free_func dealloc);
25+
void map_set(map *m, const char *key, void *value);
26+
void map_free(map *m);
27+
map * map_copy(map *m);
28+
void print_map(map *m, map_print_func pr);
2729

2830
#endif

include/view/results.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44
#include <Python.h> // PyObject
55

66
int handle_result(
7-
PyObject* raw_result,
8-
char** res_target,
9-
int* status_target,
10-
PyObject** headers_target,
11-
PyObject* raw_path,
12-
const char* method
7+
PyObject *raw_result,
8+
char **res_target,
9+
int *status_target,
10+
PyObject **headers_target,
11+
PyObject *raw_path,
12+
const char *method
1313
);
14-
char* pymem_strdup(const char* c, Py_ssize_t size);
15-
PyObject* build_default_headers();
14+
char * pymem_strdup(const char *c, Py_ssize_t size);
15+
PyObject * build_default_headers();
1616

1717
#endif

include/view/typecodes.h

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,36 +7,39 @@
77
typedef struct Route route; // route.h depends on this file
88
extern PyTypeObject TCPublicType;
99

10-
typedef enum {
10+
typedef enum
11+
{
1112
STRING_ALLOWED = 1 << 0,
1213
NULL_ALLOWED = 2 << 0
1314
} typecode_flag;
1415

1516
typedef struct _type_info type_info;
1617

17-
struct _type_info {
18+
struct _type_info
19+
{
1820
uint8_t typecode;
19-
PyObject* ob;
20-
type_info** children;
21+
PyObject *ob;
22+
type_info **children;
2123
Py_ssize_t children_size;
22-
PyObject* df;
24+
PyObject *df;
2325
};
2426

25-
bool figure_has_body(PyObject* inputs);
27+
bool figure_has_body(PyObject *inputs);
2628

2729
int load_typecodes(
28-
route* r,
29-
PyObject* target
30+
route *r,
31+
PyObject *target
3032
);
3133

32-
PyObject* cast_from_typecodes(
33-
type_info** codes,
34+
PyObject *
35+
cast_from_typecodes(
36+
type_info **codes,
3437
Py_ssize_t len,
35-
PyObject* item,
36-
PyObject* json_parser,
38+
PyObject *item,
39+
PyObject *json_parser,
3740
bool allow_casting
3841
);
39-
type_info** build_type_codes(PyObject* type_codes, Py_ssize_t len);
40-
void free_type_codes(type_info** codes, Py_ssize_t len);
42+
type_info ** build_type_codes(PyObject *type_codes, Py_ssize_t len);
43+
void free_type_codes(type_info **codes, Py_ssize_t len);
4144

4245
#endif

include/view/view.h

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,17 @@
44
#include <Python.h> // PyObject
55

66
void view_fatal(
7-
const char* message,
8-
const char* where,
9-
const char* func,
7+
const char *message,
8+
const char *where,
9+
const char *func,
1010
int lineno
1111
);
1212

13-
extern PyObject* ip_address;
14-
extern PyObject* invalid_status_error;
15-
extern PyObject* route_log;
16-
extern PyObject* route_warn;
17-
extern PyObject* ws_cls;
18-
extern PyObject* ws_disconnect_err;
19-
extern PyObject* ws_err_cls;
20-
extern PyObject* default_headers;
13+
extern PyObject *ip_address;
14+
extern PyObject *invalid_status_error;
15+
extern PyObject *route_log;
16+
extern PyObject *route_warn;
17+
extern PyObject *default_headers;
2118

2219
#if defined(__LINE__) && defined(__FILE__)
2320
#define VIEW_FATAL(msg) view_fatal(msg, __FILE__, __func__, __LINE__)

include/view/ws.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@
55
#include <view/backport.h>
66

77
extern PyTypeObject WebSocketType;
8-
PyObject* ws_from_data(PyObject* scope, PyObject* send, PyObject* receive);
8+
PyObject * ws_from_data(PyObject *scope, PyObject *send, PyObject *receive);
99

1010
#endif

0 commit comments

Comments
 (0)