A
lgorithmique
N
umérique
D
istribuée
Public GIT Repository
projects
/
simgrid.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Uncomment constant definition, even though currently unused.
[simgrid.git]
/
src
/
bindings
/
lua
/
lua_debug.cpp
diff --git
a/src/bindings/lua/lua_debug.cpp
b/src/bindings/lua/lua_debug.cpp
index
d0c0db6
..
1d7ed69
100644
(file)
--- a/
src/bindings/lua/lua_debug.cpp
+++ b/
src/bindings/lua/lua_debug.cpp
@@
-1,21
+1,18
@@
-/* Copyright (c) 2010-201
6
. The SimGrid Team.
- * All rights reserved.
+/* Copyright (c) 2010-201
9
. The SimGrid Team.
+ * All rights reserved.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the license (GNU LGPL) which comes with this package. */
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the license (GNU LGPL) which comes with this package. */
-
/*
* This file contains functions that aid users to debug their lua scripts; for instance,
* tables can be easily output and values are represented in a human-readable way. (For instance,
/*
* This file contains functions that aid users to debug their lua scripts; for instance,
* tables can be easily output and values are represented in a human-readable way. (For instance,
- * a
NULL
value becomes the string "nil").
+ * a
nullptr
value becomes the string "nil").
*
*/
/* SimGrid Lua debug functions */
*
*/
/* SimGrid Lua debug functions */
-extern "C" {
#include <lauxlib.h>
#include <lauxlib.h>
-}
-#include "lua_utils.h"
+#include "lua_utils.hpp"
#include "xbt.h"
XBT_LOG_NEW_DEFAULT_CATEGORY(lua_debug, "Lua bindings (helper functions)");
#include "xbt.h"
XBT_LOG_NEW_DEFAULT_CATEGORY(lua_debug, "Lua bindings (helper functions)");
@@
-37,15
+34,15
@@
const char* sglua_tostring(lua_State* L, int index) {
switch (lua_type(L, index)) {
case LUA_TNIL:
switch (lua_type(L, index)) {
case LUA_TNIL:
- s
printf(buff
, "nil");
+ s
nprintf(buff, 4
, "nil");
break;
break;
- case LUA_TNUMBER:
- s
printf(buff
, "%.3f", lua_tonumber(L, index));
+ case LUA_TNUMBER:
+ s
nprintf(buff, 64
, "%.3f", lua_tonumber(L, index));
break;
case LUA_TBOOLEAN:
break;
case LUA_TBOOLEAN:
- s
printf(buff
, "%s", lua_toboolean(L, index) ? "true" : "false");
+ s
nprintf(buff, 64
, "%s", lua_toboolean(L, index) ? "true" : "false");
break;
case LUA_TSTRING:
break;
case LUA_TSTRING:
@@
-54,24
+51,28
@@
const char* sglua_tostring(lua_State* L, int index) {
case LUA_TFUNCTION:
if (lua_iscfunction(L, index)) {
case LUA_TFUNCTION:
if (lua_iscfunction(L, index)) {
- s
printf(buff
, "C-function");
+ s
nprintf(buff, 11
, "C-function");
}
else {
}
else {
- s
printf(buff
, "function");
+ s
nprintf(buff, 9
, "function");
}
break;
case LUA_TTABLE:
}
break;
case LUA_TTABLE:
- s
printf(buff
, "table(%p)", lua_topointer(L, index));
+ s
nprintf(buff, 64
, "table(%p)", lua_topointer(L, index));
break;
case LUA_TLIGHTUSERDATA:
case LUA_TUSERDATA:
break;
case LUA_TLIGHTUSERDATA:
case LUA_TUSERDATA:
- s
printf(buff
, "userdata(%p)", lua_touserdata(L, index));
+ s
nprintf(buff, 64
, "userdata(%p)", lua_touserdata(L, index));
break;
case LUA_TTHREAD:
break;
case LUA_TTHREAD:
- sprintf(buff, "thread");
+ snprintf(buff, 7, "thread");
+ break;
+
+ default:
+ snprintf(buff, 64, "unknown(%d)", lua_type(L, index));
break;
}
return buff;
break;
}
return buff;
@@
-84,7
+85,7
@@
static int sglua_dump_table(lua_State* L) {
if (lua_istable(L, i)) {
lua_pushnil(L); /* table nil */
if (lua_istable(L, i)) {
lua_pushnil(L); /* table nil */
- //lua_next pops the topmost element from the stack and
+ //lua_next pops the topmost element from the stack and
//gets the next pair from the table
while (lua_next(L, -1)) { /* table key val */
// we need to copy here, as a cast from "Number" to "String"
//gets the next pair from the table
while (lua_next(L, -1)) { /* table key val */
// we need to copy here, as a cast from "Number" to "String"
@@
-164,7
+165,7
@@
void sglua_stack_dump(lua_State* L, const char* msg)
p[0] = '\0';
for (int i = 1; i <= top; i++) { /* repeat for each level */
p[0] = '\0';
for (int i = 1; i <= top; i++) { /* repeat for each level */
- p += s
printf(p
, "%s ", sglua_tostring(L, i));
+ p += s
nprintf(p, 2048-(p-buff)
, "%s ", sglua_tostring(L, i));
}
XBT_DEBUG("%s%s", msg, buff);
}
XBT_DEBUG("%s%s", msg, buff);
@@
-172,13
+173,13
@@
void sglua_stack_dump(lua_State* L, const char* msg)
}
/**
}
/**
- *
\
brief Like luaL_checkudata, with additional debug logs.
+ *
@
brief Like luaL_checkudata, with additional debug logs.
*
* This function is for debugging purposes only.
*
*
* This function is for debugging purposes only.
*
- *
\
param L a lua state
- *
\
param ud index of the userdata to check in the stack
- *
\
param tname key of the metatable of this userdata in the registry
+ *
@
param L a lua state
+ *
@
param ud index of the userdata to check in the stack
+ *
@
param tname key of the metatable of this userdata in the registry
*/
void* sglua_checkudata_debug(lua_State* L, int ud, const char* tname)
{
*/
void* sglua_checkudata_debug(lua_State* L, int ud, const char* tname)
{
@@
-190,7
+191,7
@@
void* sglua_checkudata_debug(lua_State* L, int ud, const char* tname)
int has_mt = lua_getmetatable(L, ud);
XBT_DEBUG("Checking the userdata: has metatable ? %d", has_mt);
int has_mt = lua_getmetatable(L, ud);
XBT_DEBUG("Checking the userdata: has metatable ? %d", has_mt);
- const void* actual_mt =
NULL
;
+ const void* actual_mt =
nullptr
;
if (has_mt) {
actual_mt = lua_topointer(L, -1);
lua_pop(L, 1);
if (has_mt) {
actual_mt = lua_topointer(L, -1);
lua_pop(L, 1);
@@
-198,8
+199,8
@@
void* sglua_checkudata_debug(lua_State* L, int ud, const char* tname)
XBT_DEBUG("Checking the task's metatable: expected %p, found %p", correct_mt, actual_mt);
sglua_stack_dump(L, "my_checkudata: ");
XBT_DEBUG("Checking the task's metatable: expected %p, found %p", correct_mt, actual_mt);
sglua_stack_dump(L, "my_checkudata: ");
- if (p ==
NULL || !lua_getmetatable(L, ud) || !
lua_rawequal(L, -1, -2))
- XBT_ERROR("Error: Userdata is
NULL
, couldn't find metatable or top of stack does not equal element below it.");
+ if (p ==
nullptr || not lua_getmetatable(L, ud) || not
lua_rawequal(L, -1, -2))
+ XBT_ERROR("Error: Userdata is
nullptr
, couldn't find metatable or top of stack does not equal element below it.");
lua_pop(L, 2);
return p;
}
lua_pop(L, 2);
return p;
}
@@
-210,18
+211,17
@@
void* sglua_checkudata_debug(lua_State* L, int ud, const char* tname)
* This function is a valid lua_Writer that writes into a memory buffer passed
* as userdata.
*
* This function is a valid lua_Writer that writes into a memory buffer passed
* as userdata.
*
- * @param L a lua state
- * @param source some data
- * @param s
z
number of bytes of data
- * @param user
_
data the memory buffer to write
+ * @param L
a lua state
+ * @param source
some data
+ * @param s
ize
number of bytes of data
+ * @param userdata the memory buffer to write
*/
*/
-int sglua_memory_writer(lua_State* L, const void* source, size_t size,
- void* userdata) {
-
- sglua_buffer_t buffer = (sglua_buffer_t) userdata;
+int sglua_memory_writer(lua_State* /*L*/, const void* source, size_t size, void* userdata)
+{
+ sglua_buffer_t buffer = static_cast<sglua_buffer_t>(userdata);
while (buffer->capacity < buffer->size + size) {
buffer->capacity *= 2;
while (buffer->capacity < buffer->size + size) {
buffer->capacity *= 2;
- buffer->data =
(char*)xbt_realloc(buffer->data, buffer->capacity
);
+ buffer->data =
static_cast<char*>(xbt_realloc(buffer->data, buffer->capacity)
);
}
memcpy(buffer->data + buffer->size, source, size);
buffer->size += size;
}
memcpy(buffer->data + buffer->size, source, size);
buffer->size += size;