# API issues or me?

- Thread: https://externals.io/message/21842
- Original archive: https://news-web.php.net/php.internals/21842
- Started by D. Walsh on 2006-02-11T12:24:04+00:00
- Messages: 6
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #21842 — D. Walsh — 2006-02-11T12:24:04+00:00

URL: https://externals.io/message/21842#21842

I've been coding modules using the current available API and I've  
recently tried compiling PHP-5.1.2 for Apache 2.0 and I'm not  
obtaining the expected results when a function that should return an  
array but doesn't.

Compiling PHP 5.1.2 (or any previous version) for Apache 1.3.x the  
module works properly and the issue only occurs when compiling for 2.0.

I'm not sure if there are API changes that are not in the current  
documentation so if someone could examine the following code and sees  
something obvious I'd appreciate it if you'd point it out.

-- Dale



PHP_FUNCTION(ram_disk_file_load)
{
	pval *file, *args, *p_argc;
	pval *entry;
	zval *p_prcalc;
	HashTable *args_arr;
	int i, xsize, ysize, argc;
	double ymin,ymax;
	char **argv, **prcalc;

	/*
	 * xsize is the number of bytes per sector
	 * ysize is the number of bytes (in kb) for the ramdisk.
	 * argv[0] is the command to perform.
	 * argv[1] is either 'disk' mode or 'raw' mode
	 * argv[2] contains the file with the disk images contents to load  
into it
	 */

	if ( disk_test_error() )
		disk_clear_error();

	if ( (ZEND_NUM_ARGS() >= 3 && ZEND_NUM_ARGS() <= 6) &&  
zend_get_parameters(ht, 3, &file, &args, &p_argc) == SUCCESS)
	{
		if ( args->type != IS_ARRAY )
		{
			php_error(E_WARNING, "2nd Variable passed to disk_config is not an  
array!\n");
			RETURN_FALSE;
		}

		convert_to_long(p_argc);
		convert_to_string(file);

		convert_to_array(args);
		args_arr = args->value.ht;

		// here we want to raw copy our saved content file to the new ram disk
		argc = p_argc->value.lval + 3;
		argv = (char **) emalloc(argc * sizeof(char *));
		argv[0] = "init";
		argv[1] = estrdup("raw");
		argv[2] = estrdup(file->value.str.val);

		for (i = 3; i < argc; i++)
		{
			pval **dataptr;

			if ( zend_hash_get_current_data(args_arr, (void *) &dataptr) ==  
FAILURE )
				continue;

			entry = *dataptr;

			if ( entry->type != IS_STRING )
				convert_to_string(entry);

			argv[i] = estrdup(entry->value.str.val);

			if ( i < argc )
				zend_hash_move_forward(args_arr);
		}

		optind = 0; opterr = 0;
		if (size _config(argc-1, &argv[1], &prcalc, &xsize, &ysize) != -1 )
		{
			array_init(return_value);
			add_assoc_long(return_value, "xsize", xsize);
			add_assoc_long(return_value, "ysize", ysize);

			MAKE_STD_ZVAL(p_prcalc);
			array_init(p_prcalc);

			if (prcalc)
			{
				for (i = 0; prcalc[i]; i++)
				{
					add_next_index_string(p_prcalc, prcalc[i], 1);
					free(prcalc[i]);
				}
				free(prcalc);
			}
			zend_hash_update(return_value->value.ht, "prcalc", sizeof("prcalc"),
							(void *)&p_prcalc, sizeof(zval *), NULL);
		}
		else
		{
			RETVAL_FALSE; // PROBLEM - FAILED TO PERFORM THE TASK
		}
		for (i = 1; i < argc; i++)
			efree(argv[i]);

		efree(argv);
	}
	else
	{
		WRONG_PARAM_COUNT;
	}
	return;
}

---

## #21843 — Marcus Boerger — 2006-02-11T12:33:39+00:00

URL: https://externals.io/message/21842#21843 · In reply to: #21842

Hello D.,

  you are using the old parameter parsing api which is deprecated for
very long now. Maybe changing to the new one will fix your problems or
find you more help.

marcus

Saturday, February 11, 2006, 1:24:04 PM, you wrote:

> I've been coding modules using the current available API and I've  
> recently tried compiling PHP-5.1.2 for Apache 2.0 and I'm not  
> obtaining the expected results when a function that should return an  
> array but doesn't.

> Compiling PHP 5.1.2 (or any previous version) for Apache 1.3.x the  
> module works properly and the issue only occurs when compiling for 2.0.

> I'm not sure if there are API changes that are not in the current  
> documentation so if someone could examine the following code and sees  
> something obvious I'd appreciate it if you'd point it out.

> -- Dale



> PHP_FUNCTION(ram_disk_file_load)
> {
>         pval *file, *args, *p_argc;
>         pval *entry;
>         zval *p_prcalc;
>         HashTable *args_arr;
>         int i, xsize, ysize, argc;
>         double ymin,ymax;
>         char **argv, **prcalc;

>         /*
>          * xsize is the number of bytes per sector
>          * ysize is the number of bytes (in kb) for the ramdisk.
>          * argv[0] is the command to perform.
>          * argv[1] is either 'disk' mode or 'raw' mode
>          * argv[2] contains the file with the disk images contents to load  
> into it
>          */

>         if ( disk_test_error() )
>                 disk_clear_error();

>         if ( (ZEND_NUM_ARGS() >= 3 && ZEND_NUM_ARGS() <= 6) &&  
> zend_get_parameters(ht, 3, &file, &args, &p_argc) == SUCCESS)
>         {
>                 if ( args->type != IS_ARRAY )
>                 {
>                         php_error(E_WARNING, "2nd Variable passed to disk_config is not an
> array!\n");
>                         RETURN_FALSE;
>                 }

>                 convert_to_long(p_argc);
>                 convert_to_string(file);

>                 convert_to_array(args);
>                 args_arr = args->value.ht;

>                 // here we want to raw copy our saved content file to the new ram disk
>                 argc = p_argc->value.lval + 3;
>                 argv = (char **) emalloc(argc * sizeof(char *));
>                 argv[0] = "init";
>                 argv[1] = estrdup("raw");
>                 argv[2] = estrdup(file->value.str.val);

>                 for (i = 3; i < argc; i++)
>                 {
>                         pval **dataptr;

>                         if ( zend_hash_get_current_data(args_arr, (void *) &dataptr) ==
> FAILURE )
>                                 continue;

>                         entry = *dataptr;

>                         if ( entry->type != IS_STRING )
>                                 convert_to_string(entry);

>                         argv[i] = estrdup(entry->value.str.val);

>                         if ( i < argc )
>                                 zend_hash_move_forward(args_arr);
>                 }

>                 optind = 0; opterr = 0;
>                 if (size _config(argc-1, &argv[1], &prcalc, &xsize, &ysize) != -1 )
>                 {
>                         array_init(return_value);
>                         add_assoc_long(return_value, "xsize", xsize);
>                         add_assoc_long(return_value, "ysize", ysize);

>                         MAKE_STD_ZVAL(p_prcalc);
>                         array_init(p_prcalc);

>                         if (prcalc)
>                         {
>                                 for (i = 0; prcalc[i]; i++)
>                                 {
>                                         add_next_index_string(p_prcalc, prcalc[i], 1);
>                                         free(prcalc[i]);
>                                 }
>                                 free(prcalc);
>                         }
>                         zend_hash_update(return_value->value.ht, "prcalc", sizeof("prcalc"),
>                                                         (void *)&p_prcalc, sizeof(zval *), NULL);
>                 }
>                 else
>                 {
>                         RETVAL_FALSE; // PROBLEM - FAILED TO PERFORM THE TASK
>                 }
>                 for (i = 1; i < argc; i++)
>                         efree(argv[i]);

>                 efree(argv);
>         }
>         else
>         {
>                 WRONG_PARAM_COUNT;
>         }
>         return;
> }




Best regards,
 Marcus

---

## #21845 — D. Walsh — 2006-02-11T16:32:33+00:00

URL: https://externals.io/message/21842#21845 · In reply to: #21843

> Hello D.,
>
>   you are using the old parameter parsing api which is deprecated for
> very long now. Maybe changing to the new one will fix your problems or
> find you more help.

I'm using the documentation that Wez directed me too about 8 months  
ago, where's the newer?

> marcus
>
> Saturday, February 11, 2006, 1:24:04 PM, you wrote:
>
> > […]
>
> > […]
>
> > […]
>
> > […]
>
>
>
> > […]
>
> > […]
>
> > […]
>
> > […]
>
> > […]
>
> > […]
>
> > […]
>
> > […]
>
> > […]
>
> > […]
>
> > […]
>
> > […]
>
> > […]
>
> > […]
>
> > […]
>
> > […]
>
> > […]
>
>
>
>
> Best regards,
>  Marcus

-- Dale

---

## #21846 — Marcus Boerger — 2006-02-11T16:49:40+00:00

URL: https://externals.io/message/21842#21846 · In reply to: #21845

Hello D.,

  for example look here: http://talks.somabo.de

Saturday, February 11, 2006, 5:32:33 PM, you wrote:

> 

> > […]

> I'm using the documentation that Wez directed me too about 8 months  
> ago, where's the newer?

> > […]

> -- Dale




Best regards,
 Marcus

---

## #21847 — D.Walsh — 2006-02-11T17:23:50+00:00

URL: https://externals.io/message/21842#21847 · In reply to: #21846

> Hello D.,
>
>   for example look here: http://talks.somabo.de

I take it there's no new official API docs from PHP themselves?

No, problem, thanks for the link Marcus, I guess any doc is better  
than none at all.

> Saturday, February 11, 2006, 5:32:33 PM, you wrote:
>
> > […]
>
> > […]
>
> > […]
>
> > […]
>
> > […]
>
>
>
>
> Best regards,
>  Marcus

---

## #21849 — Nuno Lopes — 2006-02-11T19:44:25+00:00

URL: https://externals.io/message/21842#21849 · In reply to: #21847

> > […]
> 
> I take it there's no new official API docs from PHP themselves?

There is a "somewhat official" documentation in phpdoc:
http://php.net/manual/en/zend-api.zend-parse-parameters.php
http://php.net/manual/en/zend.arguments.php


Nuno
