예제 #1
0
/*
 * save a corba object to a php object
 */
void orbit_save_data(zval * php_object, int type, void * data)
{
    pval * orbit_data_handle = NULL;
    long id = zend_list_insert(
                  data, 										/* data */
                  type								/* type */
              );


    /*
     * do it like they do in php_COM_call_function_handler
     * (insert into some magic hash index)
     */
    ALLOC_ZVAL(orbit_data_handle);	/* allocate memory for value */

    orbit_data_handle->type = IS_LONG;
    orbit_data_handle->value.lval = id;

    pval_copy_constructor(orbit_data_handle);	/* why? */

    INIT_PZVAL(orbit_data_handle);	/* set reference count */

    zend_hash_index_update(
        php_object->value.obj.properties, /* hashtable */
        0, 																/* hash??? */
        &orbit_data_handle,								/* data */
        sizeof(pval *),										/* data size */
        NULL															/* destination */
    );
}
예제 #2
0
파일: python.c 프로젝트: demos/Motif
/* {{{ convert_pyobject_to_zobject(PyObject *obj)
   Convert Python object to a PHP (Zend) object */
static zval *
convert_pyobject_to_zobject(PyObject *obj)
{
	pval *ret;
	zval *handle;
	TSRMLS_FETCH();

	/* Create a PHP Python object */
	MAKE_STD_ZVAL(ret);
	object_init_ex(ret, &python_class_entry);
	ret->is_ref = 1;
	ret->refcount = 1;

	/* Assign the current PyObject to the new PHP Python object */
	ALLOC_ZVAL(handle);
	Z_TYPE_P(handle) = IS_LONG;
	Z_LVAL_P(handle) = zend_list_insert(obj, le_pyobject);
	pval_copy_constructor(handle);
	INIT_PZVAL(handle);
	zend_hash_index_update(Z_OBJPROP_P(ret), 0, &handle, sizeof(pval *), NULL);

	return ret;
}
예제 #3
0
PHPAPI void php_variant_to_pval(VARIANT *var_arg, pval *pval_arg, int persistent, int codepage)
{

   switch(var_arg->vt & ~VT_BYREF)
   {
      case VT_EMPTY:
         var_uninit(pval_arg);
         break;

      case VT_UI1:
         if(var_arg->vt & VT_BYREF)
            pval_arg->value.lval = (long)*(var_arg->pbVal);
         else
            pval_arg->value.lval = (long) var_arg->bVal;

         pval_arg->type = IS_LONG;
         break;

      case VT_I2:
         if(var_arg->vt & VT_BYREF)
            pval_arg->value.lval = (long )*(var_arg->piVal);
         else
            pval_arg->value.lval = (long) var_arg->iVal;

         pval_arg->type = IS_LONG;
         break;

      case VT_I4:
         if(var_arg->vt & VT_BYREF)
            pval_arg->value.lval = *(var_arg->plVal);
         else
            pval_arg->value.lval = var_arg->lVal;

         pval_arg->type = IS_LONG;
         break;

      case VT_R4:
         if(var_arg->vt & VT_BYREF)
            pval_arg->value.dval = (double)*(var_arg->pfltVal);
         else
            pval_arg->value.dval = (double) var_arg->fltVal;

         pval_arg->type = IS_DOUBLE;
         break;

      case VT_R8:
         if(var_arg->vt & VT_BYREF)
            pval_arg->value.dval = *(var_arg->pdblVal);
         else
            pval_arg->value.dval = var_arg->dblVal;

         pval_arg->type = IS_DOUBLE;
         break;

      case VT_DECIMAL:
         {
            OLECHAR *unicode_str;
            switch(VarBstrFromDec(&var_arg->decVal, LOCALE_SYSTEM_DEFAULT, 0, &unicode_str))
            {
               case S_OK:
                  pval_arg->value.str.val = php_OLECHAR_to_char(unicode_str, &pval_arg->value.str.len, persistent, codepage);
                  pval_arg->type = IS_STRING;
                  break;

               default:
                  php_error(E_WARNING, "Error converting DECIMAL value to PHP floating point");
                  break;
            }
         }
         break;

      case VT_CY:
         if(var_arg->vt & VT_BYREF)
		    VarR8FromCy(var_arg->cyVal, &(pval_arg->value.dval));
         else
		    VarR8FromCy(*(var_arg->pcyVal), &(pval_arg->value.dval));

         pval_arg->type = IS_DOUBLE;
         break;

      case VT_BOOL:
         if (var_arg->vt & VT_BYREF)
            if (*(var_arg->pboolVal) & 0xFFFF)
               pval_arg->value.lval = 1;
            else
               pval_arg->value.lval = 0;
         else
            if (var_arg->boolVal & 0xFFFF)
               pval_arg->value.lval = 1;
            else
               pval_arg->value.lval = 0;

         pval_arg->type = IS_BOOL;
         break;

      case VT_NULL:
      case VT_VOID:
         pval_arg->type = IS_NULL;
         break;

      case VT_VARIANT:
         php_variant_to_pval(var_arg->pvarVal, pval_arg, persistent, codepage);
         break;

      case VT_BSTR:
         if (pval_arg->is_ref == 0  || (var_arg->vt & VT_BYREF) != VT_BYREF) {
            pval_arg->value.str.val = php_OLECHAR_to_char(var_arg->bstrVal, &pval_arg->value.str.len, persistent, codepage);
            SysFreeString(var_arg->bstrVal);
         } else {
            pval_arg->value.str.val = php_OLECHAR_to_char(*(var_arg->pbstrVal), &pval_arg->value.str.len, persistent, codepage);
            SysFreeString(*(var_arg->pbstrVal));
            efree(var_arg->pbstrVal);
         }

         pval_arg->type = IS_STRING;
         break;

      case VT_DATE: {
            SYSTEMTIME wintime;
            struct tm phptime;

            VariantTimeToSystemTime(var_arg->date, &wintime);

            phptime.tm_year  = wintime.wYear - 1900;
            phptime.tm_mon   = wintime.wMonth - 1;
            phptime.tm_mday  = wintime.wDay;
            phptime.tm_hour  = wintime.wHour;
            phptime.tm_min   = wintime.wMinute;
            phptime.tm_sec   = wintime.wSecond;
            phptime.tm_isdst = -1;

            tzset();
            pval_arg->value.lval = mktime(&phptime);
            pval_arg->type = IS_LONG;
         }
         break;
      case VT_DISPATCH: {
            pval *handle;
			i_dispatch *obj;

            pval_arg->type=IS_OBJECT;
            pval_arg->value.obj.ce = &com_class_entry;
            pval_arg->value.obj.properties = (HashTable *) emalloc(sizeof(HashTable));
            pval_arg->is_ref=1;
            pval_arg->refcount=1;
            zend_hash_init(pval_arg->value.obj.properties, 0, NULL, ZVAL_PTR_DTOR, 0);

            ALLOC_ZVAL(handle);
			obj = emalloc(sizeof(i_dispatch));
			php_COM_set(obj, var_arg->pdispVal, TRUE);

            handle->type = IS_LONG;
			handle->value.lval = zend_list_insert(obj, php_COM_get_le_idispatch());
            pval_copy_constructor(handle);
            INIT_PZVAL(handle);
            zend_hash_index_update(pval_arg->value.obj.properties, 0, &handle, sizeof(pval *), NULL);
         }
         break;
      case VT_UNKNOWN:
//wtf ??
		  var_arg->pdispVal->lpVtbl->Release(var_arg->pdispVal);
         /* break missing intentionally */

      case VT_I1:
         if(var_arg->vt & VT_BYREF)
            pval_arg->value.lval = (long)*(var_arg->pcVal);
         else
            pval_arg->value.lval = (long) var_arg->cVal;

         pval_arg->type = IS_LONG;
         break;

      case VT_UI2:
         if(var_arg->vt & VT_BYREF)
            pval_arg->value.lval = (long)*(var_arg->puiVal);
         else
            pval_arg->value.lval = (long) var_arg->uiVal;

         pval_arg->type = IS_LONG;
         break;

      case VT_UI4:
         if(var_arg->vt & VT_BYREF)
            pval_arg->value.lval = (long)*(var_arg->pulVal);
         else
            pval_arg->value.lval = (long) var_arg->ulVal;

         pval_arg->type = IS_LONG;
         break;

      case VT_INT:
         if(var_arg->vt & VT_BYREF)
            pval_arg->value.lval = (long)*(var_arg->pintVal);
         else
            pval_arg->value.lval = (long) var_arg->intVal;

         pval_arg->type = IS_LONG;
         break;

      case VT_UINT:
         if(var_arg->vt & VT_BYREF)
            pval_arg->value.lval = (long)*(var_arg->puintVal);
         else
            pval_arg->value.lval = (long) var_arg->uintVal;

         pval_arg->type = IS_LONG;
         break;

      default:
         php_error(E_WARNING,"Unsupported variant type: %d (0x%X)", var_arg->vt, var_arg->vt);
         var_reset(pval_arg);
         break;
   }
}