Commit 177e829f authored by Dmitry Frank's avatar Dmitry Frank Committed by Sergey Lyubka

Add v7 arg to _mk_ and _get_ functions

`v7_mk_undefined()` and `v7_mk_null()` are left unchanged, but marked
deprecated, and `V7_UNDEFINED` and `V7_NULL` are public now.

Xtensa code size with instrumentation: 590400 -> 590432, i.e. 32 bytes.
Xtensa code size without instrumentation: 530848 -> 531760, i.e. 912
bytes.

As objdump reveals, inside v7.c, `v7_mk_number` and others are inlined,
so the extra v7 argument is eliminated; outside of v7.c it's obviously
not inlined.

----

Also, v7_get_int() is added, which currently just casts stored double
value to int

PUBLISHED_FROM=e984b7308faf2380b3de388f238e0fae0aea545d
parent b5b672ec
--- ---
title: "mg_mk_str()" title: "MG_MK_STR()"
decl_name: "mg_mk_str" decl_name: "MG_MK_STR"
symbol_kind: "func" symbol_kind: "func"
signature: | signature: |
struct mg_str mg_mk_str(const char *s); #define MG_MK_STR(str_literal);
--- ---
A helper function for creating mg_str struct from plain C string. Macro for initializing mg_str.
`NULL` is allowed and becomes `{NULL, 0}`.
...@@ -2269,7 +2269,7 @@ void mg_mgr_init(struct mg_mgr *m, void *user_data) { ...@@ -2269,7 +2269,7 @@ void mg_mgr_init(struct mg_mgr *m, void *user_data) {
static enum v7_err mg_send_js(struct v7 *v7, v7_val_t *res) { static enum v7_err mg_send_js(struct v7 *v7, v7_val_t *res) {
v7_val_t arg0 = v7_arg(v7, 0); v7_val_t arg0 = v7_arg(v7, 0);
v7_val_t arg1 = v7_arg(v7, 1); v7_val_t arg1 = v7_arg(v7, 1);
struct mg_connection *c = (struct mg_connection *) v7_get_ptr(arg0); struct mg_connection *c = (struct mg_connection *) v7_get_ptr(v7, arg0);
size_t len = 0; size_t len = 0;
if (v7_is_string(arg1)) { if (v7_is_string(arg1)) {
...@@ -2277,7 +2277,7 @@ static enum v7_err mg_send_js(struct v7 *v7, v7_val_t *res) { ...@@ -2277,7 +2277,7 @@ static enum v7_err mg_send_js(struct v7 *v7, v7_val_t *res) {
mg_send(c, data, len); mg_send(c, data, len);
} }
*res = v7_mk_number(len); *res = v7_mk_number(v7, len);
return V7_OK; return V7_OK;
} }
...@@ -5183,9 +5183,9 @@ void mg_http_handler(struct mg_connection *nc, int ev, void *ev_data) { ...@@ -5183,9 +5183,9 @@ void mg_http_handler(struct mg_connection *nc, int ev, void *ev_data) {
} }
/* Invoke callback. TODO(lsm): report errors */ /* Invoke callback. TODO(lsm): report errors */
v7_array_push(v7, args, v7_mk_foreign(nc)); v7_array_push(v7, args, v7_mk_foreign(v7, nc));
v7_array_push(v7, args, req); v7_array_push(v7, args, req);
if (v7_apply(v7, v2, v7_mk_undefined(), args, &res) == V7_OK && if (v7_apply(v7, v2, V7_UNDEFINED, args, &res) == V7_OK &&
v7_is_truthy(v7, res)) { v7_is_truthy(v7, res)) {
js_callback_handled_request++; js_callback_handled_request++;
} }
......
...@@ -104,10 +104,12 @@ ...@@ -104,10 +104,12 @@
#define NORETURN __attribute__((noreturn)) #define NORETURN __attribute__((noreturn))
#define NOINLINE __attribute__((noinline)) #define NOINLINE __attribute__((noinline))
#define WARN_UNUSED_RESULT __attribute__((warn_unused_result)) #define WARN_UNUSED_RESULT __attribute__((warn_unused_result))
#define NOINSTR __attribute__((no_instrument_function))
#else #else
#define NORETURN #define NORETURN
#define NOINLINE #define NOINLINE
#define WARN_UNUSED_RESULT #define WARN_UNUSED_RESULT
#define NOINSTR
#endif /* __GNUC__ */ #endif /* __GNUC__ */
#ifndef ARRAY_SIZE #ifndef ARRAY_SIZE
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment