Electronics & Programming

develissimo

Open Source electronics development and programming

  • You are not logged in.
  • Root
  • » PHP
  • » [PHP-DEV] Access raw buffer (for binary data) [RSS Feed]

#1 Nov. 1, 2005 00:30:48

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

[PHP-DEV] Access raw buffer (for binary data)


I am developing a PHP plugin using PHP 4.4 SDK (not 5) and I need toaccess a parameter as a raw char * pointer instead of a string or anyother C type.Until now to access parameters I am using the zend_get_parameters_exroutine and then the various convert_to_something routines.I think I can't use the convert_to_string function because myparameters is binary data but I wonder what I can use in this case, Ineed the raw char * pointer and not a C string...Thanks for you reply,
Marco Bambini

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

Offline

#2 Nov. 1, 2005 00:35:58

Rasmus L.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

[PHP-DEV] Access raw buffer (for binary data)


Marco Bambini wrote:I am developing a PHP plugin using PHP 4.4 SDK (not 5) and I need toaccess a parameter as a raw char * pointer instead of a string or anyother C type.Until now to access parameters I am using the zend_get_parameters_exroutine and then the various convert_to_something routines.I think I can't use the convert_to_string function because my parametersis binary data but I wonder what I can use in this case, I need the rawchar * pointer and not a C string...I think you are a bit confused. There is no such thing as a C string.A string in C is simply an array of chars or a char *. In order to dealwith binary data you have to carry the length of the data around withthe char * which is exactly what PHP does. Without that you have no wayof knowing how much binary data you have. So in short, you should befine using the standard PHP API string.-Rasmus

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

Offline

#3 Nov. 1, 2005 00:47:22

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

[PHP-DEV] Access raw buffer (for binary data)


Thanks a lot Rasmus, I have just (wrongly) assumed that theconvert_to_string function tries to search for the 0 terminationcharacter.Thanks,
Marco Bambini

On Nov 1, 2005, at 1:35 AM, Rasmus Lerdorf wrote:Marco Bambini wrote:I am developing a PHP plugin using PHP 4.4 SDK (not 5) and I needto access a parameter as a raw char * pointer instead of a stringor any other C type.Until now to access parameters I am using thezend_get_parameters_ex routine and then the variousconvert_to_something routines.I think I can't use the convert_to_string function because myparameters is binary data but I wonder what I can use in thiscase, I need the raw char * pointer and not a C string...I think you are a bit confused. There is no such thing as a Cstring. A string in C is simply an array of chars or a char *. Inorder to deal with binary data you have to carry the length of thedata around with the char * which is exactly what PHP does.Without that you have no way of knowing how much binary data youhave. So in short, you should be fine using the standard PHP APIstring.-Rasmus

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

Offline

#4 Nov. 1, 2005 08:11:32

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

[PHP-DEV] Access raw buffer (for binary data)


On Tue, 1 Nov 2005, Marco Bambini wrote:

> Thanks a lot Rasmus, I have just (wrongly) assumed that the convert_to_string
> function tries to search for the 0 termination character.

It doesn't - but, PHP strings always require \0 to be the last
character so you always need to allocate one more byte and put the \0 in
there - even for binary data.

Derick

--
Derick Rethanshttp://derickrethans.nl|http://ez.no|http://xdebug.org--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit:http://www.php.net/unsub.php

Offline

#5 Nov. 1, 2005 08:48:27

Rasmus L.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

[PHP-DEV] Access raw buffer (for binary data)


Derick Rethans wrote:On Tue, 1 Nov 2005, Marco Bambini wrote:Thanks a lot Rasmus, I have just (wrongly) assumed that the convert_to_string
function tries to search for the 0 termination character.It doesn't - but, PHP strings always require \0 to be the lastcharacter so you always need to allocate one more byte and put the \0 inthere - even for binary data.That's not really a PHP requirement, but more of a good convention toprevent something external from falling off the end of a string. If youare just working with it internally you don't need it.-Rasmus

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

Offline

#6 Nov. 1, 2005 08:54:28

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

[PHP-DEV] Access raw buffer (for binary data)


On Tue, 1 Nov 2005, Rasmus Lerdorf wrote:

> Derick Rethans wrote:
> > On Tue, 1 Nov 2005, Marco Bambini wrote:
> >
> > > Thanks a lot Rasmus, I have just (wrongly) assumed that the
> > > convert_to_string
> > > function tries to search for the 0 termination character.
> >
> > It doesn't - but, PHP strings always require \0 to be the last character so
> > you always need to allocate one more byte and put the \0 in there - even for
> > binary data.
>
> That's not really a PHP requirement, but more of a good convention to prevent
> something external from falling off the end of a string. If you are just
> working with it internally you don't need it.

Right, but if you store it as a string in a ZVAL you do, otherwise the
engine can warn you about it.

Derick

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

Offline

#7 Nov. 1, 2005 08:55:29

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

[PHP-DEV] Access raw buffer (for binary data)


At 10:47 01/11/2005, Rasmus Lerdorf wrote:Derick Rethans wrote:On Tue, 1 Nov 2005, Marco Bambini wrote:Thanks a lot Rasmus, I have just (wrongly) assumed that theconvert_to_stringfunction tries to search for the 0 termination character.It doesn't - but, PHP strings always require \0 to be the last characterso you always need to allocate one more byte and put the \0 in there -even for binary data.That's not really a PHP requirement, but more of a good convention toprevent something external from falling off the end of a string. If youare just working with it internally you don't need it.It's a mix of both, to clarify:- For 'PHP strings', i.e. strings that go back into PHP, it is a strictrequirement.- For 'internal' strings, assuming internal means strings used by theextension that never go anywhere beyond that, there aren't any requirementsof any kind, other than using the memory allocator perhaps. For thatmatter, strings are like any other kind of data structure.So it all depends on what people understand when they read 'PHP strings' or'internal'.Zeev

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

Offline

  • Root
  • » PHP
  • » [PHP-DEV] Access raw buffer (for binary data) [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