Re: [PHP] php extension about php_stream_fopen_tmpfile()

2013-05-16 Thread Matijn Woudt
On Fri, May 10, 2013 at 3:37 AM, Bleakwind bleakw...@gmail.com wrote:

 I write a php extension.
 How can I user Zend API do that?
 where can I find some doc about file_handle-handle ?



There's not really a place to ask questions for writing extensions, but
most people here will not be able to answer your question, because they
only write PHP code.
The documentation for the Zend API is freely available from their website.
If it is not there, have a look at the source code, the best documentation
around for any product.
If you still have problems with an extension, the best place to ask would
be the PHP internals list, where the PHP devs hang around, but it does
probably require more understanding from your side first.




 ZEND_API zend_op_array *(*org_compile_file)(zend_file_handle *file_handle,
 int type TSRMLS_DC);
 ZEND_API zend_op_array *sead_compile_file(zend_file_handle *file_handle,
 int type TSRMLS_DC)
 {
 php_stream *stream;
 char *data_decode;
 int data_decode_len;


Neither php_stream_write nor fwrite use the int type, use size_t instead.



 /* ... */

 /* Zend API Begin: This unsuccessful */
 php_stream *tmpstream;
 if ((tmpstream = php_stream_fopen_tmpfile()) == NULL) {
 php_error_docref(NULL TSRMLS_CC, E_WARNING, Unable to create
 temporary file.  Check permissions in temporary files directory.);
 php_stream_close(stream);
 return org_compile_file(file_handle, type TSRMLS_CC);
 }
 numbytes = php_stream_write(tmpstream, data_decode, data_decode_len);
 if (numbytes != data_decode_len) {
 php_error_docref(NULL TSRMLS_CC, E_WARNING, Only %d of %d bytes
 written, possibly out of free disk space, numbytes, data_decode_len);
 numbytes = -1;
 }
 php_stream_rewind(tmpstream);
 /* Zend API End */

 /* C Begin: This is OK */
 FILE *tmpstream;
 tmpstream = tmpfile();
 fwrite(data_decode, data_decode_len, 1, tmpstream);
 rewind(tmpstream);
 /* C End */


So what happens? You haven't shown us any error, crash, etc?

- Matijn


[PHP] php extension about php_stream_fopen_tmpfile()

2013-05-09 Thread Bleakwind
I write a php extension.
How can I user Zend API do that?
where can I find some doc about file_handle-handle ?

ZEND_API zend_op_array *(*org_compile_file)(zend_file_handle *file_handle,
int type TSRMLS_DC);
ZEND_API zend_op_array *sead_compile_file(zend_file_handle *file_handle,
int type TSRMLS_DC)
{
php_stream *stream;
char *data_decode;
int data_decode_len;

/* ... */

/* Zend API Begin: This unsuccessful */
php_stream *tmpstream;
if ((tmpstream = php_stream_fopen_tmpfile()) == NULL) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, Unable to create
temporary file.  Check permissions in temporary files directory.);
php_stream_close(stream);
return org_compile_file(file_handle, type TSRMLS_CC);
}
numbytes = php_stream_write(tmpstream, data_decode, data_decode_len);
if (numbytes != data_decode_len) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, Only %d of %d bytes
written, possibly out of free disk space, numbytes, data_decode_len);
numbytes = -1;
}
php_stream_rewind(tmpstream);
/* Zend API End */

/* C Begin: This is OK */
FILE *tmpstream;
tmpstream = tmpfile();
fwrite(data_decode, data_decode_len, 1, tmpstream);
rewind(tmpstream);
/* C End */

file_handle-handle.fp = tmpstream;
file_handle-type = ZEND_HANDLE_FP;
file_handle-opened_path = expand_filepath(file_handle-filename, NULL
TSRMLS_CC);

return org_compile_file(file_handle, type TSRMLS_CC);
}