Skip to content

Commit a682753

Browse files
committed
Some more fixes for module issues
- fix non-latin charset displaying in formatted strings - more fixes for string library natives
1 parent 073acc0 commit a682753

File tree

6 files changed

+116
-89
lines changed

6 files changed

+116
-89
lines changed

amx-deps/src/CFunctions.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ int CFunctions::amxLoad(lua_State *luaVM) {
169169

170170
// Load .amx
171171
AMX *amx = new AMX;
172-
int err = aux_LoadProgram(amx, amxPath, NULL);
172+
int err = aux_LoadProgram(amx, amxPath, NULL);
173173
if(err != AMX_ERR_NONE) {
174174
delete amx;
175175
lua_pushboolean(luaVM, 0);

amx-deps/src/amx/amx.c

Lines changed: 98 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -1757,31 +1757,41 @@ int AMXAPI amx_PushArray(AMX *amx, cell *amx_addr, cell **phys_addr, const cell
17571757
return err;
17581758
}
17591759

1760+
int AMXAPI amx_PushStringLen(AMX* amx, cell* amx_addr, cell** phys_addr, const char* string, int length, int pack, int use_wchar)
1761+
{
1762+
cell *paddr, xaddr;
1763+
int numcells, err;
1764+
1765+
assert(amx != NULL);
1766+
1767+
numcells = length + 1;
1768+
1769+
if (pack)
1770+
numcells = (numcells + sizeof(cell) - 1) / sizeof(cell);
1771+
err = amx_Allot(amx, numcells, &xaddr, &paddr);
1772+
if (err == AMX_ERR_NONE) {
1773+
if (amx_addr != NULL)
1774+
*amx_addr = xaddr;
1775+
if (phys_addr != NULL)
1776+
*phys_addr = paddr;
1777+
amx_SetStringLen(paddr, string, length, pack, use_wchar, UNLIMITED);
1778+
err = amx_Push(amx, xaddr);
1779+
} /* if */
1780+
return err;
1781+
}
1782+
17601783
int AMXAPI amx_PushString(AMX *amx, cell *amx_addr, cell **phys_addr, const char *string, int pack, int use_wchar)
17611784
{
1762-
cell *paddr, xaddr;
1763-
int numcells,err;
1785+
int length;
17641786

1765-
assert(amx!=NULL);
17661787
assert(string!=NULL);
17671788

17681789
#if defined AMX_ANSIONLY
1769-
numcells=strlen(string) + 1;
1790+
length = strlen(string);
17701791
#else
1771-
numcells= (use_wchar ? wcslen((const wchar_t*)string) : strlen(string)) + 1;
1792+
length = (use_wchar ? wcslen((const wchar_t*)string) : strlen(string));
17721793
#endif
1773-
if (pack)
1774-
numcells=(numcells+sizeof(cell)-1)/sizeof(cell);
1775-
err=amx_Allot(amx,numcells,&xaddr,&paddr);
1776-
if (err==AMX_ERR_NONE) {
1777-
if (amx_addr!=NULL)
1778-
*amx_addr=xaddr;
1779-
if (phys_addr!=NULL)
1780-
*phys_addr=paddr;
1781-
amx_SetString(paddr,string,pack,use_wchar,UNLIMITED);
1782-
err=amx_Push(amx,xaddr);
1783-
} /* if */
1784-
return err;
1794+
return amx_PushStringLen(amx, amx_addr, phys_addr, string, length, pack, use_wchar);
17851795
}
17861796
#endif /* AMX_PUSHXXX */
17871797

@@ -1937,7 +1947,7 @@ static const void * const amx_opcodelist[] = {
19371947
if (index==AMX_EXEC_MAIN) {
19381948
if (hdr->cip<0)
19391949
return AMX_ERR_INDEX;
1940-
cip=(cell *)(code + (int)hdr->cip);
1950+
cip=(cell *)(code+(int)hdr->cip);
19411951
} else if (index==AMX_EXEC_CONT) {
19421952
/* all registers: pri, alt, frm, cip, hea, stk, reset_stk, reset_hea */
19431953
frm=amx->frm;
@@ -1947,14 +1957,14 @@ static const void * const amx_opcodelist[] = {
19471957
alt=amx->alt;
19481958
reset_stk=amx->reset_stk;
19491959
reset_hea=amx->reset_hea;
1950-
cip=(cell *)(code + (int)amx->cip);
1960+
cip=(cell *)(code+(int)amx->cip);
19511961
} else if (index<0) {
19521962
return AMX_ERR_INDEX;
19531963
} else {
19541964
if (index>=(int)NUMENTRIES(hdr,publics,natives))
19551965
return AMX_ERR_INDEX;
19561966
func=GETENTRY(hdr,publics,index);
1957-
cip=(cell *)(code + (int)func->address);
1967+
cip=(cell *)(code+(int)func->address);
19581968
} /* if */
19591969
/* check values just copied */
19601970
CHKSTACK();
@@ -2206,7 +2216,7 @@ static const void * const amx_opcodelist[] = {
22062216
frm=pri;
22072217
break;
22082218
case 6:
2209-
cip=(cell *)(code + (int)pri);
2219+
cip=(cell *)(code+(int)pri);
22102220
break;
22112221
} /* switch */
22122222
NEXT(cip);
@@ -2301,7 +2311,7 @@ static const void * const amx_opcodelist[] = {
23012311
NEXT(cip);
23022312
op_jrel:
23032313
offs=*cip;
2304-
cip=(cell *)((unsigned char *)cip + (int)offs + sizeof(cell));
2314+
cip=(cell *)((unsigned char *)cip+(int)offs + sizeof(cell));
23052315
NEXT(cip);
23062316
op_jzer:
23072317
if (pri==0)
@@ -2749,7 +2759,7 @@ static const void * const amx_opcodelist[] = {
27492759
NEXT(cip);
27502760
op_symbol:
27512761
GETPARAM(offs);
2752-
cip=(cell *)((unsigned char *)cip + (int)offs);
2762+
cip=(cell *)((unsigned char *)cip+(int)offs);
27532763
NEXT(cip);
27542764
op_srange:
27552765
SKIPPARAM(2);
@@ -3093,7 +3103,7 @@ int AMXAPI amx_Exec(AMX *amx, cell *retval, int index)
30933103
if (index==AMX_EXEC_MAIN) {
30943104
if (hdr->cip<0)
30953105
return AMX_ERR_INDEX;
3096-
cip=(cell *)(code + (int)hdr->cip);
3106+
cip=(cell *)(code+(int)hdr->cip);
30973107
} else if (index==AMX_EXEC_CONT) {
30983108
/* all registers: pri, alt, frm, cip, hea, stk, reset_stk, reset_hea */
30993109
frm=amx->frm;
@@ -3103,14 +3113,14 @@ int AMXAPI amx_Exec(AMX *amx, cell *retval, int index)
31033113
alt=amx->alt;
31043114
reset_stk=amx->reset_stk;
31053115
reset_hea=amx->reset_hea;
3106-
cip=(cell *)(code + (int)amx->cip);
3116+
cip=(cell *)(code+(int)amx->cip);
31073117
} else if (index<0) {
31083118
return AMX_ERR_INDEX;
31093119
} else {
31103120
if (index>=(cell)NUMENTRIES(hdr,publics,natives))
31113121
return AMX_ERR_INDEX;
31123122
func=GETENTRY(hdr,publics,index);
3113-
cip=(cell *)(code + (int)func->address);
3123+
cip=(cell *)(code+(int)func->address);
31143124
} /* if */
31153125
/* check values just copied */
31163126
CHKSTACK();
@@ -3405,7 +3415,7 @@ int AMXAPI amx_Exec(AMX *amx, cell *retval, int index)
34053415
frm=pri;
34063416
break;
34073417
case 6:
3408-
cip=(cell *)(code + (int)pri);
3418+
cip=(cell *)(code+(int)pri);
34093419
break;
34103420
} /* switch */
34113421
break;
@@ -3501,7 +3511,7 @@ int AMXAPI amx_Exec(AMX *amx, cell *retval, int index)
35013511
break;
35023512
case OP_JREL:
35033513
offs=*cip;
3504-
cip=(cell *)((unsigned char *)cip + (int)offs + sizeof(cell));
3514+
cip=(cell *)((unsigned char *)cip+(int)offs + sizeof(cell));
35053515
break;
35063516
case OP_JZER:
35073517
if (pri==0)
@@ -3946,7 +3956,7 @@ int AMXAPI amx_Exec(AMX *amx, cell *retval, int index)
39463956
break;
39473957
case OP_SYMBOL:
39483958
GETPARAM(offs);
3949-
cip=(cell *)((unsigned char *)cip + (int)offs);
3959+
cip=(cell *)((unsigned char *)cip+(int)offs);
39503960
break;
39513961
case OP_SRANGE:
39523962
SKIPPARAM(2);
@@ -4306,61 +4316,72 @@ int AMXAPI amx_StrLen(const cell *cstr, int *length)
43064316
#endif
43074317

43084318
#if defined AMX_XXXSTRING || defined AMX_EXEC
4319+
int AMXAPI amx_SetStringLen(cell* dest, const char* source, int length, int pack, int use_wchar, size_t size)
4320+
{ /* the memory blocks should not overlap */
4321+
int len, i;
4322+
4323+
assert_static(UNLIMITED > 0);
4324+
len = length;
4325+
if (pack) {
4326+
/* create a packed string */
4327+
if (size < UNLIMITED / sizeof(cell) && (size_t)len >= size * sizeof(cell))
4328+
len = size * sizeof(cell) - 1;
4329+
dest[len / sizeof(cell)] = 0; /* clear last bytes of last (semi-filled) cell*/
4330+
#if defined AMX_ANSIONLY
4331+
memcpy(dest, source, len);
4332+
#else
4333+
if (use_wchar) {
4334+
for (i = 0; i < len; i++)
4335+
((char*)dest)[i] = (char)(((wchar_t*)source)[i]);
4336+
} else {
4337+
memcpy(dest, source, len);
4338+
} /* if */
4339+
#endif
4340+
/* On Big Endian machines, the characters are well aligned in the
4341+
* cells; on Little Endian machines, we must swap all cells.
4342+
*/
4343+
assert(check_endian());
4344+
#if BYTE_ORDER == LITTLE_ENDIAN
4345+
len /= sizeof(cell);
4346+
while (len > 0)
4347+
swapcell((ucell*)&dest[len--]);
4348+
swapcell((ucell*)&dest[0]);
4349+
#endif
4350+
4351+
} else {
4352+
/* create an unpacked string */
4353+
if (size < UNLIMITED && (size_t)len >= size)
4354+
len = size - 1;
4355+
#if defined AMX_ANSIONLY
4356+
for (i = 0; i < len; i++)
4357+
dest[i] = (cell)source[i];
4358+
#else
4359+
if (use_wchar) {
4360+
for (i = 0; i < len; i++)
4361+
dest[i] = (cell)(((wchar_t*)source)[i]);
4362+
} else {
4363+
for (i = 0; i < len; i++)
4364+
dest[i] = (cell)(unsigned char)source[i];
4365+
} /* if */
4366+
#endif
4367+
dest[len] = 0;
4368+
} /* if */
4369+
return AMX_ERR_NONE;
4370+
}
4371+
43094372
int AMXAPI amx_SetString(cell *dest,const char *source,int pack,int use_wchar,size_t size)
43104373
{ /* the memory blocks should not overlap */
4311-
int len, i;
4374+
int length;
4375+
4376+
assert(source!=NULL);
43124377

4313-
assert_static(UNLIMITED>0);
43144378
#if defined AMX_ANSIONLY
43154379
(void)use_wchar;
4316-
len=strlen(source);
4380+
length = strlen(source);
43174381
#else
4318-
len= use_wchar ? wcslen((const wchar_t*)source) : strlen(source);
4382+
length = use_wchar ? wcslen((const wchar_t*)source) : strlen(source);
43194383
#endif
4320-
if (pack) {
4321-
/* create a packed string */
4322-
if (size<UNLIMITED/sizeof(cell) && (size_t)len>=size*sizeof(cell))
4323-
len=size*sizeof(cell)-1;
4324-
dest[len/sizeof(cell)]=0; /* clear last bytes of last (semi-filled) cell*/
4325-
#if defined AMX_ANSIONLY
4326-
memcpy(dest,source,len);
4327-
#else
4328-
if (use_wchar) {
4329-
for (i=0; i<len; i++)
4330-
((char*)dest)[i]=(char)(((wchar_t*)source)[i]);
4331-
} else {
4332-
memcpy(dest,source,len);
4333-
} /* if */
4334-
#endif
4335-
/* On Big Endian machines, the characters are well aligned in the
4336-
* cells; on Little Endian machines, we must swap all cells.
4337-
*/
4338-
assert(check_endian());
4339-
#if BYTE_ORDER==LITTLE_ENDIAN
4340-
len /= sizeof(cell);
4341-
while (len>=0)
4342-
swapcell((ucell *)&dest[len--]);
4343-
#endif
4344-
4345-
} else {
4346-
/* create an unpacked string */
4347-
if (size<UNLIMITED && (size_t)len>=size)
4348-
len=size-1;
4349-
#if defined AMX_ANSIONLY
4350-
for (i=0; i<len; i++)
4351-
dest[i]=(cell)source[i];
4352-
#else
4353-
if (use_wchar) {
4354-
for (i=0; i<len; i++)
4355-
dest[i]=(cell)(((wchar_t*)source)[i]);
4356-
} else {
4357-
for (i=0; i<len; i++)
4358-
dest[i]=(cell)source[i];
4359-
} /* if */
4360-
#endif
4361-
dest[len]=0;
4362-
} /* if */
4363-
return AMX_ERR_NONE;
4384+
return amx_SetStringLen(dest, source, length, pack, use_wchar, size);
43644385
}
43654386
#endif
43664387

amx-deps/src/amx/amx.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ extern "C" {
203203
#error Unsupported cell size (PAWN_CELL_SIZE)
204204
#endif
205205

206-
#define UNPACKEDMAX (((cell)1 << (sizeof(cell)-1)*8) - 1)
206+
#define UNPACKEDMAX (((ucell)1 << (sizeof(ucell)-1)*8) - 1)
207207
#define UNLIMITED (~1u >> 1)
208208
#define STKMARGIN ((cell)(16*sizeof(cell)))
209209

@@ -219,10 +219,8 @@ typedef int (AMXAPI *AMX_IDLE)(struct tagAMX *amx, int AMXAPI Exec(struct tagAMX
219219

220220
#if defined _MSC_VER
221221
#pragma warning(disable:4100) /* "'%$S' : unreferenced formal parameter" */
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) */
222+
#pragma warning(disable:4103) /* disable warning message 4103 that complains about pragma pack in a header file */
223+
#pragma warning(disable:4127) /* "conditional expression is constant" (needed for static_assert) */
226224
#pragma warning(disable:4996) /* POSIX name is deprecated */
227225
#elif defined __GNUC__
228226
#elif defined __clang__
@@ -517,12 +515,14 @@ int AMXAPI amx_NumTags(AMX *amx, int *number);
517515
int AMXAPI amx_Push(AMX *amx, cell value);
518516
int AMXAPI amx_PushArray(AMX *amx, cell *amx_addr, cell **phys_addr, const cell array[], int numcells);
519517
int AMXAPI amx_PushString(AMX *amx, cell *amx_addr, cell **phys_addr, const char *string, int pack, int use_wchar);
518+
int AMXAPI amx_PushStringLen(AMX* amx, cell* amx_addr, cell** phys_addr, const char* string, int length, int pack, int use_wchar);
520519
int AMXAPI amx_RaiseError(AMX *amx, int error);
521520
int AMXAPI amx_Register(AMX *amx, const AMX_NATIVE_INFO *nativelist, int number);
522521
int AMXAPI amx_Release(AMX *amx, cell amx_addr);
523522
int AMXAPI amx_SetCallback(AMX *amx, AMX_CALLBACK callback);
524523
int AMXAPI amx_SetDebugHook(AMX *amx, AMX_DEBUG debug);
525524
int AMXAPI amx_SetString(cell *dest, const char *source, int pack, int use_wchar, size_t size);
525+
int AMXAPI amx_SetStringLen(cell* dest, const char* source, int length, int pack, int use_wchar, size_t size);
526526
int AMXAPI amx_SetUserData(AMX* amx, long tag, void* ptr);
527527
int AMXAPI amx_StrLen(const cell *cstring, int *length);
528528
int AMXAPI amx_UTF8Check(const char *string, int *length);

amx-deps/src/amx/amxstring.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,9 +172,15 @@ static cell extractchar(cell *string,int index,int mklower)
172172
c=string[index];
173173
if (mklower) {
174174
#if defined __WIN32__ || defined _WIN32 || defined WIN32
175-
c=(cell)CharLower((LPTSTR)c);
175+
/* this takes a string pointer or a single character */
176+
intptr_t p=c;
177+
p=(intptr_t)CharLower((LPTSTR)p);
178+
c=(cell)p;
176179
#elif defined _Windows
177-
c=(cell)AnsiLower((LPSTR)c);
180+
/* just fix some truncation warnings */
181+
intptr_t p=c;
182+
p=(intptr_t)AnsiLower((LPSTR)p);
183+
c=(cell)p;
178184
#else
179185
if ((unsigned int)(c-'A')<26u)
180186
c+='a'-'A';

amx-deps/src/lib/lua5.1.so

-1.45 MB
Binary file not shown.

amx-deps/src/util.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,9 @@ std::string ToUTF8(const char * str)
6868

6969
std::string ToOriginalCP(const char * str)
7070
{
71-
/*iconv_t conv = iconv_open("CP1251","UTF-8");
72-
iconv(conv, (const char**)&str, (size_t*)&strLen, &pOut, (size_t*)&newstrLen);
73-
iconv_close(conv);*/
71+
/*iconv_t conv = iconv_open("CP1251","UTF-8");
72+
iconv(conv, (const char**)&str, (size_t*)&strLen, &pOut, (size_t*)&newstrLen);
73+
iconv_close(conv);*/
7474

7575
std::wstring newstr = utf8_mbstowcs(str);
7676

@@ -82,7 +82,7 @@ std::string ToOriginalCP(const char * str)
8282
dest[newstr.length()] = 0;
8383

8484
std::string retstr = dest;
85-
delete[] dest;
85+
delete[] dest;
8686
return retstr;
8787
}
8888

0 commit comments

Comments
 (0)