Skip to content

Commit 3c8ae7c

Browse files
committed
lAcpiEvaluateObject: Change error handling
1 parent 843f714 commit 3c8ae7c

File tree

2 files changed

+36
-9
lines changed

2 files changed

+36
-9
lines changed

stand/liblua/acpi/lacpi_object.c

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,20 +73,41 @@ lAcpiEvaluateObject(lua_State *L)
7373
return luaL_error(L, "Incorrect arguments");
7474
}
7575

76+
/*
77+
* 4 is expected to be a table of ACPI_OBJECTs.
78+
* These are passed when the method you are evaluating needs them.
79+
* Each element of this table is converted into an ACPI_OBJECT.
80+
*
81+
* Each element of this table must be a table with:
82+
* 1: obj_type -- UINT32 specifying the current element's
83+
* ACPI_OBJECT_TYPE
84+
* 2..n: fields -- used to build the corresponding
85+
* ACPI_OBJECT, where n depends on obj_type. (see actypes.h)
86+
*
87+
*/
7688
if (lua_istable(L, 4)) {
7789
obj_count = lua_rawlen(L, 4);
7890
objs = malloc(sizeof(ACPI_OBJECT) * obj_count);
7991
if (objs == NULL) {
80-
return luaL_error(L, "Failed to malloc objs.");
92+
lua_pushnil(L);
93+
lua_pushstring(L, "Failed to malloc objs.");
94+
return 2;
8195
}
8296

8397
for (int i = 0; i < obj_count; ++i) {
8498
lua_rawgeti(L, 4, i + 1);
85-
8699
lua_getfield(L, -1, "obj_type");
87-
obj_type = lua_int_to_uint32(L, -1,
88-
"Invalid ACPI Object type");
100+
101+
if ((status = lua_int_to_uint32(L, -1, &obj_type))
102+
!= AE_OK) {
103+
lua_pushnil(L);
104+
lua_pushstring(L, "ACPI_OBJECT_TYPE must be"
105+
" UINT32");
106+
free(objs);
107+
return 2;
108+
}
89109
lua_pop(L, 1);
110+
90111
build_acpi_obj(L, &objs[i], obj_type);
91112
lua_pop(L, 1);
92113
}
@@ -106,8 +127,12 @@ lAcpiEvaluateObject(lua_State *L)
106127

107128
free_acpi_objs(objs, obj_count);
108129

109-
return luaL_error(L,
130+
char errbuf[64];
131+
snprintf(errbuf, sizeof(errbuf),
110132
"AcpiEvaluateObject failed with status 0x%x", status);
133+
lua_pushnil(L);
134+
lua_pushstring(L, errbuf);
135+
return 2;
111136
}
112137

113138
if (return_buffer.Pointer != NULL) {

stand/liblua/acpi/lacpi_utils.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,17 @@ lacpi_create_mt_gc(lua_State *L, const char *mt, lua_CFunction gc_func)
3434
return 1;
3535
}
3636

37-
UINT32
38-
lua_int_to_uint32(lua_State *L, int index, const char *errmsg)
37+
int
38+
lua_int_to_uint32(lua_State *L, int index, UINT32 *out)
3939
{
4040
lua_Integer temp = luaL_checkinteger(L, index);
41+
4142
if (temp < 0 || temp > UINT32_MAX) {
42-
luaL_error(L, "%s", errmsg);
43+
return AE_NUMERIC_OVERFLOW;
4344
}
4445

45-
return (UINT32)temp;
46+
*out = (UINT32)temp;
47+
return AE_OK;
4648
}
4749

4850
/***** FACTORY *****/

0 commit comments

Comments
 (0)