Skip to content

Commit 2888f3c

Browse files
committed
Update SourcePawn.
This modifies smn_sorting to use the new 2D array access API.
1 parent b118947 commit 2888f3c

2 files changed

Lines changed: 27 additions & 15 deletions

File tree

core/logic/smn_sorting.cpp

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -283,13 +283,17 @@ int sort_strings_asc(const void *blk1, const void *blk2)
283283
cell_t str_addr1 = *(cell_t *)blk1;
284284
cell_t str_addr2 = *(cell_t *)blk2;
285285

286-
char *str1;
287-
char *str2;
288-
if (sSortContext->LocalToString(str_addr1, &str1) != SP_ERROR_NONE ||
289-
sSortContext->LocalToString(str_addr2, &str2) != SP_ERROR_NONE)
286+
ARRAY_PTR h1, h2;
287+
if (sSortContext->LocalToArrayPtr(str_addr1, &h1) != SP_ERROR_NONE ||
288+
sSortContext->LocalToArrayPtr(str_addr2, &h2) != SP_ERROR_NONE)
290289
{
291290
return 0;
292291
}
292+
char *str1 = (char *)sSortContext->GetArrayData(h1);
293+
char *str2 = (char *)sSortContext->GetArrayData(h2);
294+
295+
if (!str1 || !str2)
296+
return 0;
293297

294298
return strcmp(str1, str2);
295299
}
@@ -299,13 +303,17 @@ int sort_strings_desc(const void *blk1, const void *blk2)
299303
cell_t str_addr1 = *(cell_t *)blk1;
300304
cell_t str_addr2 = *(cell_t *)blk2;
301305

302-
char *str1;
303-
char *str2;
304-
if (sSortContext->LocalToString(str_addr1, &str1) != SP_ERROR_NONE ||
305-
sSortContext->LocalToString(str_addr2, &str2) != SP_ERROR_NONE)
306+
ARRAY_PTR h1, h2;
307+
if (sSortContext->LocalToArrayPtr(str_addr1, &h1) != SP_ERROR_NONE ||
308+
sSortContext->LocalToArrayPtr(str_addr2, &h2) != SP_ERROR_NONE)
306309
{
307310
return 0;
308311
}
312+
char *str1 = (char *)sSortContext->GetArrayData(h1);
313+
char *str2 = (char *)sSortContext->GetArrayData(h2);
314+
315+
if (!str1 || !str2)
316+
return 0;
309317

310318
return strcmp(str2, str1);
311319
}
@@ -316,12 +324,14 @@ static cell_t sm_SortStrings(IPluginContext *pContext, const cell_t *params)
316324
if (!rt->UsesDirectArrays())
317325
return sm_SortStrings_Legacy(pContext, params);
318326

319-
cell_t *array;
327+
ARRAY_PTR handle;
328+
if (pContext->LocalToArrayPtr(params[1], &handle) != SP_ERROR_NONE)
329+
return 0;
330+
331+
cell_t *array = (cell_t *)pContext->GetArrayData(handle);
320332
cell_t array_size = params[2];
321333
cell_t type = params[3];
322334

323-
pContext->LocalToPhysAddr(params[1], &array);
324-
325335
ke::SaveAndSet<IPluginContext*> set_context(&sSortContext, pContext);
326336

327337
if (type == Sort_Ascending)
@@ -507,12 +517,14 @@ static cell_t sm_SortCustom2D(IPluginContext *pContext, const cell_t *params)
507517
if (!rt->UsesDirectArrays())
508518
return sm_SortCustom2D_Legacy(pContext, params);
509519

510-
cell_t *array;
520+
ARRAY_PTR handle;
521+
if (pContext->LocalToArrayPtr(params[1], &handle) != SP_ERROR_NONE)
522+
return 0;
523+
524+
cell_t *array = (cell_t *)pContext->GetArrayData(handle);
511525
cell_t array_size = params[2];
512526
IPluginFunction *pFunction;
513527

514-
pContext->LocalToPhysAddr(params[1], &array);
515-
516528
if ((pFunction=pContext->GetFunctionById(params[3])) == NULL)
517529
{
518530
return pContext->ThrowNativeError("Function %x is not a valid function", params[3]);

0 commit comments

Comments
 (0)