Tarantool development patches archive
 help / color / mirror / Atom feed
From: Vladislav Shpilevoy <v.shpilevoy@tarantool.org>
To: tarantool-patches@freelists.org, imeevma@tarantool.org
Cc: vdavydov.dev@gmail.com
Subject: Re: [tarantool-patches] [PATCH v2 2/3] lua: internal function to parse space format
Date: Fri, 21 Jun 2019 22:39:40 +0200	[thread overview]
Message-ID: <5a5beb84-0bee-2a9c-41f7-b4b275c0fd42@tarantool.org> (raw)
In-Reply-To: <bb85acfd88ba9a39c4431b82d2e25f7978889062.1561130584.git.imeevma@gmail.com>

Thanks for the patch!

> +
> +static int
> +lbox_tuple_format_new(struct lua_State *L)
> +{
> +	assert(CTID_STRUCT_TUPLE_FORMAT_PTR != 0);
> +	if (lua_gettop(L) == 0)
> +		return lbox_push_tuple_format(L, tuple_format_runtime);
> +	if (lua_gettop(L) > 1 || ! lua_istable(L, 1))
> +		return luaL_error(L, "Usage: box.internal.format_new(format)");
> +	uint32_t count = lua_objlen(L, 1);
> +	if (count == 0)
> +		return lbox_push_tuple_format(L, tuple_format_runtime);
> +	size_t size = count * sizeof(struct field_def);
> +	struct region *region = &fiber()->gc;
> +	size_t region_svp = region_used(region);
> +	struct field_def *fields =
> +		(struct field_def *)region_alloc(region, size);
> +	if (fields == NULL) {
> +		diag_set(OutOfMemory, size, "region_alloc", "fields");
> +		return luaT_error(L);
> +	}
> +	for (uint32_t i = 0; i < count; ++i) {
> +		size_t len;
> +
> +		fields[i] = field_def_default;
> +
> +		lua_pushinteger(L, i + 1);
> +		lua_gettable(L, 1);
> +
> +		lua_pushstring(L, "type");
> +		lua_gettable(L, -2);
> +		if (! lua_isnil(L, -1)) {
> +			const char *type_name = lua_tolstring(L, -1, &len);
> +			fields[i].type = field_type_by_name(type_name, len);
> +			if (fields[i].type == field_type_MAX) {
> +				const char *err =
> +					"field %d has unknown field type";
> +				return luaL_error(L, tt_sprintf(err, i + 1));

Here and in all other 'return on error' the region leaks. But there is
another point. How can there be errors, if the method is internal? If I
had implemented that patch, I would panic/assert on any error here, except
region OOM.

  reply	other threads:[~2019-06-21 20:39 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-06-21 15:25 [PATCH v2 0/3] netbox: define formats for tuple from netbox imeevma
2019-06-21 15:25 ` [PATCH v2 1/3] netbox: store method_encoder args in request imeevma
2019-06-21 20:39   ` [tarantool-patches] " Vladislav Shpilevoy
2019-06-21 15:25 ` [PATCH v2 2/3] lua: internal function to parse space format imeevma
2019-06-21 20:39   ` Vladislav Shpilevoy [this message]
2019-06-21 15:25 ` [PATCH v2 3/3] netbox: define formats for tuple from netbox imeevma
2019-06-21 20:39   ` [tarantool-patches] " Vladislav Shpilevoy

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5a5beb84-0bee-2a9c-41f7-b4b275c0fd42@tarantool.org \
    --to=v.shpilevoy@tarantool.org \
    --cc=imeevma@tarantool.org \
    --cc=tarantool-patches@freelists.org \
    --cc=vdavydov.dev@gmail.com \
    --subject='Re: [tarantool-patches] [PATCH v2 2/3] lua: internal function to parse space format' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox