-
Notifications
You must be signed in to change notification settings - Fork 0
/
libevent-2.0.4-alpha-msg-new-with-arg.patch
218 lines (203 loc) · 7.5 KB
/
libevent-2.0.4-alpha-msg-new-with-arg.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
diff --git a/event_rpcgen.py b/event_rpcgen.py
index f8d14d6..9eb7576 100755
--- a/event_rpcgen.py
+++ b/event_rpcgen.py
@@ -117,6 +117,7 @@ class StructCCode(Struct):
print >>file, \
"""struct %(name)s *%(name)s_new(void);
+struct %(name)s *%(name)s_new_with_arg(void *);
void %(name)s_free(struct %(name)s *);
void %(name)s_clear(struct %(name)s *);
void %(name)s_marshal(struct evbuffer *, const struct %(name)s *);
@@ -157,6 +158,12 @@ int evtag_unmarshal_%(name)s(struct evbuffer *, ev_uint32_t,
'struct %(name)s *\n'
'%(name)s_new(void)\n'
'{\n'
+ ' return %(name)s_new_with_arg(NULL);\n'
+ '}\n'
+ '\n'
+ 'struct %(name)s *\n'
+ '%(name)s_new_with_arg(void *unused)\n'
+ '{\n'
' struct %(name)s *tmp;\n'
' if ((tmp = malloc(sizeof(struct %(name)s))) == NULL) {\n'
' event_warn("%%s: malloc", __func__);\n'
diff --git a/evrpc.c b/evrpc.c
index 6ba1382..939260a 100644
--- a/evrpc.c
+++ b/evrpc.c
@@ -339,7 +339,7 @@ evrpc_request_cb_closure(void *arg, enum EVRPC_HOOK_RESULT hook_res)
goto error;
/* let's check that we can parse the request */
- rpc_state->request = rpc->request_new();
+ rpc_state->request = rpc->request_new(rpc->request_new_arg);
if (rpc_state->request == NULL)
goto error;
@@ -351,7 +351,7 @@ evrpc_request_cb_closure(void *arg, enum EVRPC_HOOK_RESULT hook_res)
/* at this point, we have a well formed request, prepare the reply */
- rpc_state->reply = rpc->reply_new();
+ rpc_state->reply = rpc->reply_new(rpc->reply_new_arg);
if (rpc_state->reply == NULL)
goto error;
@@ -1069,9 +1069,9 @@ error:
/** Takes a request object and fills it in with the right magic */
static struct evrpc *
evrpc_register_object(const char *name,
- void *(*req_new)(void), void (*req_free)(void *),
+ void *(*req_new)(void*), void *req_new_arg, void (*req_free)(void *),
int (*req_unmarshal)(void *, struct evbuffer *),
- void *(*rpl_new)(void), void (*rpl_free)(void *),
+ void *(*rpl_new)(void*), void *rpl_new_arg, void (*rpl_free)(void *),
int (*rpl_complete)(void *),
void (*rpl_marshal)(struct evbuffer *, void *))
{
@@ -1084,9 +1084,11 @@ evrpc_register_object(const char *name,
return (NULL);
}
rpc->request_new = req_new;
+ rpc->request_new_arg = req_new_arg;
rpc->request_free = req_free;
rpc->request_unmarshal = req_unmarshal;
rpc->reply_new = rpl_new;
+ rpc->reply_new_arg = rpl_new_arg;
rpc->reply_free = rpl_free;
rpc->reply_complete = rpl_complete;
rpc->reply_marshal = rpl_marshal;
@@ -1096,15 +1098,15 @@ evrpc_register_object(const char *name,
int
evrpc_register_generic(struct evrpc_base *base, const char *name,
void (*callback)(struct evrpc_req_generic *, void *), void *cbarg,
- void *(*req_new)(void), void (*req_free)(void *),
+ void *(*req_new)(void *), void *req_new_arg, void (*req_free)(void *),
int (*req_unmarshal)(void *, struct evbuffer *),
- void *(*rpl_new)(void), void (*rpl_free)(void *),
+ void *(*rpl_new)(void *), void *rpl_new_arg, void (*rpl_free)(void *),
int (*rpl_complete)(void *),
void (*rpl_marshal)(struct evbuffer *, void *))
{
struct evrpc* rpc =
- evrpc_register_object(name, req_new, req_free, req_unmarshal,
- rpl_new, rpl_free, rpl_complete, rpl_marshal);
+ evrpc_register_object(name, req_new, req_new_arg, req_free, req_unmarshal,
+ rpl_new, rpl_new_arg, rpl_free, rpl_complete, rpl_marshal);
if (rpc == NULL)
return (-1);
evrpc_register_rpc(base, rpc,
diff --git a/include/event2/rpc.h b/include/event2/rpc.h
index b735a1c..4f2f404 100644
--- a/include/event2/rpc.h
+++ b/include/event2/rpc.h
@@ -315,10 +315,10 @@ void evrpc_free(struct evrpc_base *base);
#define EVRPC_REGISTER(base, name, request, reply, callback, cbarg) \
evrpc_register_generic(base, #name, \
(void (*)(struct evrpc_req_generic *, void *))callback, cbarg, \
- (void *(*)(void))request##_new, \
+ (void *(*)(void *))request##_new, NULL, \
(void (*)(void *))request##_free, \
(int (*)(void *, struct evbuffer *))request##_unmarshal, \
- (void *(*)(void))reply##_new, \
+ (void *(*)(void *))reply##_new, NULL, \
(void (*)(void *))reply##_free, \
(int (*)(void *))reply##_complete, \
(void (*)(struct evbuffer *, void *))reply##_marshal)
@@ -571,9 +571,9 @@ int evrpc_send_request_generic(struct evrpc_pool *pool,
int
evrpc_register_generic(struct evrpc_base *base, const char *name,
void (*callback)(struct evrpc_req_generic *, void *), void *cbarg,
- void *(*req_new)(void), void (*req_free)(void *),
+ void *(*req_new)(void *), void *req_new_arg, void (*req_free)(void *),
int (*req_unmarshal)(void *, struct evbuffer *),
- void *(*rpl_new)(void), void (*rpl_free)(void *),
+ void *(*rpl_new)(void *), void *rpl_new_arg, void (*rpl_free)(void *),
int (*rpl_complete)(void *),
void (*rpl_marshal)(struct evbuffer *, void *));
diff --git a/include/event2/rpc_struct.h b/include/event2/rpc_struct.h
index 3141156..1586c8a 100644
--- a/include/event2/rpc_struct.h
+++ b/include/event2/rpc_struct.h
@@ -63,7 +63,8 @@ struct evrpc {
const char* uri;
/* creates a new request structure */
- void *(*request_new)(void);
+ void *(*request_new)(void *);
+ void *request_new_arg;
/* frees the request structure */
void (*request_free)(void *);
@@ -72,9 +73,10 @@ struct evrpc {
int (*request_unmarshal)(void *, struct evbuffer *);
/* creates a new reply structure */
- void *(*reply_new)(void);
+ void *(*reply_new)(void *);
+ void *reply_new_arg;
- /* creates a new reply structure */
+ /* frees the reply structure */
void (*reply_free)(void *);
/* verifies that the reply is valid */
diff --git a/test/regress.gen.c b/test/regress.gen.c
index 59fd74b..cf2e52d 100644
--- a/test/regress.gen.c
+++ b/test/regress.gen.c
@@ -41,6 +41,12 @@ static struct msg_access_ __msg_base = {
struct msg *
msg_new(void)
{
+ return msg_new_with_arg(NULL);
+}
+
+struct msg *
+msg_new_with_arg(void *unused)
+{
struct msg *tmp;
if ((tmp = malloc(sizeof(struct msg))) == NULL) {
event_warn("%s: malloc", __func__);
@@ -436,6 +442,12 @@ static struct kill_access_ __kill_base = {
struct kill *
kill_new(void)
{
+ return kill_new_with_arg(NULL);
+}
+
+struct kill *
+kill_new_with_arg(void *unused)
+{
struct kill *tmp;
if ((tmp = malloc(sizeof(struct kill))) == NULL) {
event_warn("%s: malloc", __func__);
@@ -719,6 +731,12 @@ static struct run_access_ __run_base = {
struct run *
run_new(void)
{
+ return run_new_with_arg(NULL);
+}
+
+struct run *
+run_new_with_arg(void *unused)
+{
struct run *tmp;
if ((tmp = malloc(sizeof(struct run))) == NULL) {
event_warn("%s: malloc", __func__);
diff --git a/test/regress.gen.h b/test/regress.gen.h
index 6e729a9..1281b94 100644
--- a/test/regress.gen.h
+++ b/test/regress.gen.h
@@ -51,6 +51,7 @@ struct msg {
};
struct msg *msg_new(void);
+struct msg *msg_new_with_arg(void *);
void msg_free(struct msg *);
void msg_clear(struct msg *);
void msg_marshal(struct evbuffer *, const struct msg *);
@@ -105,6 +106,7 @@ struct kill {
};
struct kill *kill_new(void);
+struct kill *kill_new_with_arg(void *);
void kill_free(struct kill *);
void kill_clear(struct kill *);
void kill_marshal(struct evbuffer *, const struct kill *);
@@ -176,6 +178,7 @@ struct run {
};
struct run *run_new(void);
+struct run *run_new_with_arg(void *);
void run_free(struct run *);
void run_clear(struct run *);
void run_marshal(struct evbuffer *, const struct run *);