Re: native functions that returns arrays

103 views
Skip to first unread message

杨标(Vinge)

unread,
May 5, 2013, 10:31:42 PM5/5/13
to pawnscript
Hi Alex! Sorry that I can't get it. Can you talk about it with more detail.
Without pointer operations, How can I get the data in the allocated
memory through the address returned to pawn?
Shouled I defina a native function to read wirte the memory like:
cell nativeArrayRead(address, index)
cell nativeArrayWrite(address,index,value)
some thing like that?

  

======== 2013-05-06 07:18:06 您在来信中写道: ========

Today's Topic Summary
Group: http://groups.google.com/group/pawnscript/topics
native functions that returns arrays [1 Update]
Ternary operator using stupid stack sizes. [3 Updates]
native functions that returns arrays
Alex Cole <yle...@gmail.com> May 05 09:32AM -0700

PAWN doesn't have pointers, but it does have addresses. I suspect you
allocate memory on the heap then return that address as a single cell from
the native.


Ternary operator using stupid stack sizes.
Alex Cole <yle...@gmail.com> May 05 07:17AM -0700

OK, I've managed to produce a minimal test case:

#pragma tabsize 4
#pragma semicolon 1
#pragma ctrlchar '\\'

stock SomeFunction()
{
#if defined __COMPILER_SECOND_PASS
for (new loop = 1; loop; loop = (loop ? 0 : 1))
#endif
{
}
return 0;
}

main()
{
return SomeFunction() ? 0 : 1;
}

static stock __COMPILER_SECOND_PASS() {}

When I compile this with 3.2.3664 it gives excess heap allocations on the
final "return" of the code. When I compile this with 4.0.4733 I get:

Assertion Failed: result, function hier13, file sc3.c, line 1197.
ABNORMAL TERMINATION

Which does seem to confirm that there is a bug in heap allocation somewhere
and that it still exists. I don't have any other compilers compiled on
which to test.


Alex Cole <yle...@gmail.com> May 05 07:22AM -0700

Actually, you don't even need the loop:

new gVar;

stock SomeFunction()
{
#if defined main
gVar = (gVar ? 0 : 1);
#endif
return 0;
}

main()
{
return SomeFunction() ? 0 : 1;
}


Alex Cole <yle...@gmail.com> May 05 07:50AM -0700

Sorry, I can't figure out how to edit messages (probably as they're
emails). Just a note that I first reported this here:

http://forum.sa-mp.com/showpost.php?p=2508346

As I'm Y_Less from the SA:MP forums.


You received this message because you are subscribed to the Google Group pawnscript.
You can post via email.
To unsubscribe from this group, send an empty message.
For more options, visit this group.

--
You received this message because you are subscribed to the Google Groups "Pawn Scripting Language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pawnscript+...@googlegroups.com.
To post to this group, send email to pawns...@googlegroups.com.
Visit this group at http://groups.google.com/group/pawnscript?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




= = = = = = = = = = = = = = = = = = = = = =
        致
礼!

              杨标(Vinge)
              ven....@gmail.com
               2013-05-06

Alex Cole

unread,
May 6, 2013, 9:25:40 AM5/6/13
to pawns...@googlegroups.com
OK, I don't know sorry.  I was playing about with this but it didn't work as I thought it did (you might have better luck):

/*
static cell AMX_NATIVE_CALL
    n_ArrRet(AMX * amx, cell * params)
{
    cell
        pawnRet;
    cell
        data[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
    amx_PushArray(amx, &pawnRet, 0, data, sizeof (data) / sizeof (cell));
    return pawnRet;
}
*/

native [10]ArrRet();

#include <a_samp>

main()
{
    new
        a[10];
    a = ArrRet();
    Func(a);
}

Func(arr[], s = sizeof (arr))
{
    for (new i = 0; i != s; ++i)
    {
        printf("arr[%d] = %d", i, arr[i]);
    }
}

Reply all
Reply to author
Forward
0 new messages