TT_BYTES is converting properly; TT_UINT is not.
This commit is contained in:
parent
49ca034b32
commit
ddbde60396
3 changed files with 84 additions and 27 deletions
24
src/bindings/php/Tests/ChTest.php
Normal file
24
src/bindings/php/Tests/ChTest.php
Normal file
|
|
@ -0,0 +1,24 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
include_once 'hammer.php';
|
||||||
|
|
||||||
|
class ChTest extends PHPUnit_Framework_TestCase
|
||||||
|
{
|
||||||
|
protected $parser;
|
||||||
|
|
||||||
|
protected function setUp()
|
||||||
|
{
|
||||||
|
$this->parser = h_ch("\xa2");
|
||||||
|
}
|
||||||
|
public function testSuccess()
|
||||||
|
{
|
||||||
|
$result = h_parse($this->parser, "\xa2");
|
||||||
|
$this->assertEquals("\xa2", $result);
|
||||||
|
}
|
||||||
|
public function testFailure()
|
||||||
|
{
|
||||||
|
$result = h_parse($this->parser, "95");
|
||||||
|
$this->assertEquals(NULL, $result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
|
@ -8,12 +8,11 @@ class TokenTest extends PHPUnit_Framework_TestCase
|
||||||
|
|
||||||
protected function setUp()
|
protected function setUp()
|
||||||
{
|
{
|
||||||
$this->parser = hammer::h_token("95\xa2");
|
$this->parser = h_token("95\xa2");
|
||||||
}
|
}
|
||||||
public function testSuccess()
|
public function testSuccess()
|
||||||
{
|
{
|
||||||
$result = hammer::h_parse($this->parser, "95\xa2");
|
$result = h_parse($this->parser, "95\xa2");
|
||||||
var_dump($result);
|
|
||||||
$this->assertEquals("95\xa2", $result);
|
$this->assertEquals("95\xa2", $result);
|
||||||
}
|
}
|
||||||
public function testFailure()
|
public function testFailure()
|
||||||
|
|
|
||||||
|
|
@ -136,6 +136,23 @@
|
||||||
|
|
||||||
#if defined(SWIGPHP)
|
#if defined(SWIGPHP)
|
||||||
%ignore HCountedArray_;
|
%ignore HCountedArray_;
|
||||||
|
|
||||||
|
%inline %{
|
||||||
|
static int h_tt_php;
|
||||||
|
%}
|
||||||
|
|
||||||
|
%init %{
|
||||||
|
h_tt_php = h_allocate_token_type("com.upstandinghackers.hammer.php");
|
||||||
|
%}
|
||||||
|
|
||||||
|
%inline {
|
||||||
|
struct HParsedToken_;
|
||||||
|
struct HParseResult_;
|
||||||
|
static zval* hpt_to_php(const struct HParsedToken_ *token);
|
||||||
|
|
||||||
|
//static struct HParsedToken_* call_action(const struct HParseResult_ *p, void* user_data);
|
||||||
|
}
|
||||||
|
|
||||||
%typemap(in) (const uint8_t* str, const size_t len) {
|
%typemap(in) (const uint8_t* str, const size_t len) {
|
||||||
$1 = (uint8_t*)(*$input)->value.str.val;
|
$1 = (uint8_t*)(*$input)->value.str.val;
|
||||||
$2 = (*$input)->value.str.len;
|
$2 = (*$input)->value.str.len;
|
||||||
|
|
@ -166,25 +183,42 @@
|
||||||
// TODO: raise parse failure
|
// TODO: raise parse failure
|
||||||
RETVAL_NULL();
|
RETVAL_NULL();
|
||||||
} else {
|
} else {
|
||||||
$result = hpt_to_php($1->ast);
|
if ($1->ast == NULL) {
|
||||||
printf("Being returned: %s\n", Z_STRVAL_P($result));
|
RETVAL_NULL();
|
||||||
|
} else {
|
||||||
|
switch($1->ast->token_type) {
|
||||||
|
case TT_NONE:
|
||||||
|
RETVAL_NULL();
|
||||||
|
break;
|
||||||
|
case TT_BYTES:
|
||||||
|
RETVAL_STRINGL((char*)$1->ast->token_data.bytes.token, $1->ast->token_data.bytes.len, 1);
|
||||||
|
break;
|
||||||
|
case TT_SINT:
|
||||||
|
RETVAL_LONG($1->ast->token_data.sint);
|
||||||
|
break;
|
||||||
|
case TT_UINT:
|
||||||
|
RETVAL_LONG($1->ast->token_data.uint);
|
||||||
|
break;
|
||||||
|
case TT_SEQUENCE:
|
||||||
|
array_init($result);
|
||||||
|
for (int i=0; i < $1->ast->token_data.seq->used; i++) {
|
||||||
|
add_next_index_zval($result, hpt_to_php($1->ast->token_data.seq->elements[i]));
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
/* if (token->token_type == h_tt_php) { */
|
||||||
|
/* ZEND_REGISTER_RESOURCE(return_value, token->token_data.user, le_swig__p_void); // it's a void*, what else could I do with it? */
|
||||||
|
/* return return_value; */
|
||||||
|
/* } else { */
|
||||||
|
/* // I guess that's a python thing */
|
||||||
|
/* //return (zval*)SWIG_NewPointerObj((void*)token, SWIGTYPE_p_HParsedToken_, 0 | 0); */
|
||||||
|
/* // TODO: support registry */
|
||||||
|
/* } */
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
%inline %{
|
|
||||||
static int h_tt_php;
|
|
||||||
%}
|
|
||||||
|
|
||||||
%init %{
|
|
||||||
h_tt_php = h_allocate_token_type("com.upstandinghackers.hammer.php");
|
|
||||||
%}
|
|
||||||
|
|
||||||
%inline {
|
|
||||||
struct HParsedToken_;
|
|
||||||
struct HParseResult_;
|
|
||||||
static zval* hpt_to_php(const struct HParsedToken_ *token);
|
|
||||||
|
|
||||||
//static struct HParsedToken_* call_action(const struct HParseResult_ *p, void* user_data);
|
|
||||||
}
|
|
||||||
|
|
||||||
#else
|
#else
|
||||||
#warning no Hammer typemaps defined
|
#warning no Hammer typemaps defined
|
||||||
|
|
@ -420,6 +454,7 @@ def int64(): return _h_int64()
|
||||||
return ret;
|
return ret;
|
||||||
case TT_BYTES:
|
case TT_BYTES:
|
||||||
ZVAL_STRINGL(ret, (char*)token->token_data.bytes.token, token->token_data.bytes.len, 1);
|
ZVAL_STRINGL(ret, (char*)token->token_data.bytes.token, token->token_data.bytes.len, 1);
|
||||||
|
printf("Being returned from hpt_to_php: %s\n", Z_STRVAL_P(ret));
|
||||||
return ret;
|
return ret;
|
||||||
case TT_SINT:
|
case TT_SINT:
|
||||||
ZVAL_LONG(ret, token->token_data.sint);
|
ZVAL_LONG(ret, token->token_data.sint);
|
||||||
|
|
@ -430,21 +465,20 @@ def int64(): return _h_int64()
|
||||||
case TT_SEQUENCE:
|
case TT_SEQUENCE:
|
||||||
array_init(ret);
|
array_init(ret);
|
||||||
for (int i=0; i < token->token_data.seq->used; i++) {
|
for (int i=0; i < token->token_data.seq->used; i++) {
|
||||||
add_next_index_zval(ret, hpt_to_php(token->token_data.seq->elements[i]));
|
add_next_index_zval(ret, hpt_to_php(token->token_data.seq->elements[i]));
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
default:
|
default:
|
||||||
/* if (token->token_type == h_tt_php) { */
|
/* if (token->token_type == h_tt_php) { */
|
||||||
/* ZEND_REGISTER_RESOURCE(return_value, token->token_data.user, le_swig__p_void); // it's a void*, what else could I do with it? */
|
/* ZEND_REGISTER_RESOURCE(return_value, token->token_data.user, le_swig__p_void); // it's a void*, wh
|
||||||
/* return return_value; */
|
/* return return_value; */
|
||||||
/* } else { */
|
/* } else { */
|
||||||
/* // I guess that's a python thing */
|
/* // I guess that's a python thing */
|
||||||
/* //return (zval*)SWIG_NewPointerObj((void*)token, SWIGTYPE_p_HParsedToken_, 0 | 0); */
|
/* //return (zval*)SWIG_NewPointerObj((void*)token, SWIGTYPE_p_HParsedToken_, 0 | 0); */
|
||||||
/* // TODO: support registry */
|
/* // TODO: support registry */
|
||||||
/* } */
|
/* } */
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue