Splint fiddles.
CVS patchset: 7242 CVS date: 2004/04/19 12:12:12
This commit is contained in:
parent
b687c65d77
commit
f748bc43d9
|
@ -315,24 +315,24 @@ rdcl(/*@returned@*/ char * buf, size_t size, FD_t fd)
|
|||
switch (*p) {
|
||||
case '\\':
|
||||
switch (*(p+1)) {
|
||||
case '\0': break;
|
||||
default: p++; break;
|
||||
case '\0': /*@switchbreak@*/ break;
|
||||
default: p++; /*@switchbreak@*/ break;
|
||||
}
|
||||
break;
|
||||
/*@switchbreak@*/ break;
|
||||
case '%':
|
||||
switch (*(p+1)) {
|
||||
case '{': p++, bc++; break;
|
||||
case '(': p++, pc++; break;
|
||||
case '%': p++; break;
|
||||
case '{': p++, bc++; /*@switchbreak@*/ break;
|
||||
case '(': p++, pc++; /*@switchbreak@*/ break;
|
||||
case '%': p++; /*@switchbreak@*/ break;
|
||||
}
|
||||
break;
|
||||
case '{': if (bc > 0) bc++; break;
|
||||
case '}': if (bc > 0) bc--; break;
|
||||
case '(': if (pc > 0) pc++; break;
|
||||
case ')': if (pc > 0) pc--; break;
|
||||
/*@switchbreak@*/ break;
|
||||
case '{': if (bc > 0) bc++; /*@switchbreak@*/ break;
|
||||
case '}': if (bc > 0) bc--; /*@switchbreak@*/ break;
|
||||
case '(': if (pc > 0) pc++; /*@switchbreak@*/ break;
|
||||
case ')': if (pc > 0) pc--; /*@switchbreak@*/ break;
|
||||
}
|
||||
}
|
||||
if (nb <= 0 || (*q != '\\' && !bc && !pc) || *(q+1) == '\0') {
|
||||
if (nb == 0 || (*q != '\\' && !bc && !pc) || *(q+1) == '\0') {
|
||||
*(++q) = '\0'; /* trim trailing \r, \n */
|
||||
break;
|
||||
}
|
||||
|
@ -678,21 +678,21 @@ doDefine(MacroBuf mb, /*@returned@*/ const char * se, int level, int expandbody)
|
|||
switch (*s) {
|
||||
case '\\':
|
||||
switch (*(s+1)) {
|
||||
case '\0': break;
|
||||
default: s++; break;
|
||||
case '\0': /*@switchbreak@*/ break;
|
||||
default: s++; /*@switchbreak@*/ break;
|
||||
}
|
||||
break;
|
||||
/*@switchbreak@*/ break;
|
||||
case '%':
|
||||
switch (*(s+1)) {
|
||||
case '{': *be++ = *s++; bc++; break;
|
||||
case '(': *be++ = *s++; pc++; break;
|
||||
case '%': *be++ = *s++; break;
|
||||
case '{': *be++ = *s++; bc++; /*@switchbreak@*/ break;
|
||||
case '(': *be++ = *s++; pc++; /*@switchbreak@*/ break;
|
||||
case '%': *be++ = *s++; /*@switchbreak@*/ break;
|
||||
}
|
||||
break;
|
||||
case '{': if (bc > 0) bc++; break;
|
||||
case '}': if (bc > 0) bc--; break;
|
||||
case '(': if (pc > 0) pc++; break;
|
||||
case ')': if (pc > 0) pc--; break;
|
||||
/*@switchbreak@*/ break;
|
||||
case '{': if (bc > 0) bc++; /*@switchbreak@*/ break;
|
||||
case '}': if (bc > 0) bc--; /*@switchbreak@*/ break;
|
||||
case '(': if (pc > 0) pc++; /*@switchbreak@*/ break;
|
||||
case ')': if (pc > 0) pc--; /*@switchbreak@*/ break;
|
||||
}
|
||||
*be++ = *s++;
|
||||
}
|
||||
|
|
223
rpmio/rpmhook.c
223
rpmio/rpmhook.c
|
@ -1,3 +1,4 @@
|
|||
/*@-bounds@*/
|
||||
#include "system.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
|
@ -18,6 +19,7 @@ typedef struct rpmhookItem_s {
|
|||
|
||||
typedef struct rpmhookBucket_s {
|
||||
unsigned long hash;
|
||||
/*@relnull@*/
|
||||
char *name;
|
||||
rpmhookItem item;
|
||||
} * rpmhookBucket;
|
||||
|
@ -31,8 +33,8 @@ typedef struct rpmhookTable_s {
|
|||
|
||||
rpmhookArgs rpmhookArgsNew(int argc)
|
||||
{
|
||||
rpmhookArgs args = (rpmhookArgs)xcalloc(1, sizeof(struct rpmhookArgs_s)+
|
||||
(argc-1)*sizeof(rpmhookArgv));
|
||||
rpmhookArgs args = (rpmhookArgs) xcalloc(1,
|
||||
sizeof(*args) + sizeof(args->argv) * (argc-1));
|
||||
args->argc = argc;
|
||||
return args;
|
||||
}
|
||||
|
@ -43,39 +45,43 @@ rpmhookArgs rpmhookArgsFree(rpmhookArgs args)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
/*@only@*/
|
||||
static rpmhookTable rpmhookTableNew(int size)
|
||||
/*@*/
|
||||
{
|
||||
rpmhookTable table =
|
||||
(rpmhookTable)xcalloc(1, sizeof(struct rpmhookTable_s)+
|
||||
sizeof(struct rpmhookBucket_s)*(size-1));
|
||||
rpmhookTable table = (rpmhookTable) xcalloc(1,
|
||||
sizeof(*table) + sizeof(table->bucket) * (size-1));
|
||||
table->size = size;
|
||||
return table;
|
||||
}
|
||||
|
||||
#if 0
|
||||
static rpmhookTable rpmhookTableFree(rpmhookTable table)
|
||||
/*@*/
|
||||
{
|
||||
rpmhookItem item, nextItem;
|
||||
int i;
|
||||
for (i = 0; i != table->size; i++) {
|
||||
if (table->bucket[i].name) {
|
||||
free(table->bucket[i].name);
|
||||
item = table->bucket[i].item;
|
||||
while (item) {
|
||||
nextItem = item->next;
|
||||
free(item);
|
||||
item = nextItem;
|
||||
}
|
||||
}
|
||||
if (table->bucket[i].name == NULL)
|
||||
continue;
|
||||
free(table->bucket[i].name);
|
||||
item = table->bucket[i].item;
|
||||
while (item) {
|
||||
nextItem = item->next;
|
||||
free(item);
|
||||
item = nextItem;
|
||||
}
|
||||
}
|
||||
free(table);
|
||||
return NULL;
|
||||
}
|
||||
#endif
|
||||
|
||||
static void rpmhookTableRehash(rpmhookTable *table);
|
||||
static void rpmhookTableRehash(rpmhookTable *table)
|
||||
/*@modifies *table @*/;
|
||||
|
||||
static int rpmhookTableFindBucket(rpmhookTable *table, const char *name)
|
||||
/*@modifies *table @*/
|
||||
{
|
||||
/* Hash based on http://www.isthe.com/chongo/tech/comp/fnv/ */
|
||||
unsigned long perturb;
|
||||
|
@ -83,63 +89,76 @@ static int rpmhookTableFindBucket(rpmhookTable *table, const char *name)
|
|||
unsigned char *bp = (unsigned char *)name;
|
||||
unsigned char *be = bp + strlen(name);
|
||||
rpmhookBucket bucket;
|
||||
if (((*table)->used/2)*3 > (*table)->size)
|
||||
rpmhookTableRehash(table);
|
||||
int ret;
|
||||
|
||||
if (((*table)->used/2)*3 > (*table)->size)
|
||||
rpmhookTableRehash(table);
|
||||
while (bp < be) {
|
||||
hash ^= (unsigned long)*bp++;
|
||||
hash *= (unsigned long)0x01000193;
|
||||
hash ^= (unsigned long)*bp++;
|
||||
hash *= (unsigned long)0x01000193;
|
||||
}
|
||||
perturb = hash;
|
||||
ret = hash % (*table)->size;
|
||||
bucket = &(*table)->bucket[ret];
|
||||
while (bucket->name &&
|
||||
(bucket->hash != hash || strcmp(bucket->name, name) != 0)) {
|
||||
/* Collision resolution based on Python's perturb scheme. */
|
||||
ret = ((ret << 2) + ret + perturb + 1) % (*table)->size;
|
||||
perturb >>= 5;
|
||||
bucket = &(*table)->bucket[ret];
|
||||
(bucket->hash != hash || strcmp(bucket->name, name) != 0)) {
|
||||
/* Collision resolution based on Python's perturb scheme. */
|
||||
/*@-shiftimplementation@*/
|
||||
ret = ((ret << 2) + ret + perturb + 1) % (*table)->size;
|
||||
/*@=shiftimplementation@*/
|
||||
perturb >>= 5;
|
||||
bucket = &(*table)->bucket[ret];
|
||||
}
|
||||
if (!bucket->name)
|
||||
bucket->hash = hash;
|
||||
bucket->hash = hash;
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void rpmhookTableRehash(rpmhookTable *table)
|
||||
/*@modifies *table @*/
|
||||
{
|
||||
rpmhookTable newtable = rpmhookTableNew((*table)->size*2);
|
||||
int n, i = 0;
|
||||
|
||||
/*@-branchstate@*/
|
||||
for (; i != (*table)->size; i++) {
|
||||
if ((*table)->bucket[i].name) {
|
||||
n = rpmhookTableFindBucket(&newtable, (*table)->bucket[i].name);
|
||||
newtable->bucket[n].name = (*table)->bucket[i].name;
|
||||
newtable->bucket[n].item = (*table)->bucket[i].item;
|
||||
}
|
||||
if ((*table)->bucket[i].name == NULL)
|
||||
continue;
|
||||
n = rpmhookTableFindBucket(&newtable, (*table)->bucket[i].name);
|
||||
newtable->bucket[n].name = (*table)->bucket[i].name;
|
||||
newtable->bucket[n].item = (*table)->bucket[i].item;
|
||||
}
|
||||
/*@=branchstate@*/
|
||||
newtable->used = (*table)->used;
|
||||
/*@-unqualifiedtrans@*/
|
||||
free(*table);
|
||||
/*@=unqualifiedtrans@*/
|
||||
*table = newtable;
|
||||
}
|
||||
|
||||
static void rpmhookTableAddItem(rpmhookTable *table, const char *name,
|
||||
rpmhookFunc func, void *data)
|
||||
rpmhookFunc func, void *data)
|
||||
/*@modifies *table @*/
|
||||
{
|
||||
int n = rpmhookTableFindBucket(table, name);
|
||||
rpmhookBucket bucket = &(*table)->bucket[n];
|
||||
rpmhookItem *item = &bucket->item;
|
||||
if (!bucket->name) {
|
||||
bucket->name = strdup(name);
|
||||
(*table)->used++;
|
||||
bucket->name = strdup(name);
|
||||
(*table)->used++;
|
||||
}
|
||||
while (*item) item = &(*item)->next;
|
||||
*item = calloc(1, sizeof(struct rpmhookItem_s));
|
||||
*item = xcalloc(1, sizeof(**item));
|
||||
(*item)->func = func;
|
||||
/*@-temptrans@*/
|
||||
(*item)->data = data;
|
||||
/*@=temptrans@*/
|
||||
}
|
||||
|
||||
static void rpmhookTableDelItem(rpmhookTable *table, const char *name,
|
||||
rpmhookFunc func, void *data,
|
||||
int matchfunc, int matchdata)
|
||||
rpmhookFunc func, void *data,
|
||||
int matchfunc, int matchdata)
|
||||
/*@modifies *table @*/
|
||||
{
|
||||
int n = rpmhookTableFindBucket(table, name);
|
||||
rpmhookBucket bucket = &(*table)->bucket[n];
|
||||
|
@ -147,111 +166,127 @@ static void rpmhookTableDelItem(rpmhookTable *table, const char *name,
|
|||
rpmhookItem lastItem = NULL;
|
||||
rpmhookItem nextItem;
|
||||
while (item) {
|
||||
nextItem = item->next;
|
||||
if ((!matchfunc || item->func == func) &&
|
||||
(!matchdata || item->data == data)) {
|
||||
free(item);
|
||||
if (lastItem)
|
||||
lastItem->next = nextItem;
|
||||
else
|
||||
bucket->item = nextItem;
|
||||
} else {
|
||||
lastItem = item;
|
||||
}
|
||||
item = nextItem;
|
||||
nextItem = item->next;
|
||||
/*@-branchstate@*/
|
||||
if ((!matchfunc || item->func == func) &&
|
||||
(!matchdata || item->data == data)) {
|
||||
free(item);
|
||||
if (lastItem)
|
||||
lastItem->next = nextItem;
|
||||
else
|
||||
bucket->item = nextItem;
|
||||
} else {
|
||||
lastItem = item;
|
||||
}
|
||||
/*@=branchstate@*/
|
||||
/*@-usereleased@*/
|
||||
item = nextItem;
|
||||
}
|
||||
if (!bucket->item) {
|
||||
free(bucket->name);
|
||||
bucket->name = NULL;
|
||||
(*table)->used--;
|
||||
free(bucket->name);
|
||||
bucket->name = NULL;
|
||||
(*table)->used--;
|
||||
}
|
||||
/*@=usereleased@*/
|
||||
}
|
||||
|
||||
static rpmhookArgs rpmhookArgsParse(const char *argt, va_list ap)
|
||||
/*@*/
|
||||
{
|
||||
rpmhookArgs args = rpmhookArgsNew(strlen(argt));
|
||||
int i;
|
||||
|
||||
/*@-temptrans@*/
|
||||
args->argt = argt;
|
||||
/*@=temptrans@*/
|
||||
for (i = 0; i != args->argc; i++) {
|
||||
switch (argt[i]) {
|
||||
case 's':
|
||||
args->argv[i].s = va_arg(ap, char *);
|
||||
break;
|
||||
case 'i':
|
||||
args->argv[i].i = va_arg(ap, int);
|
||||
break;
|
||||
case 'f':
|
||||
args->argv[i].f = (float)va_arg(ap, double);
|
||||
break;
|
||||
case 'p':
|
||||
args->argv[i].p = va_arg(ap, void *);
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr, "error: unsupported type '%c' as "
|
||||
"a hook argument\n", argt[i]);
|
||||
break;
|
||||
}
|
||||
switch (argt[i]) {
|
||||
case 's':
|
||||
args->argv[i].s = va_arg(ap, char *);
|
||||
/*@switchbreak@*/ break;
|
||||
case 'i':
|
||||
args->argv[i].i = va_arg(ap, int);
|
||||
/*@switchbreak@*/ break;
|
||||
case 'f':
|
||||
args->argv[i].f = (float)va_arg(ap, double);
|
||||
/*@switchbreak@*/ break;
|
||||
case 'p':
|
||||
args->argv[i].p = va_arg(ap, void *);
|
||||
/*@switchbreak@*/ break;
|
||||
default:
|
||||
/*@-modfilesys @*/
|
||||
fprintf(stderr, "error: unsupported type '%c' as "
|
||||
"a hook argument\n", argt[i]);
|
||||
/*@=modfilesys @*/
|
||||
/*@switchbreak@*/ break;
|
||||
}
|
||||
}
|
||||
return args;
|
||||
}
|
||||
|
||||
static void rpmhookTableCallArgs(rpmhookTable *table, const char *name,
|
||||
rpmhookArgs args)
|
||||
rpmhookArgs args)
|
||||
/*@modifies *table @*/
|
||||
{
|
||||
int n = rpmhookTableFindBucket(table, name);
|
||||
rpmhookItem item = (*table)->bucket[n].item;
|
||||
while (item) {
|
||||
if (item->func(args, item->data) != 0)
|
||||
break;
|
||||
item = item->next;
|
||||
if (item->func(args, item->data) != 0)
|
||||
break;
|
||||
item = item->next;
|
||||
}
|
||||
}
|
||||
|
||||
/*@unchecked@*/ /*@only@*/ /*@null@*/
|
||||
static rpmhookTable globalTable = NULL;
|
||||
|
||||
void rpmhookRegister(const char *name, rpmhookFunc func, void *data)
|
||||
/*@globals globalTable @*/
|
||||
/*@modifies globalTable @*/
|
||||
{
|
||||
if (!globalTable)
|
||||
globalTable = rpmhookTableNew(RPMHOOK_TABLE_INITSIZE);
|
||||
if (globalTable == NULL)
|
||||
globalTable = rpmhookTableNew(RPMHOOK_TABLE_INITSIZE);
|
||||
rpmhookTableAddItem(&globalTable, name, func, data);
|
||||
}
|
||||
|
||||
void rpmhookUnregister(const char *name, rpmhookFunc func, void *data)
|
||||
{
|
||||
if (globalTable)
|
||||
rpmhookTableDelItem(&globalTable, name, func, data, 1, 1);
|
||||
if (globalTable != NULL)
|
||||
rpmhookTableDelItem(&globalTable, name, func, data, 1, 1);
|
||||
}
|
||||
|
||||
void rpmhookUnregisterAny(const char *name, rpmhookFunc func)
|
||||
{
|
||||
if (globalTable)
|
||||
rpmhookTableDelItem(&globalTable, name, func, NULL, 1, 0);
|
||||
if (globalTable != NULL)
|
||||
rpmhookTableDelItem(&globalTable, name, func, NULL, 1, 0);
|
||||
}
|
||||
|
||||
void rpmhookUnregisterAll(const char *name)
|
||||
{
|
||||
if (globalTable)
|
||||
rpmhookTableDelItem(&globalTable, name, NULL, NULL, 0, 0);
|
||||
if (globalTable != NULL)
|
||||
rpmhookTableDelItem(&globalTable, name, NULL, NULL, 0, 0);
|
||||
}
|
||||
|
||||
void rpmhookCall(const char *name, const char *argt, ...)
|
||||
{
|
||||
if (globalTable) {
|
||||
rpmhookArgs args;
|
||||
va_list ap;
|
||||
va_start(ap, argt);
|
||||
args = rpmhookArgsParse(argt, ap);
|
||||
rpmhookTableCallArgs(&globalTable, name, args);
|
||||
rpmhookArgsFree(args);
|
||||
va_end(ap);
|
||||
if (globalTable != NULL) {
|
||||
rpmhookArgs args;
|
||||
va_list ap;
|
||||
va_start(ap, argt);
|
||||
args = rpmhookArgsParse(argt, ap);
|
||||
/*@-noeffect@*/
|
||||
rpmhookTableCallArgs(&globalTable, name, args);
|
||||
/*@=noeffect@*/
|
||||
(void) rpmhookArgsFree(args);
|
||||
va_end(ap);
|
||||
}
|
||||
}
|
||||
|
||||
void rpmhookCallArgs(const char *name, rpmhookArgs args)
|
||||
{
|
||||
if (globalTable)
|
||||
rpmhookTableCallArgs(&globalTable, name, args);
|
||||
/*@-noeffect@*/
|
||||
if (globalTable != NULL)
|
||||
rpmhookTableCallArgs(&globalTable, name, args);
|
||||
/*@=noeffect@*/
|
||||
}
|
||||
|
||||
/* vim:ts=4:sw=4:et
|
||||
*/
|
||||
/*@=bounds@*/
|
||||
|
|
|
@ -2,31 +2,41 @@
|
|||
#define RPMHOOK_H
|
||||
|
||||
typedef union {
|
||||
const char *s;
|
||||
/*@observer@*/
|
||||
const char * s;
|
||||
int i;
|
||||
float f;
|
||||
void *p;
|
||||
/*@observer@*/
|
||||
void * p;
|
||||
} rpmhookArgv;
|
||||
|
||||
typedef struct rpmhookArgs_s {
|
||||
int argc;
|
||||
const char *argt;
|
||||
const char * argt;
|
||||
rpmhookArgv argv[1];
|
||||
} * rpmhookArgs;
|
||||
|
||||
typedef int (*rpmhookFunc)(rpmhookArgs args, void *data);
|
||||
typedef int (*rpmhookFunc) (rpmhookArgs args, void *data);
|
||||
|
||||
rpmhookArgs rpmhookArgsNew(int argc);
|
||||
rpmhookArgs rpmhookArgsFree(rpmhookArgs args);
|
||||
/*@only@*/
|
||||
rpmhookArgs rpmhookArgsNew(int argc)
|
||||
/*@*/;
|
||||
rpmhookArgs rpmhookArgsFree(/*@only@*/ rpmhookArgs args)
|
||||
/*@modifies args @*/;
|
||||
|
||||
void rpmhookRegister(const char *name, rpmhookFunc func, void *data);
|
||||
void rpmhookUnregister(const char *name, rpmhookFunc func, void *data);
|
||||
void rpmhookUnregisterAny(const char *name, rpmhookFunc func);
|
||||
void rpmhookUnregisterAll(const char *name);
|
||||
void rpmhookCall(const char *name, const char *argt, ...);
|
||||
void rpmhookCallArgs(const char *name, rpmhookArgs args);
|
||||
void rpmhookRegister(const char *name, rpmhookFunc func, void *data)
|
||||
/*@globals internalState @*/
|
||||
/*@modifies internalState @*/;
|
||||
void rpmhookUnregister(const char *name, rpmhookFunc func, void *data)
|
||||
/*@*/;
|
||||
void rpmhookUnregisterAny(const char *name, rpmhookFunc func)
|
||||
/*@*/;
|
||||
void rpmhookUnregisterAll(const char *name)
|
||||
/*@*/;
|
||||
void rpmhookCall(const char *name, const char *argt, ...)
|
||||
/*@*/;
|
||||
void rpmhookCallArgs(const char *name, rpmhookArgs args)
|
||||
/*@globals internalState @*/
|
||||
/*@modifies internalState @*/;
|
||||
|
||||
#endif
|
||||
|
||||
/* vim:ts=4:sw=4:et
|
||||
*/
|
||||
|
|
|
@ -623,12 +623,14 @@ static int rpm_interactive(lua_State *L)
|
|||
}
|
||||
|
||||
typedef struct rpmluaHookData_s {
|
||||
/*@shared@*/
|
||||
lua_State *L;
|
||||
int funcRef;
|
||||
int dataRef;
|
||||
} * rpmluaHookData;
|
||||
|
||||
static int rpmluaHookWrapper(rpmhookArgs args, void *data)
|
||||
/*@*/
|
||||
{
|
||||
rpmluaHookData hookdata = (rpmluaHookData)data;
|
||||
lua_State *L = hookdata->L;
|
||||
|
@ -641,23 +643,23 @@ static int rpmluaHookWrapper(rpmhookArgs args, void *data)
|
|||
case 's':
|
||||
lua_pushstring(L, args->argv[i].s);
|
||||
lua_rawseti(L, -2, i+1);
|
||||
break;
|
||||
/*@switchbreak@*/ break;
|
||||
case 'i':
|
||||
lua_pushnumber(L, args->argv[i].i);
|
||||
lua_pushnumber(L, (lua_Number)args->argv[i].i);
|
||||
lua_rawseti(L, -2, i+1);
|
||||
break;
|
||||
/*@switchbreak@*/ break;
|
||||
case 'f':
|
||||
lua_pushnumber(L, args->argv[i].f);
|
||||
lua_pushnumber(L, (lua_Number)args->argv[i].f);
|
||||
lua_rawseti(L, -2, i+1);
|
||||
break;
|
||||
/*@switchbreak@*/ break;
|
||||
case 'p':
|
||||
lua_pushlightuserdata(L, args->argv[i].p);
|
||||
lua_rawseti(L, -2, i+1);
|
||||
break;
|
||||
/*@switchbreak@*/ break;
|
||||
default:
|
||||
luaL_error(L, "unsupported type '%c' as "
|
||||
(void) luaL_error(L, "unsupported type '%c' as "
|
||||
"a hook argument\n", args->argt[i]);
|
||||
break;
|
||||
/*@switchbreak@*/ break;
|
||||
}
|
||||
}
|
||||
if (lua_pcall(L, 1, 1, 0) != 0) {
|
||||
|
@ -673,11 +675,13 @@ static int rpmluaHookWrapper(rpmhookArgs args, void *data)
|
|||
}
|
||||
|
||||
static int rpm_register(lua_State *L)
|
||||
/*@globals internalState @*/
|
||||
/*@modifies L, internalState @*/
|
||||
{
|
||||
if (!lua_isstring(L, 1)) {
|
||||
luaL_argerror(L, 1, "hook name expected");
|
||||
(void) luaL_argerror(L, 1, "hook name expected");
|
||||
} else if (!lua_isfunction(L, 2)) {
|
||||
luaL_argerror(L, 2, "function expected");
|
||||
(void) luaL_argerror(L, 2, "function expected");
|
||||
} else {
|
||||
rpmluaHookData hookdata =
|
||||
lua_newuserdata(L, sizeof(struct rpmluaHookData_s));
|
||||
|
@ -685,7 +689,9 @@ static int rpm_register(lua_State *L)
|
|||
hookdata->dataRef = luaL_ref(L, LUA_REGISTRYINDEX);
|
||||
lua_pushvalue(L, 2);
|
||||
hookdata->funcRef = luaL_ref(L, LUA_REGISTRYINDEX);
|
||||
/*@-temptrans@*/
|
||||
hookdata->L = L;
|
||||
/*@=temptrans@*/
|
||||
rpmhookRegister(lua_tostring(L, 1), rpmluaHookWrapper, hookdata);
|
||||
return 1;
|
||||
}
|
||||
|
@ -693,11 +699,12 @@ static int rpm_register(lua_State *L)
|
|||
}
|
||||
|
||||
static int rpm_unregister(lua_State *L)
|
||||
/*@modifies L @*/
|
||||
{
|
||||
if (!lua_isstring(L, 1)) {
|
||||
luaL_argerror(L, 1, "hook name expected");
|
||||
(void) luaL_argerror(L, 1, "hook name expected");
|
||||
} else if (!lua_islightuserdata(L, 2)) {
|
||||
luaL_argerror(L, 2, "hook information expected");
|
||||
(void) luaL_argerror(L, 2, "hook information expected");
|
||||
} else {
|
||||
rpmluaHookData hookdata = (rpmluaHookData)lua_touserdata(L, 2);
|
||||
luaL_unref(L, LUA_REGISTRYINDEX, hookdata->funcRef);
|
||||
|
@ -708,9 +715,11 @@ static int rpm_unregister(lua_State *L)
|
|||
}
|
||||
|
||||
static int rpm_call(lua_State *L)
|
||||
/*@globals internalState @*/
|
||||
/*@modifies L, internalState @*/
|
||||
{
|
||||
if (!lua_isstring(L, 1)) {
|
||||
luaL_argerror(L, 1, "hook name expected");
|
||||
(void) luaL_argerror(L, 1, "hook name expected");
|
||||
} else {
|
||||
rpmhookArgs args = rpmhookArgsNew(lua_gettop(L)-1);
|
||||
const char *name = lua_tostring(L, 1);
|
||||
|
@ -721,9 +730,10 @@ static int rpm_call(lua_State *L)
|
|||
case LUA_TNIL:
|
||||
argt[i] = 'p';
|
||||
args->argv[i].p = NULL;
|
||||
break;
|
||||
/*@switchbreak@*/ break;
|
||||
case LUA_TNUMBER: {
|
||||
float f = (float)lua_tonumber(L, i+1);
|
||||
/*@+relaxtypes@*/
|
||||
if (f == (int)f) {
|
||||
argt[i] = 'i';
|
||||
args->argv[i].i = (int)f;
|
||||
|
@ -731,28 +741,30 @@ static int rpm_call(lua_State *L)
|
|||
argt[i] = 'f';
|
||||
args->argv[i].f = f;
|
||||
}
|
||||
break;
|
||||
}
|
||||
/*@=relaxtypes@*/
|
||||
} /*@switchbreak@*/ break;
|
||||
case LUA_TSTRING:
|
||||
argt[i] = 's';
|
||||
args->argv[i].s = lua_tostring(L, i+1);
|
||||
break;
|
||||
/*@switchbreak@*/ break;
|
||||
case LUA_TUSERDATA:
|
||||
case LUA_TLIGHTUSERDATA:
|
||||
argt[i] = 'p';
|
||||
args->argv[i].p = lua_touserdata(L, i+1);
|
||||
break;
|
||||
/*@switchbreak@*/ break;
|
||||
default:
|
||||
luaL_error(L, "unsupported Lua type passed to hook");
|
||||
(void) luaL_error(L, "unsupported Lua type passed to hook");
|
||||
argt[i] = 'p';
|
||||
args->argv[i].p = NULL;
|
||||
break;
|
||||
/*@switchbreak@*/ break;
|
||||
}
|
||||
}
|
||||
/*@-compdef -kepttrans -usereleased @*/
|
||||
args->argt = argt;
|
||||
rpmhookCallArgs(name, args);
|
||||
free(argt);
|
||||
rpmhookArgsFree(args);
|
||||
(void) rpmhookArgsFree(args);
|
||||
/*@=compdef =kepttrans =usereleased @*/
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -828,6 +840,3 @@ static int luaopen_rpm(lua_State *L)
|
|||
}
|
||||
|
||||
/*@=bounds =realcompare =sizeoftype =protoparammatch @*/
|
||||
|
||||
/* vim:sts=4:sw=4
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue