Skip to content

Commit

Permalink
Fix async name
Browse files Browse the repository at this point in the history
  • Loading branch information
joente committed Jan 24, 2024
1 parent 955b09f commit 26e61b0
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 2 deletions.
1 change: 1 addition & 0 deletions inc/ti/async.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@
#include <ti/module.h>

ti_module_t * ti_async_get_module(void);
void ti_async_init(void);

#endif /* TI_EXT_ASYNC_H_ */
1 change: 1 addition & 0 deletions inc/ti/val.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <util/vec.h>

/* name */
extern ti_val_t * val__async_name;
extern ti_val_t * val__data_name;
extern ti_val_t * val__time_name;
extern ti_val_t * val__year_name;
Expand Down
5 changes: 5 additions & 0 deletions inc/ti/val.inline.h
Original file line number Diff line number Diff line change
Expand Up @@ -805,6 +805,11 @@ static inline ti_val_t * ti_val_gmt_offset_name(void)
return ti_incref(val__gmt_offset_name), val__gmt_offset_name;
}

static inline ti_val_t * ti_val_borrow_async_name(void)
{
return val__async_name;
}

static inline ti_val_t * ti_val_borrow_year_name(void)
{
return val__year_name;
Expand Down
2 changes: 1 addition & 1 deletion inc/ti/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
* "-rc0"
* ""
*/
#define TI_VERSION_PRE_RELEASE "-alpha9"
#define TI_VERSION_PRE_RELEASE "-alpha10"

#define TI_MAINTAINER \
"Jeroen van der Heijden <jeroen@cesbit.com>"
Expand Down
19 changes: 19 additions & 0 deletions itest/test_advanced.py
Original file line number Diff line number Diff line change
Expand Up @@ -2478,6 +2478,25 @@ async def test_adv_rel(self, client):
""")
self.assertIs(res, None)

async def test_future_name(self, client):
# bug solved in v1.5.0
await client.query(r"""//ti
new_procedure("add_user", || {
return future(|| {
user = thing();
.users.add(user);
user;
});
});
.users = set();
""")

with self.assertRaisesRegex(
LookupError,
r'module `async` has no function `id`'):
await client.query(r"""//ti
user = add_user(); user.id();
""")

if __name__ == '__main__':
run_test(TestAdvanced())
3 changes: 3 additions & 0 deletions src/ti.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <ti.h>
#include <ti/access.h>
#include <ti/api.h>
#include <ti/async.h>
#include <ti/auth.h>
#include <ti/change.h>
#include <ti/collection.h>
Expand Down Expand Up @@ -244,6 +245,8 @@ int ti_init(void)
ti_thing_init_gc())
return -1;

ti_async_init(); /* after ti_val_init_common() */

shutdown_counter = (int) ti.cfg->shutdown_period;
ti.fn = strx_cat(ti.cfg->storage_path, ti__fn);
ti.node_fn = strx_cat(ti.cfg->storage_path, ti__node_fn);
Expand Down
7 changes: 7 additions & 0 deletions src/ti/async.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*/
#include <ti/async.h>
#include <ti/varr.h>
#include <ti/val.inline.h>
#include <ti/query.h>
#include <ti.h>

Expand Down Expand Up @@ -54,8 +55,14 @@ static ti_module_t async__module = {
.ref = 1,
.status = TI_MODULE_STAT_RUNNING,
.cb = (ti_module_cb) async__cb,
.name = NULL,
};

void ti_async_init(void)
{
async__module.name = (ti_name_t *) ti_val_borrow_async_name();
}

ti_module_t * ti_async_get_module(void)
{
return &async__module;
Expand Down
4 changes: 3 additions & 1 deletion src/ti/val.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ static ti_val_t * val__gs_str;
static ti_val_t * val__charset_str;

/* name */
ti_val_t * val__async_name;
ti_val_t * val__data_name;
ti_val_t * val__time_name;
ti_val_t * val__year_name;
Expand Down Expand Up @@ -739,6 +740,7 @@ int ti_val_init_common(void)
"-_");

/* names */
val__async_name = (ti_val_t *) ti_names_from_str("async");
val__data_name = (ti_val_t *) ti_names_from_str("data");
val__time_name = (ti_val_t *) ti_names_from_str("time");
val__year_name = (ti_val_t *) ti_names_from_str("year");
Expand Down Expand Up @@ -775,7 +777,7 @@ int ti_val_init_common(void)
!val__beautify_name || !val__parent_name || !val__parent_type_name ||
!val__key_name || !val__key_type_name || !val__flags_name ||
!val__data_name || !val__time_name || !val__re_email ||
!val__re_url || !val__re_tel)
!val__re_url || !val__re_tel || !val__async_name)
{
return -1;
}
Expand Down

0 comments on commit 26e61b0

Please sign in to comment.