Electronics & Programming

develissimo

Open Source electronics development and programming

  • You are not logged in.
  • Root
  • » PHP
  • » [PHP-DEV] Accept null type hint in C [RSS Feed]

#1 Oct. 27, 2005 07:52:04

Bob S.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

[PHP-DEV] Accept null type hint in C


Hi,

Since NULL typehints are allowed in userland, how would I go about it in C?

I have ZEND_ARG_OBJ_INFO(0, obj, ZObject, 1) which has allow null set on.

Then in the method:

if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O", &objA,
pow_ce_ZObject) == FAILURE) {


If I pass NULL, it fails on the grounds that it isn't a ZObject.

Also,

Could someone explain the purpose of the zend_parse_method_parameters
function as opposed to using the zend_parse_parameters?

Thanks

Bob Silva

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit:http://www.php.net/unsub.php

Offline

#2 Oct. 27, 2005 08:09:08

Marcus B.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

[PHP-DEV] Accept null type hint in C


Hello Bob,

Thursday, October 27, 2005, 8:51:18 AM, you wrote:

> Hi,

> Since NULL typehints are allowed in userland, how would I go about it in C?

> I have ZEND_ARG_OBJ_INFO(0, obj, ZObject, 1) which has allow null set on.

> Then in the method:

> if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O", &objA,
> pow_ce_ZObject) == FAILURE) {

Use "|!O" or "|!o" instead. '!' allows NULL and sets the return value in
c-land to NULL.

marcus


> If I pass NULL, it fails on the grounds that it isn't a ZObject.

> Also,

> Could someone explain the purpose of the zend_parse_method_parameters
> function as opposed to using the zend_parse_parameters?

> Thanks

> Bob Silva




Best regards,
Marcus

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit:http://www.php.net/unsub.php

Offline

#3 Oct. 27, 2005 16:48:21

Bob S.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

[PHP-DEV] Accept null type hint in C


I tried the "|!O" and that really hoses things.

The | gets processed in zend_parse_va_args and removed (spec is
incremented), so that "!O" get sent to zend_parse_arg_impl. Inside of
zend_parse_arg_impl, the ! gets set to char c and spec_walk gets incremented
which makes the check for the null operator fail and also makes the check
for arg type check the ! in the switch case. The result is that "unknown"
got sent as the parameter to the function. Not sure if this would be
classified as a bug, but it doesn't work for trying to accept a null type
hinted parameter in C.

I'll keep playing around with parameter combinations and see what works.

Thanks

Bob Silva


-----Original Message-----
From: Marcus Boerger
Sent: Thursday, October 27, 2005 12:06 AM
To: Bob Silva
Cc: intern***@*ists.php.net
Subject: Re: Accept null type hint in C

Hello Bob,

Thursday, October 27, 2005, 8:51:18 AM, you wrote:

> Hi,

> Since NULL typehints are allowed in userland, how would I go about it in
C?

> I have ZEND_ARG_OBJ_INFO(0, obj, ZObject, 1) which has allow null set on.

> Then in the method:

> if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O", &objA,
> pow_ce_ZObject) == FAILURE) {

Use "|!O" or "|!o" instead. '!' allows NULL and sets the return value in
c-land to NULL.

marcus


> If I pass NULL, it fails on the grounds that it isn't a ZObject.

> Also,

> Could someone explain the purpose of the zend_parse_method_parameters
> function as opposed to using the zend_parse_parameters?

> Thanks

> Bob Silva




Best regards,
Marcus

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit:http://www.php.net/unsub.php

Offline

#4 Oct. 27, 2005 19:18:21

Marcus B.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

[PHP-DEV] Accept null type hint in C


Hello Bob,

that's definitively wrong, actually there must be something wrong with
your code. The '|' is to ensure that the parameter is optional. Thus if you
moit the param it's return value is untouched which means you have to
initaialize the returned zval * to null before passing its address to the
parsing functions. The only way "unknown" gets send back is when you
use an unhandled spec. But you are using "O" or did you actually missread
and took zero? (which would be plain bullshit)

marcus

Thursday, October 27, 2005, 5:47:36 PM, you wrote:

> I tried the "|!O" and that really hoses things.

> The | gets processed in zend_parse_va_args and removed (spec is
> incremented), so that "!O" get sent to zend_parse_arg_impl. Inside of
> zend_parse_arg_impl, the ! gets set to char c and spec_walk gets incremented
> which makes the check for the null operator fail and also makes the check
> for arg type check the ! in the switch case. The result is that "unknown"
> got sent as the parameter to the function. Not sure if this would be
> classified as a bug, but it doesn't work for trying to accept a null type
> hinted parameter in C.

> I'll keep playing around with parameter combinations and see what works.

> Thanks

> Bob Silva


> -----Original Message-----
> From: Marcus Boerger
> Sent: Thursday, October 27, 2005 12:06 AM
> To: Bob Silva
> Cc: intern***@*ists.php.net
> Subject: Re: Accept null type hint in C

> Hello Bob,

> Thursday, October 27, 2005, 8:51:18 AM, you wrote:

>> Hi,

>> Since NULL typehints are allowed in userland, how would I go about it in
> C?

>> I have ZEND_ARG_OBJ_INFO(0, obj, ZObject, 1) which has allow null set on.

>> Then in the method:

>> if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O", &objA,
>> pow_ce_ZObject) == FAILURE) {

> Use "|!O" or "|!o" instead. '!' allows NULL and sets the return value in
> c-land to NULL.

> marcus


>> If I pass NULL, it fails on the grounds that it isn't a ZObject.

>> Also,

>> Could someone explain the purpose of the zend_parse_method_parameters
>> function as opposed to using the zend_parse_parameters?

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit:http://www.php.net/unsub.php

Offline

#5 Oct. 27, 2005 19:33:26

Rob R.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

[PHP-DEV] Accept null type hint in C


Marcus Boerger wrote:Hello Bob,

that's definitively wrong, actually there must be something wrong with
your code. The '|' is to ensure that the parameter is optional. Thus if you
moit the param it's return value is untouched which means you have to
initaialize the returned zval * to null before passing its address to the
parsing functions. The only way "unknown" gets send back is when you
use an unhandled spec. But you are using "O" or did you actually missread
and took zero? (which would be plain bullshit)

marcus

Thursday, October 27, 2005, 5:47:36 PM, you wrote:I tried the "|!O" and that really hoses things.Isn't it supposed to be |O! ?

Rob

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit:http://www.php.net/unsub.php

Offline

#6 Oct. 27, 2005 19:40:30

Marcus B.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

[PHP-DEV] Accept null type hint in C


Hello Rob,

args, shit you're right!

marcus

Thursday, October 27, 2005, 8:35:12 PM, you wrote:

> Marcus Boerger wrote:

>>Hello Bob,
>>
>> that's definitively wrong, actually there must be something wrong with
>>your code. The '|' is to ensure that the parameter is optional. Thus if you
>>moit the param it's return value is untouched which means you have to
>>initaialize the returned zval * to null before passing its address to the
>>parsing functions. The only way "unknown" gets send back is when you
>>use an unhandled spec. But you are using "O" or did you actually missread
>>and took zero? (which would be plain bullshit)
>>
>>marcus
>>
>>Thursday, October 27, 2005, 5:47:36 PM, you wrote:
>>
>>
>>
>>>I tried the "|!O" and that really hoses things.
>>>
>>>
> Isn't it supposed to be |O! ?

> Rob



Best regards,
Marcus

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit:http://www.php.net/unsub.php

Offline

#7 Oct. 27, 2005 23:09:13

Bob S.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

[PHP-DEV] Accept null type hint in C


Thanks guys, the O! works as expected. It didn't need the | since I actually
want to force a parameter to be sent even if it is null.

I did think it was weird that the parse_parameter functions set the zval*
passed in to NULL instead of setting the value/type of the zval to IS_NULL.
This took a bit to debug since it is kinda outta step with the way Zend
handles zvals elsewhere.

BTW Marcus, nice work on the SPL stuff.

Bob

-----Original Message-----
From: Marcus Boerger
Sent: Thursday, October 27, 2005 11:40 AM
To: Rob Richards
Cc: Bob Silva; intern***@*ists.php.net
Subject: Re: Accept null type hint in C

Hello Rob,

args, shit you're right!

marcus

Thursday, October 27, 2005, 8:35:12 PM, you wrote:

> Marcus Boerger wrote:

>>Hello Bob,
>>
>> that's definitively wrong, actually there must be something wrong with
>>your code. The '|' is to ensure that the parameter is optional. Thus if
you
>>moit the param it's return value is untouched which means you have to
>>initaialize the returned zval * to null before passing its address to the
>>parsing functions. The only way "unknown" gets send back is when you
>>use an unhandled spec. But you are using "O" or did you actually missread
>>and took zero? (which would be plain bullshit)
>>
>>marcus
>>
>>Thursday, October 27, 2005, 5:47:36 PM, you wrote:
>>
>>
>>
>>>I tried the "|!O" and that really hoses things.
>>>
>>>
> Isn't it supposed to be |O! ?

> Rob



Best regards,
Marcus

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit:http://www.php.net/unsub.php

Offline

#8 Oct. 28, 2005 19:12:55

Marcus B.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

[PHP-DEV] Accept null type hint in C


Hello Bob,

there is also an *_ex() version of the parsing function that can be made
not emitting a warning on type missmatch. That way you can have a first one
look for the object and a second one look for other types. But we do not
support checking for null. So in your case that would be checking for any
zval and then checking it's type. Thus you could check the number of
arguments with ZEND_NUM_ARGS(), directly grab the zval and check for it's
two allowed types using the old API.

marcus

Friday, October 28, 2005, 12:08:28 AM, you wrote:

> Thanks guys, the O! works as expected. It didn't need the | since I actually
> want to force a parameter to be sent even if it is null.

> I did think it was weird that the parse_parameter functions set the zval*
> passed in to NULL instead of setting the value/type of the zval to IS_NULL.
> This took a bit to debug since it is kinda outta step with the way Zend
> handles zvals elsewhere.

> BTW Marcus, nice work on the SPL stuff.

> Bob

> -----Original Message-----
> From: Marcus Boerger
> Sent: Thursday, October 27, 2005 11:40 AM
> To: Rob Richards
> Cc: Bob Silva; intern***@*ists.php.net
> Subject: Re: Accept null type hint in C

> Hello Rob,

> args, shit you're right!
>
> marcus

> Thursday, October 27, 2005, 8:35:12 PM, you wrote:

>> Marcus Boerger wrote:

>>>Hello Bob,
>>>
>>> that's definitively wrong, actually there must be something wrong with
>>>your code. The '|' is to ensure that the parameter is optional. Thus if
> you
>>>moit the param it's return value is untouched which means you have to
>>>initaialize the returned zval * to null before passing its address to the
>>>parsing functions. The only way "unknown" gets send back is when you
>>>use an unhandled spec. But you are using "O" or did you actually missread
>>>and took zero? (which would be plain bullshit)
>>>
>>>marcus
>>>
>>>Thursday, October 27, 2005, 5:47:36 PM, you wrote:
>>>
>>>
>>>
>>>>I tried the "|!O" and that really hoses things.
>>>>
>>>>
>> Isn't it supposed to be |O! ?

>> Rob



> Best regards,
> Marcus




Best regards,
Marcus

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit:http://www.php.net/unsub.php

Offline

  • Root
  • » PHP
  • » [PHP-DEV] Accept null type hint in C [RSS Feed]

Board footer

Moderator control

Enjoy the 18th of November
PoweredBy

The Forums are managed by develissimo stuff members, if you find any issues or misplaced content please help us to fix it. Thank you! Tell us via Contact Options
Leave a Message
Welcome to Develissimo Live Support