Sat May 20 09:46:17 2017 UTC ()
always put the module on the stack


(mbalmer)
diff -r1.22 -r1.23 src/sys/modules/lua/lua.c

cvs diff -r1.22 -r1.23 src/sys/modules/lua/lua.c (expand / switch to unified diff)

--- src/sys/modules/lua/lua.c 2017/05/20 08:31:13 1.22
+++ src/sys/modules/lua/lua.c 2017/05/20 09:46:17 1.23
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: lua.c,v 1.22 2017/05/20 08:31:13 mbalmer Exp $ */ 1/* $NetBSD: lua.c,v 1.23 2017/05/20 09:46:17 mbalmer Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 2011 - 2017 by Marc Balmer <mbalmer@NetBSD.org>. 4 * Copyright (c) 2011 - 2017 by Marc Balmer <mbalmer@NetBSD.org>.
5 * Copyright (c) 2014 by Lourival Vieira Neto <lneto@NetBSD.org>. 5 * Copyright (c) 2014 by Lourival Vieira Neto <lneto@NetBSD.org>.
6 * All rights reserved. 6 * All rights reserved.
7 * 7 *
8 * Redistribution and use in source and binary forms, with or without 8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions 9 * modification, are permitted provided that the following conditions
10 * are met: 10 * are met:
11 * 1. Redistributions of source code must retain the above copyright 11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer. 12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright 13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the 14 * notice, this list of conditions and the following disclaimer in the
@@ -504,36 +504,36 @@ lua_require(lua_State *L) @@ -504,36 +504,36 @@ lua_require(lua_State *L)
504 if (lua_verbose) 504 if (lua_verbose)
505 device_printf(sc_self, "autoload %s\n", name); 505 device_printf(sc_self, "autoload %s\n", name);
506 module_autoload(name, MODULE_CLASS_MISC); 506 module_autoload(name, MODULE_CLASS_MISC);
507 LIST_FOREACH(m, &lua_modules, mod_next) 507 LIST_FOREACH(m, &lua_modules, mod_next)
508 if (!strcmp(m->mod_name, module)) { 508 if (!strcmp(m->mod_name, module)) {
509 md = m; 509 md = m;
510 break; 510 break;
511 } 511 }
512 } 512 }
513 513
514 if (md != NULL) 514 if (md != NULL)
515 LIST_FOREACH(s, &lua_states, lua_next) 515 LIST_FOREACH(s, &lua_states, lua_next)
516 if (s->K->L == L) { 516 if (s->K->L == L) {
517 LIST_FOREACH(m, &s->lua_modules, mod_next) 
518 if (m == md) 
519 return 1; 
520 
521 if (lua_verbose) 517 if (lua_verbose)
522 device_printf(sc_self, 518 device_printf(sc_self,
523 "require module %s\n", 519 "require module %s\n",
524 md->mod_name); 520 md->mod_name);
525 luaL_requiref(L, md->mod_name, md->open, 0); 521 luaL_requiref(L, md->mod_name, md->open, 0);
526 522
 523 LIST_FOREACH(m, &s->lua_modules, mod_next)
 524 if (m == md)
 525 return 1;
 526
527 md->refcount++; 527 md->refcount++;
528 LIST_INSERT_HEAD(&s->lua_modules, md, mod_next); 528 LIST_INSERT_HEAD(&s->lua_modules, md, mod_next);
529 return 1; 529 return 1;
530 } 530 }
531 531
532 lua_pushstring(L, "module not found"); 532 lua_pushstring(L, "module not found");
533 return lua_error(L); 533 return lua_error(L);
534} 534}
535 535
536typedef struct { 536typedef struct {
537 size_t size; 537 size_t size;
538} __packed alloc_header_t; 538} __packed alloc_header_t;
539 539