Assertion failed

70 views
Skip to first unread message

Tasa V

unread,
Apr 12, 2016, 10:38:56 AM4/12/16
to Pawn Scripting Language
Hello,

i'm using the example code from pawn to run a abstract machine. This is a modified of prun4.c.
The original prun4.c example runs perfect. I am using VS 2015 (project generated via CMake).

Okay, what I'm trying is to split up the code of prun4 up to use a function which executes the pawn function i define how often i want.
I created AMX amx Variable in the main and give them to the function:

int main(int argc, char *argv[])
{
...
AMX amx;
...
usePawnFunction(&amx, "rot13", "some text");
usePawnFunction(&amx, "rot13", "some other text");
usePawnFunction(&amx, "rot13", "some more blabla");
...
}

The function structur itself:

int usePawnFunction(AMX *amx, char *functionName, char *functionParameterValue)
{
...
amx_GetString(output, address, 0, sizeof output);
amx_Release(&amx, address);
...
}

The problem is that it doesn't work since i created the function. There must be a problem with the "AMX amx"-Variable. I get an error on execution:




I also tried to create AMX amx as a pointer and reservate space through malloc:
AMX *amx;
amx = (struct tagAMX *)malloc(sizeof(struct tagAMX));
But it doesn't anything on it.


So how can I fix this error?
I need the AMX amx Variable also outside in other functions i want to write.



------------------------------------
Here is the whole code of my modified example pawnrun.c:

/*  Command-line shell for the "Pawn" Abstract Machine.
*
*  Copyright (c) ITB CompuPhase, 2001-2010
*
*  This file may be freely used. No warranties of any kind.
*/
#include <stdio.h>
#include <stdlib.h>     /* for exit() */
#include <string.h>     /* for memset() (on some compilers) */
#include "amx.h"
#include "amxaux.c"


void ErrorExit(AMX *amx, int errorcode)
{
printf("Run time error %d: \"%s\" on address %ld\n",
errorcode, aux_StrError(errorcode),
(amx != NULL) ? amx->cip : 0);
}

void PrintUsage(char *program)
{
printf("Usage: %s <filename>\n", program);
exit(1);
}

int usePawnFunction(AMX *amx, char *functionName, char *functionParameterValue)
{
size_t memsize;
void *program;
int index, err;
cell *address;
char output[128];

err = amx_FindPublic(&amx, functionName, &index); // searching pawn function with name given in functionName
if (err)
{
ErrorExit(&amx, err);
return -1;
}

err = amx_PushString(&amx, &address, functionParameterValue, 0, 0); // gives value functionParameterValue on first parameter of pawn function
if (err)
{
ErrorExit(&amx, err);
return -1;
}

err = amx_Exec(&amx, NULL, index);
if (err)
{
ErrorExit(&amx, err);
return -1;
}

amx_GetString(output, address, 0, sizeof output);
amx_Release(&amx, address);
printf("function %s returns \"%s\"\n", functionName, output);
}

int main(int argc, char *argv[])
{
extern int AMXAPI amx_ConsoleInit(AMX *amx);
extern int AMXAPI amx_ConsoleCleanup(AMX *amx);
extern int AMXAPI amx_CoreInit(AMX *amx);
extern int AMXAPI amx_CoreCleanup(AMX *amx);

size_t memsize;
void *program;
AMX amx;
int index, err;
cell *address;
char output[128];
char name[32];

while (1)
{
system("echo %cd%");
printf("\n");
printf("Enter name of program to load. e for exit: ");
scanf("%s", name);

if (strcmp(name, "e") == 0)
break;

size_t memsize;
void *program;
int err;

if ((memsize = aux_ProgramSize(name)) == 0)
{
printf("Program not found.\n");
return -1;
}

program = malloc(memsize);
if (program == NULL)
{
ErrorExit(NULL, AMX_ERR_MEMORY);
return -1;
}

err = aux_LoadProgram(&amx, name, program);
if (err)
{
ErrorExit(&amx, err);
return -1;
}

amx_ConsoleInit(&amx);
err = amx_CoreInit(&amx);
if (err)
{
ErrorExit(&amx, err);
return -1;
}

if (usePawnFunction(&amx, "rot13", "some text") == -1)
continue;

if (usePawnFunction(&amx, "rot13", "some other text") == -1)
continue;

if (usePawnFunction(&amx, "rot13", "some more blabla") == -1)
continue;

amx_ConsoleCleanup(&amx);
amx_CoreCleanup(&amx);
amx_Cleanup(&amx);
free(program);
}

return 0;
}







pawnrun.c

Thiadmer Riemersma

unread,
May 15, 2016, 2:38:37 PM5/15/16
to pawns...@googlegroups.com
The problem is that in your function usePawnFunction() you don't pass the address of the AMX variable to the functions of the abstract machine API, but you pass the address of a pointer to the AMX variable. So that's an address of an address.

Concretely, on line 35, which says:

    err = amx_FindPublic(&amx, functionName, &index);

you must remove the "&" before variable "amx". That is, it shoud become:

    err = amx_FindPublic(amx, functionName, &index);

This must be fixed throughout the function. For example, there is the same fix on lines 38, 42, 45, 49, 52 and 57.

You C compiler ought to have warned you of this. If it did not, then either you have you warning level set too low, or you are ignoring warnings.

--
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 https://groups.google.com/group/pawnscript.
For more options, visit https://groups.google.com/d/optout.

Tasa V

unread,
May 21, 2016, 9:46:19 AM5/21/16
to Pawn Scripting Language
Thank you, it works now! That was a stupid mistake.
I'm using VS2015.
----
But I have another problem. I tried to add a simple native-function (also tried the Power-example) but I get a run time error 19 on executing the pawn script.
I followed the implementer guide:

I created the function in my pawnrun.c:
static cell AMX_NATIVE_CALL doublenbr(AMX *amx, const cell *params)
{
return params[1] * 2;
}

I linked the function:
AMX_NATIVE_INFO test_Natives[] = {
{ "doublenbr",       doublenbr },
{ NULL, NULL }        /* terminator */
};

int main(int argc, char *argv[])
{
...

amx_ConsoleInit(&amx);
err = amx_CoreInit(&amx);
if (err)
{
ErrorExit(&amx, err);
return -1;
}

err = amx_Register(&amx, test_Natives, -1);
if (err)
{
ErrorExit(&amx, err);
return -1;
}

if (usePawnFunction(&amx, "rot13", "some text") == -1)
continue;
...

I created a test.inc:
native doublenbr(c);

In my pawn script file I tried to use the function with:
doublenbr(2);

But the problem is, when I load the pawn script it writes me:
Run time error 19: "File or function is not found" on address 0

I don't know what I'm doing wrong, I tried different things, taking code from the Power.c example, setting AMX_NATIVE_CALL to different calling conventions (like in the implementer guide). I couldn't see warnings for that in the compiler.
Can you help me again please?

I attached my code + the plugin.
pawnrun.c
pawn-script.zip

Tasa V

unread,
Jan 19, 2017, 10:30:52 PM1/19/17
to Pawn Scripting Language
Hi,
can no one help me?
I can't get the natives run. Compiling works fine under Windows (VS2015) and Linux GCC, but on both I got this pawn-error when I run a pawn script with "native doublenbr(c);"

Run time error 19: "File or function is not found" on address 0

I really don't know what to do

Can some one please help me ?
Code is in my previous post.

Thiadmer Riemersma

unread,
Jan 20, 2017, 7:20:20 AM1/20/17
to pawns...@googlegroups.com
Sorry for the late reply.

You should ignore error 19 until the last call to amx_Register(). One way to do this is to simply register all native functions and only check for errors in the very last call. See the snippet below, where I have commented out a few lines of your code.

amx_ConsoleInit(&amx);
err = amx_CoreInit(&amx);
// if (err)
// {
//     ErrorExit(&amx, err);
//     return -1;
// }

err = amx_Register(&amx, test_Natives, -1);
if (err)
{
    ErrorExit(&amx, err);
    return -1;
}
I hope this helps,
Thiadmer Riemersma


To unsubscribe from this group and stop receiving emails from it, send an email to pawnscript+unsubscribe@googlegroups.com.

Tasa V

unread,
Jan 20, 2017, 6:12:12 PM1/20/17
to Pawn Scripting Language
Hi Thiadmer,

I didn't knew that ConsoleInit and CoreInit are Natives-Register functions.
Thank you for that! It works!

King Regards
Reply all
Reply to author
Forward
0 new messages