Jump to content


Photo

Calling internal function


  • Please log in to reply
1 reply to this topic

#1 wreckman

wreckman
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 11 March 2004 - 09:22 AM

I can't call a C function (internal) in an exported PHP function ! (like ftp extension for exemple)
I don't understand why, if anyone can help, please.....


Here are the sources files of my module :

php_test.c // Zend module definition files
php_php_test.h

testc.c // Non exported C functions
testc.h

Here is a sample of php_test.c :

// Return a string, Takes a string
PHP_FUNCTION(test)
{
char *szNomRepToGet;
int argc = ZEND_NUM_ARGS();
int szNomRepToGet_len;

if(zend_parse_parameters(argc TSRMLS_CC, "s", &szNomRepToGet, szNomRepToGet_len) == FAILURE)
{ return; }

char *value;
value = testcc(szNomRepToGet);
RETURN_STRING(value,1);
}

Here is a sample of testc.c

static char* testcc(char* toto); // defintion

char* testcc(char* toto)
{
stcRep StcRepTest;

/* INITIALISATION DE MA STRUCTURE */
StcRepTest.num = 1;
strcpy(StcRepTest.text, "toto");

/* TEST CONTENU STRUCTURE */
if(StcRepTest.num == 1)
{
// zend_printf("Bien vu, ta struct est déclarée");
char* testok = "ok";
return testok;
}
char* testnok = "nok";
return testnok;
}

Here is a sample of testc.h

typedef struct
{
int num;
char* text;
}stcRep;


static char* testcc(char* toto);


Thanks in advance, Rom1
...Reading : Building Custom PHP Extensions => Very Good Book !

#2 wreckman

wreckman
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 11 March 2004 - 04:51 PM

The problem is found.........

forgot to emalloc a reception variable for toto

StcRepTest.text = (char *) emalloc(strlen("toto")+1);


GOOD LUCK, EXT'CODERS




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users