Skip to content

Commit 073acc0

Browse files
committed
The rest of tweaks for amx module
1 parent d459d4c commit 073acc0

5 files changed

Lines changed: 120 additions & 106 deletions

File tree

amx-deps/src/amx/amx.c

Lines changed: 23 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -295,17 +295,6 @@ typedef enum {
295295
OP_NUM_OPCODES
296296
} OPCODE;
297297

298-
#define USENAMETABLE(hdr) \
299-
((hdr)->defsize==sizeof(AMX_FUNCSTUBNT))
300-
#define NUMENTRIES(hdr,field,nextfield) \
301-
(unsigned)(((hdr)->nextfield - (hdr)->field) / (hdr)->defsize)
302-
#define GETENTRY(hdr,table,index) \
303-
(AMX_FUNCSTUB *)((unsigned char*)(hdr) + (unsigned)(hdr)->table + (unsigned)index*(hdr)->defsize)
304-
#define GETENTRYNAME(hdr,entry) \
305-
( USENAMETABLE(hdr) \
306-
? (char *)((unsigned char*)(hdr) + (unsigned)((AMX_FUNCSTUBNT*)(entry))->nameofs) \
307-
: ((AMX_FUNCSTUB*)(entry))->name )
308-
309298
#if !defined NDEBUG
310299
static int check_endian(void)
311300
{
@@ -940,7 +929,7 @@ int AMXAPI amx_Init(AMX *amx,void *program)
940929
#endif
941930
#endif
942931
int numlibraries,i;
943-
AMX_FUNCSTUB *lib;
932+
AMX_FUNCSTUB* lib;
944933
AMX_ENTRY libinit;
945934
#endif
946935

@@ -1256,13 +1245,13 @@ int AMXAPI amx_Cleanup(AMX *amx)
12561245
#endif
12571246
AMX_HEADER *hdr;
12581247
int numlibraries,i;
1259-
AMX_FUNCSTUB *lib;
1248+
AMX_FUNCSTUB* lib;
12601249
AMX_ENTRY libcleanup;
12611250
#endif
12621251

12631252
/* unload all extension modules */
12641253
#if (defined _Windows || defined LINUX || defined __FreeBSD__ || defined __OpenBSD__) && !defined AMX_NODYNALOAD
1265-
hdr=(AMX_HEADER *)amx->base;
1254+
hdr=(AMX_HEADER*)amx->base;
12661255
assert(hdr->magic==AMX_MAGIC);
12671256
numlibraries=NUMENTRIES(hdr,libraries,pubvars);
12681257
for (i=0; i<numlibraries; i++) {
@@ -1407,7 +1396,7 @@ int AMXAPI amx_GetNative(AMX *amx, int index, char *funcname)
14071396
return AMX_ERR_NONE;
14081397
}
14091398

1410-
int AMXAPI amx_FindNative(AMX *amx, const char *name, int *index)
1399+
int AMXAPI amx_FindNative(AMX* amx, const char* name, int* index)
14111400
{
14121401
int first,last,mid,result;
14131402
char pname[sNAMEMAX+1];
@@ -1524,7 +1513,7 @@ int AMXAPI amx_FindPubVar(AMX *amx, const char *varname, cell *amx_addr)
15241513
{
15251514
int first,last,mid,result;
15261515
char pname[sNAMEMAX+1];
1527-
cell paddr;
1516+
cell paddr=0;
15281517

15291518
amx_NumPubVars(amx, &last);
15301519
last--; /* last valid index is 1 less than the number of functions */
@@ -1603,7 +1592,7 @@ int AMXAPI amx_GetTag(AMX *amx, int index, char *tagname, cell *tag_id)
16031592
int AMXAPI amx_FindTagId(AMX *amx, cell tag_id, char *tagname)
16041593
{
16051594
int first,last,mid;
1606-
cell mid_id;
1595+
cell mid_id=tag_id;
16071596

16081597
#if !defined NDEBUG
16091598
/* verify that the tagname table is sorted on the tag_id */
@@ -1683,7 +1672,7 @@ static AMX_NATIVE findfunction(const char *name, const AMX_NATIVE_INFO *list, in
16831672
int i;
16841673

16851674
assert(list!=NULL);
1686-
for (i=0; list[i].name!=NULL && (i<number || number==-1); i++)
1675+
for (i=0; (i<number || number==-1) && list[i].name!=NULL; i++)
16871676
if (strcmp(name,list[i].name)==0)
16881677
return list[i].func;
16891678
return NULL;
@@ -1731,9 +1720,6 @@ AMX_NATIVE_INFO * AMXAPI amx_NativeInfo(const char *name, AMX_NATIVE func)
17311720
}
17321721
#endif /* AMX_NATIVEINFO */
17331722

1734-
1735-
#define STKMARGIN ((cell)(16*sizeof(cell)))
1736-
17371723
#if defined AMX_PUSHXXX
17381724

17391725
int AMXAPI amx_Push(AMX *amx, cell value)
@@ -3245,14 +3231,14 @@ int AMXAPI amx_Exec(AMX *amx, cell *retval, int index)
32453231
break;
32463232
case OP_LOAD_I:
32473233
/* verify address */
3248-
if (pri>=hea && pri<stk || (ucell)pri>=(ucell)amx->stp)
3234+
if ((pri>=hea && pri<stk) || (ucell)pri>=(ucell)amx->stp)
32493235
ABORT(amx,AMX_ERR_MEMACCESS);
32503236
pri=_R(data,pri);
32513237
break;
32523238
case OP_LODB_I:
32533239
GETPARAM(offs);
32543240
/* verify address */
3255-
if (pri>=hea && pri<stk || (ucell)pri>=(ucell)amx->stp)
3241+
if ((pri>=hea && pri<stk) || (ucell)pri>=(ucell)amx->stp)
32563242
ABORT(amx,AMX_ERR_MEMACCESS);
32573243
switch ((int)offs) {
32583244
case 1:
@@ -3318,14 +3304,14 @@ int AMXAPI amx_Exec(AMX *amx, cell *retval, int index)
33183304
break;
33193305
case OP_STOR_I:
33203306
/* verify address */
3321-
if (alt>=hea && alt<stk || (ucell)alt>=(ucell)amx->stp)
3307+
if ((alt>=hea && alt<stk) || (ucell)alt>=(ucell)amx->stp)
33223308
ABORT(amx,AMX_ERR_MEMACCESS);
33233309
_W(data,alt,pri);
33243310
break;
33253311
case OP_STRB_I:
33263312
GETPARAM(offs);
33273313
/* verify address */
3328-
if (alt>=hea && alt<stk || (ucell)alt>=(ucell)amx->stp)
3314+
if ((alt>=hea && alt<stk) || (ucell)alt>=(ucell)amx->stp)
33293315
ABORT(amx,AMX_ERR_MEMACCESS);
33303316
switch ((int)offs) {
33313317
case 1:
@@ -3342,15 +3328,15 @@ int AMXAPI amx_Exec(AMX *amx, cell *retval, int index)
33423328
case OP_LIDX:
33433329
offs=pri*sizeof(cell)+alt;
33443330
/* verify address */
3345-
if (offs>=hea && offs<stk || (ucell)offs>=(ucell)amx->stp)
3331+
if ((offs>=hea && offs<stk) || (ucell)offs>=(ucell)amx->stp)
33463332
ABORT(amx,AMX_ERR_MEMACCESS);
33473333
pri=_R(data,offs);
33483334
break;
33493335
case OP_LIDX_B:
33503336
GETPARAM(offs);
33513337
offs=(pri << (int)offs)+alt;
33523338
/* verify address */
3353-
if (offs>=hea && offs<stk || (ucell)offs>=(ucell)amx->stp)
3339+
if ((offs>=hea && offs<stk) || (ucell)offs>=(ucell)amx->stp)
33543340
ABORT(amx,AMX_ERR_MEMACCESS);
33553341
pri=_R(data,offs);
33563342
break;
@@ -3840,13 +3826,13 @@ int AMXAPI amx_Exec(AMX *amx, cell *retval, int index)
38403826
/* verify top & bottom memory addresses, for both source and destination
38413827
* addresses
38423828
*/
3843-
if (pri>=hea && pri<stk || (ucell)pri>=(ucell)amx->stp)
3829+
if ((pri>=hea && pri<stk) || (ucell)pri>=(ucell)amx->stp)
38443830
ABORT(amx,AMX_ERR_MEMACCESS);
3845-
if ((pri+offs)>hea && (pri+offs)<stk || (ucell)(pri+offs)>(ucell)amx->stp)
3831+
if (((pri+offs)>hea && (pri+offs)<stk) || (ucell)(pri+offs)>(ucell)amx->stp)
38463832
ABORT(amx,AMX_ERR_MEMACCESS);
3847-
if (alt>=hea && alt<stk || (ucell)alt>=(ucell)amx->stp)
3833+
if ((alt>=hea && alt<stk) || (ucell)alt>=(ucell)amx->stp)
38483834
ABORT(amx,AMX_ERR_MEMACCESS);
3849-
if ((alt+offs)>hea && (alt+offs)<stk || (ucell)(alt+offs)>(ucell)amx->stp)
3835+
if (((alt+offs)>hea && (alt+offs)<stk) || (ucell)(alt+offs)>(ucell)amx->stp)
38503836
ABORT(amx,AMX_ERR_MEMACCESS);
38513837
#if defined _R_DEFAULT
38523838
memcpy(data+(int)alt, data+(int)pri, (int)offs);
@@ -3866,13 +3852,13 @@ int AMXAPI amx_Exec(AMX *amx, cell *retval, int index)
38663852
/* verify top & bottom memory addresses, for both source and destination
38673853
* addresses
38683854
*/
3869-
if (pri>=hea && pri<stk || (ucell)pri>=(ucell)amx->stp)
3855+
if ((pri>=hea && pri<stk) || (ucell)pri>=(ucell)amx->stp)
38703856
ABORT(amx,AMX_ERR_MEMACCESS);
3871-
if ((pri+offs)>hea && (pri+offs)<stk || (ucell)(pri+offs)>(ucell)amx->stp)
3857+
if (((pri+offs)>hea && (pri+offs)<stk) || (ucell)(pri+offs)>(ucell)amx->stp)
38723858
ABORT(amx,AMX_ERR_MEMACCESS);
3873-
if (alt>=hea && alt<stk || (ucell)alt>=(ucell)amx->stp)
3859+
if ((alt>=hea && alt<stk) || (ucell)alt>=(ucell)amx->stp)
38743860
ABORT(amx,AMX_ERR_MEMACCESS);
3875-
if ((alt+offs)>hea && (alt+offs)<stk || (ucell)(alt+offs)>(ucell)amx->stp)
3861+
if (((alt+offs)>hea && (alt+offs)<stk) || (ucell)(alt+offs)>(ucell)amx->stp)
38763862
ABORT(amx,AMX_ERR_MEMACCESS);
38773863
#if defined _R_DEFAULT
38783864
pri=memcmp(data+(int)alt, data+(int)pri, (int)offs);
@@ -3887,9 +3873,9 @@ int AMXAPI amx_Exec(AMX *amx, cell *retval, int index)
38873873
case OP_FILL:
38883874
GETPARAM(offs);
38893875
/* verify top & bottom memory addresses (destination only) */
3890-
if (alt>=hea && alt<stk || (ucell)alt>=(ucell)amx->stp)
3876+
if ((alt>=hea && alt<stk) || (ucell)alt>=(ucell)amx->stp)
38913877
ABORT(amx,AMX_ERR_MEMACCESS);
3892-
if ((alt+offs)>hea && (alt+offs)<stk || (ucell)(alt+offs)>(ucell)amx->stp)
3878+
if (((alt+offs)>hea && (alt+offs)<stk) || (ucell)(alt+offs)>(ucell)amx->stp)
38933879
ABORT(amx,AMX_ERR_MEMACCESS);
38943880
for (i=(int)alt; (size_t)offs>=sizeof(cell); i+=sizeof(cell), offs-=sizeof(cell))
38953881
_W32(data,i,pri);
@@ -4283,17 +4269,6 @@ int AMXAPI amx_Release(AMX *amx,cell amx_addr)
42834269

42844270
#if defined AMX_XXXSTRING || defined AMX_UTF8XXX
42854271

4286-
#define CHARBITS (8*sizeof(char))
4287-
#if PAWN_CELL_SIZE==16
4288-
#define CHARMASK (0xffffu << 8*(2-sizeof(char)))
4289-
#elif PAWN_CELL_SIZE==32
4290-
#define CHARMASK (0xffffffffuL << 8*(4-sizeof(char)))
4291-
#elif PAWN_CELL_SIZE==64
4292-
#define CHARMASK (0xffffffffffffffffuLL << 8*(8-sizeof(char)))
4293-
#else
4294-
#error Unsupported cell size
4295-
#endif
4296-
42974272
int AMXAPI amx_StrLen(const cell *cstr, int *length)
42984273
{
42994274
int len;

amx-deps/src/amx/amx.h

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ extern "C" {
205205

206206
#define UNPACKEDMAX (((cell)1 << (sizeof(cell)-1)*8) - 1)
207207
#define UNLIMITED (~1u >> 1)
208+
#define STKMARGIN ((cell)(16*sizeof(cell)))
208209

209210
struct tagAMX;
210211
typedef cell (AMX_NATIVE_CALL *AMX_NATIVE)(struct tagAMX *amx, const cell *params);
@@ -218,8 +219,10 @@ typedef int (AMXAPI *AMX_IDLE)(struct tagAMX *amx, int AMXAPI Exec(struct tagAMX
218219

219220
#if defined _MSC_VER
220221
#pragma warning(disable:4100) /* "'%$S' : unreferenced formal parameter" */
221-
#pragma warning(disable:4103) /* disable warning message 4103 that complains about pragma pack in a header file */
222-
#pragma warning(disable:4127) /* "conditional expression is constant" (needed for static_assert) */
222+
#pragma warning(disable:4103) /* disable warning message 4103 that complains
223+
* about pragma pack in a header file */
224+
#pragma warning(disable:4127) /* "conditional expression is constant"
225+
* (needed for static_assert) */
223226
#pragma warning(disable:4996) /* POSIX name is deprecated */
224227
#elif defined __GNUC__
225228
#elif defined __clang__
@@ -263,7 +266,9 @@ typedef struct tagAMX_NATIVE_INFO {
263266
#define AMX_USERNUM 4
264267
#endif
265268
#define sEXPMAX 19 /* maximum name length for file version <= 6 */
266-
#define sNAMEMAX 31 /* maximum name length of symbol name */
269+
#ifndef sNAMEMAX
270+
#define sNAMEMAX 31 /* maximum name length of symbol name */
271+
#endif
267272

268273
typedef struct tagAMX_FUNCSTUB {
269274
ucell address PACKED;
@@ -348,6 +353,28 @@ typedef struct tagAMX_HEADER {
348353
#define AMX_MAGIC AMX_MAGIC_64
349354
#endif
350355

356+
#define USENAMETABLE(hdr) \
357+
((hdr)->defsize==sizeof(AMX_FUNCSTUBNT))
358+
#define NUMENTRIES(hdr,field,nextfield) \
359+
(unsigned)(((hdr)->nextfield - (hdr)->field) / (hdr)->defsize)
360+
#define GETENTRY(hdr,table,index) \
361+
(AMX_FUNCSTUB *)((unsigned char*)(hdr) + (unsigned)(hdr)->table + (unsigned)index*(hdr)->defsize)
362+
#define GETENTRYNAME(hdr,entry) \
363+
( USENAMETABLE(hdr) \
364+
? (char *)((unsigned char*)(hdr) + (unsigned)((AMX_FUNCSTUBNT*)(entry))->nameofs) \
365+
: ((AMX_FUNCSTUB*)(entry))->name )
366+
367+
#define CHARBITS (8*sizeof(char))
368+
#if PAWN_CELL_SIZE==16
369+
#define CHARMASK (0xffffu << 8*(2-sizeof(char)))
370+
#elif PAWN_CELL_SIZE==32
371+
#define CHARMASK (0xffffffffuL << 8*(4-sizeof(char)))
372+
#elif PAWN_CELL_SIZE==64
373+
#define CHARMASK (0xffffffffffffffffuLL << 8*(8-sizeof(char)))
374+
#else
375+
#error Unsupported cell size
376+
#endif
377+
351378
enum {
352379
AMX_ERR_NONE,
353380
/* reserve the first 15 error codes for exit codes of the abstract machine */
@@ -496,7 +523,7 @@ int AMXAPI amx_Release(AMX *amx, cell amx_addr);
496523
int AMXAPI amx_SetCallback(AMX *amx, AMX_CALLBACK callback);
497524
int AMXAPI amx_SetDebugHook(AMX *amx, AMX_DEBUG debug);
498525
int AMXAPI amx_SetString(cell *dest, const char *source, int pack, int use_wchar, size_t size);
499-
int AMXAPI amx_SetUserData(AMX *amx, long tag, void *ptr);
526+
int AMXAPI amx_SetUserData(AMX* amx, long tag, void* ptr);
500527
int AMXAPI amx_StrLen(const cell *cstring, int *length);
501528
int AMXAPI amx_UTF8Check(const char *string, int *length);
502529
int AMXAPI amx_UTF8Get(const char *string, const char **endptr, cell *value);

amx-deps/src/amx/amxargs.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ static cell AMX_NATIVE_CALL n_argindex(AMX *amx, const cell *params)
252252
max = (int)params[3];
253253
if (max <= 0)
254254
return 0;
255-
amx_GetAddr(amx, params[2], &cptr);
255+
amx_GetAddr(amx, params[2],&cptr);
256256

257257
if ((option = tokenize(cmdline, params[1], &length)) == NULL) {
258258
/* option not found, return an empty string */
@@ -290,7 +290,7 @@ static cell AMX_NATIVE_CALL n_argstr(AMX *amx, const cell *params)
290290
if (max <= 0)
291291
return 0;
292292
amx_StrParam(amx, params[2], key);
293-
amx_GetAddr(amx, params[3], &cptr);
293+
amx_GetAddr(amx, params[3],&cptr);
294294

295295
option = matcharg(key, (int)params[1], &length);
296296
if (option == NULL)
@@ -329,7 +329,7 @@ static cell AMX_NATIVE_CALL n_argvalue(AMX *amx, const cell *params)
329329
cell *cptr;
330330

331331
amx_StrParam(amx, params[2], key);
332-
amx_GetAddr(amx, params[3], &cptr);
332+
amx_GetAddr(amx, params[3],&cptr);
333333

334334
option = matcharg(key, (int)params[1], &length);
335335
if (option == NULL)

amx-deps/src/amx/amxcons.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -749,21 +749,21 @@ static int dochar(AMX *amx,TCHAR ch,const cell* params,int paramidx,TCHAR sign,T
749749
assert(f_putstr!=NULL);
750750
assert(f_putchar!=NULL);
751751
if (width < 0) {
752-
amx_GetAddr(amx,params[paramidx],&cptr);
752+
amx_GetAddr(amx, params[paramidx],&cptr);
753753
width=*cptr;
754754
++paramidx;
755755
++ret;
756756
}
757757
if (digits < 0) {
758-
amx_GetAddr(amx,params[paramidx],&cptr);
758+
amx_GetAddr(amx, params[paramidx],&cptr);
759759
digits=*cptr;
760760
++paramidx;
761761
++ret;
762762
}
763763

764764
switch (ch) {
765765
case __T('c'):
766-
amx_GetAddr(amx,params[paramidx],&cptr);
766+
amx_GetAddr(amx, params[paramidx],&cptr);
767767
width--; /* single character itself has a with of 1 */
768768
if (sign!=__T('-'))
769769
while (width-->0)
@@ -777,7 +777,7 @@ static int dochar(AMX *amx,TCHAR ch,const cell* params,int paramidx,TCHAR sign,T
777777
case __T('i'): {
778778
cell value;
779779
int length=1;
780-
amx_GetAddr(amx,params[paramidx],&cptr);
780+
amx_GetAddr(amx, params[paramidx],&cptr);
781781
value=*cptr;
782782
if (value<0 || sign==__T('+'))
783783
length++;
@@ -814,7 +814,7 @@ static int dochar(AMX *amx,TCHAR ch,const cell* params,int paramidx,TCHAR sign,T
814814
if (width>0)
815815
_stprintf(formatstring+_tcslen(formatstring),__T("%d"),width);
816816
_stprintf(formatstring+_tcslen(formatstring),__T(".%df"),digits);
817-
amx_GetAddr(amx,params[paramidx],&cptr);
817+
amx_GetAddr(amx, params[paramidx],&cptr);
818818
#if PAWN_CELL_SIZE == 64
819819
_stprintf(buffer,formatstring,*(double*)cptr);
820820
#else
@@ -835,7 +835,7 @@ static int dochar(AMX *amx,TCHAR ch,const cell* params,int paramidx,TCHAR sign,T
835835
#if !defined FLOATPOINT
836836
case __T('r'): /* if fixed point is enabled, and floating point is not, %r == %q */
837837
#endif
838-
amx_GetAddr(amx,params[paramidx],&cptr);
838+
amx_GetAddr(amx, params[paramidx],&cptr);
839839
/* format the number */
840840
if (digits==INT_MAX)
841841
digits=3;
@@ -862,15 +862,15 @@ static int dochar(AMX *amx,TCHAR ch,const cell* params,int paramidx,TCHAR sign,T
862862
info.f_putstr=f_putstr;
863863
info.f_putchar=f_putchar;
864864
info.user=user;
865-
amx_GetAddr(amx,params[paramidx],&cptr);
865+
amx_GetAddr(amx, params[paramidx],&cptr);
866866
amx_printstring(amx,cptr,&info);
867867
return ret;
868868
} /* case */
869869

870870
case __T('x'): {
871871
ucell value;
872872
int length=1;
873-
amx_GetAddr(amx,params[paramidx],&cptr);
873+
amx_GetAddr(amx, params[paramidx],&cptr);
874874
value=*(ucell*)cptr;
875875
while (value>=0x10) {
876876
length++;
@@ -890,7 +890,7 @@ static int dochar(AMX *amx,TCHAR ch,const cell* params,int paramidx,TCHAR sign,T
890890
case __T('b'): {
891891
ucell value;
892892
int length = 1;
893-
amx_GetAddr(amx, params[paramidx], &cptr);
893+
amx_GetAddr(amx, params[paramidx],&cptr);
894894
value = *(ucell*)cptr;
895895
while (value >= 0x1) {
896896
length++;

0 commit comments

Comments
 (0)