Re: PHP extension writing

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Torsten!

On 24.09.2016 at 18:31, Torsten Rosenberger wrote:

> Am Samstag, den 24.09.2016, 17:46 +0200 schrieb Christoph M. Becker:
>
>> On 24.09.2016 at 16:29, Torsten Rosenberger wrote:
>>
>>> PHP_FUNCTION(i2c_read_value)
>>> {
>>>     int arg_len;
>>>     unsigned char reg;
>>>     unsigned short res;
>>>
>>>     if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &reg,
>>> &arg_len) == FAILURE){
>>
>> That looks wrong.  `reg` should be declared as `char *`.
>
> i have seen “s”: string, expects char* and int.

Indeed[1].  But all output parameters of zend_parse_parameters() have to
passed as pointers (cf. `&arg_len`).
> 
> but reg should be int it is a hex number for the i2c bus.

Then you should parse for "l", and handle out-of-range values by
throwing an error.  Otherwise the API is pretty fragile at best; for
instance, calling i2c_read_value('') might result in arbitrary behavior.

>> There might be a permission or working directory issue.
> 
> you are right! apache2 was not able to access /dev/i2c-1 so I add the
> apache2 user to the i2c group but also had to change the acces mod to
> the file.
> 
> now it works
> Thanks's a lot!

Fine.  You're welcome.

[1] <http://php.net/manual/en/internals2.funcs.php>

-- 
Christoph M. Becker

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux