diff options
author | Mark Spruiell <mes@zeroc.com> | 2004-04-08 23:02:05 +0000 |
---|---|---|
committer | Mark Spruiell <mes@zeroc.com> | 2004-04-08 23:02:05 +0000 |
commit | 28aa0653a528f3d679fbd84e11bd41eb83d328a3 (patch) | |
tree | 039783db525a36815ad2786a226f8b176bca90d2 /php/src | |
parent | bug fix for unmarshaling objects without factory (diff) | |
download | ice-28aa0653a528f3d679fbd84e11bd41eb83d328a3.tar.bz2 ice-28aa0653a528f3d679fbd84e11bd41eb83d328a3.tar.xz ice-28aa0653a528f3d679fbd84e11bd41eb83d328a3.zip |
removing facets
Diffstat (limited to 'php/src')
-rw-r--r-- | php/src/ice/ice_proxy.h | 8 | ||||
-rw-r--r-- | php/src/ice/ice_util.h | 8 | ||||
-rw-r--r-- | php/src/ice/marshal.cpp | 28 | ||||
-rw-r--r-- | php/src/ice/php_ice.dsp | 2 | ||||
-rw-r--r-- | php/src/ice/profile.cpp | 2 | ||||
-rw-r--r-- | php/src/ice/proxy.cpp | 136 | ||||
-rw-r--r-- | php/src/ice/util.cpp | 129 |
7 files changed, 131 insertions, 182 deletions
diff --git a/php/src/ice/ice_proxy.h b/php/src/ice/ice_proxy.h index 8e2060d4047..3e1130df210 100644 --- a/php/src/ice/ice_proxy.h +++ b/php/src/ice/ice_proxy.h @@ -27,12 +27,12 @@ ZEND_FUNCTION(Ice_ObjectPrx_ice_isA); ZEND_FUNCTION(Ice_ObjectPrx_ice_ping); ZEND_FUNCTION(Ice_ObjectPrx_ice_id); ZEND_FUNCTION(Ice_ObjectPrx_ice_ids); -ZEND_FUNCTION(Ice_ObjectPrx_ice_facets); ZEND_FUNCTION(Ice_ObjectPrx_ice_getIdentity); ZEND_FUNCTION(Ice_ObjectPrx_ice_newIdentity); +ZEND_FUNCTION(Ice_ObjectPrx_ice_getContext); +ZEND_FUNCTION(Ice_ObjectPrx_ice_newContext); ZEND_FUNCTION(Ice_ObjectPrx_ice_getFacet); ZEND_FUNCTION(Ice_ObjectPrx_ice_newFacet); -ZEND_FUNCTION(Ice_ObjectPrx_ice_appendFacet); ZEND_FUNCTION(Ice_ObjectPrx_ice_twoway); ZEND_FUNCTION(Ice_ObjectPrx_ice_isTwoway); ZEND_FUNCTION(Ice_ObjectPrx_ice_oneway); @@ -57,12 +57,12 @@ ZEND_FUNCTION(Ice_ObjectPrx_ice_checkedCast); ZEND_FE(Ice_ObjectPrx_ice_ping, NULL) \ ZEND_FE(Ice_ObjectPrx_ice_id, NULL) \ ZEND_FE(Ice_ObjectPrx_ice_ids, NULL) \ - ZEND_FE(Ice_ObjectPrx_ice_facets, NULL) \ ZEND_FE(Ice_ObjectPrx_ice_getIdentity, NULL) \ ZEND_FE(Ice_ObjectPrx_ice_newIdentity, NULL) \ + ZEND_FE(Ice_ObjectPrx_ice_getContext, NULL) \ + ZEND_FE(Ice_ObjectPrx_ice_newContext, NULL) \ ZEND_FE(Ice_ObjectPrx_ice_getFacet, NULL) \ ZEND_FE(Ice_ObjectPrx_ice_newFacet, NULL) \ - ZEND_FE(Ice_ObjectPrx_ice_appendFacet, NULL) \ ZEND_FE(Ice_ObjectPrx_ice_twoway, NULL) \ ZEND_FE(Ice_ObjectPrx_ice_isTwoway, NULL) \ ZEND_FE(Ice_ObjectPrx_ice_oneway, NULL) \ diff --git a/php/src/ice/ice_util.h b/php/src/ice/ice_util.h index f06dd737f74..b80f34f6b6c 100644 --- a/php/src/ice/ice_util.h +++ b/php/src/ice/ice_util.h @@ -36,6 +36,9 @@ namespace IcePHP bool createIdentity(zval*, const Ice::Identity& TSRMLS_DC); bool extractIdentity(zval*, Ice::Identity& TSRMLS_DC); +bool createContext(zval*, const Ice::Context& TSRMLS_DC); +bool extractContext(zval*, Ice::Context& TSRMLS_DC); + // // PHP wrapper for C++ objects. // @@ -105,11 +108,6 @@ std::string zendTypeToString(int); bool isNativeKey(const Slice::TypePtr&); // -// Extracts a context (i.e., dictionary<string, string>) from the given zval. -// -bool getContext(zval*, Ice::Context& TSRMLS_DC); - -// // Determines whether a class (or interface) inherits from a base class (or interface). // bool checkClass(zend_class_entry*, zend_class_entry*); diff --git a/php/src/ice/marshal.cpp b/php/src/ice/marshal.cpp index 0e4f8af1b11..2987b1423f7 100644 --- a/php/src/ice/marshal.cpp +++ b/php/src/ice/marshal.cpp @@ -210,9 +210,6 @@ public: virtual bool unmarshal(zval*, IceInternal::BasicStream& TSRMLS_DC); virtual void destroy(); - -private: - MarshalerPtr _facetMapMarshaler; }; class ObjectSliceMarshaler : public Marshaler @@ -1286,15 +1283,6 @@ IcePHP::ExceptionMarshaler::destroy() // IcePHP::IceObjectSliceMarshaler::IceObjectSliceMarshaler(TSRMLS_D) { - // - // Create a marshaler for the ice_facets member. - // - Profile* profile = static_cast<Profile*>(ICE_G(profile)); - assert(profile); - Slice::TypePtr keyType = profile->unit->builtin(Slice::Builtin::KindString); - Slice::TypePtr valueType = profile->unit->builtin(Slice::Builtin::KindObject); - MarshalerPtr dict = new NativeDictionaryMarshaler(keyType, valueType TSRMLS_CC); - _facetMapMarshaler = new MemberMarshaler("ice_facets", dict); } bool @@ -1304,10 +1292,7 @@ IcePHP::IceObjectSliceMarshaler::marshal(zval* zv, IceInternal::BasicStream& os os.writeTypeId(Ice::Object::ice_staticId()); os.startWriteSlice(); - if(!_facetMapMarshaler->marshal(zv, os TSRMLS_CC)) - { - return false; - } + os.writeSize(0); // For compatibility with the old AFM. os.endWriteSlice(); return true; @@ -1324,10 +1309,15 @@ IcePHP::IceObjectSliceMarshaler::unmarshal(zval* zv, IceInternal::BasicStream& i //is.readTypeId() is.startReadSlice(); - if(!_facetMapMarshaler->unmarshal(zv, is TSRMLS_CC)) + + // For compatibility with the old AFM. + Ice::Int sz; + is.readSize(sz); + if(sz != 0) { - return false; + throw Ice::MarshalException(__FILE__, __LINE__); } + is.endReadSlice(); return true; @@ -1336,8 +1326,6 @@ IcePHP::IceObjectSliceMarshaler::unmarshal(zval* zv, IceInternal::BasicStream& i void IcePHP::IceObjectSliceMarshaler::destroy() { - _facetMapMarshaler->destroy(); - _facetMapMarshaler = 0; } // diff --git a/php/src/ice/php_ice.dsp b/php/src/ice/php_ice.dsp index 00849fb9ab5..37d85f9bd98 100644 --- a/php/src/ice/php_ice.dsp +++ b/php/src/ice/php_ice.dsp @@ -87,7 +87,7 @@ BSC32=bscmake.exe # ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386
-# ADD LINK32 Iced.lib Sliced.lib IceUtild.lib php5ts.lib /nologo /dll /debug /machine:I386
+# ADD LINK32 Iced.lib Sliced.lib IceUtild.lib php5ts_debug.lib /nologo /dll /debug /machine:I386
# SUBTRACT LINK32 /pdb:none
# Begin Special Build Tool
OutDir=.\Debug
diff --git a/php/src/ice/profile.cpp b/php/src/ice/profile.cpp index 4dac82b28f4..08168dc4323 100644 --- a/php/src/ice/profile.cpp +++ b/php/src/ice/profile.cpp @@ -236,8 +236,6 @@ static const char* _coreTypes = " function ice_postUnmarshal()\n" " {\n" " }\n" - "\n" - " var $ice_facets = array();\n" "}\n" "\n" "interface Ice_ObjectFactory extends Ice_LocalObject\n" diff --git a/php/src/ice/proxy.cpp b/php/src/ice/proxy.cpp index 416febee961..c48ddf9aee4 100644 --- a/php/src/ice/proxy.cpp +++ b/php/src/ice/proxy.cpp @@ -149,12 +149,12 @@ static function_entry _methods[] = {"ice_ping", PHP_FN(Ice_ObjectPrx_ice_ping), NULL}, {"ice_id", PHP_FN(Ice_ObjectPrx_ice_id), NULL}, {"ice_ids", PHP_FN(Ice_ObjectPrx_ice_ids), NULL}, - {"ice_facets", PHP_FN(Ice_ObjectPrx_ice_facets), NULL}, {"ice_getIdentity", PHP_FN(Ice_ObjectPrx_ice_getIdentity), NULL}, {"ice_newIdentity", PHP_FN(Ice_ObjectPrx_ice_newIdentity), NULL}, + {"ice_getContext", PHP_FN(Ice_ObjectPrx_ice_getContext), NULL}, + {"ice_newContext", PHP_FN(Ice_ObjectPrx_ice_newContext), NULL}, {"ice_getFacet", PHP_FN(Ice_ObjectPrx_ice_getFacet), NULL}, {"ice_newFacet", PHP_FN(Ice_ObjectPrx_ice_newFacet), NULL}, - {"ice_appendFacet", PHP_FN(Ice_ObjectPrx_ice_appendFacet), NULL}, {"ice_twoway", PHP_FN(Ice_ObjectPrx_ice_twoway), NULL}, {"ice_isTwoway", PHP_FN(Ice_ObjectPrx_ice_isTwoway), NULL}, {"ice_oneway", PHP_FN(Ice_ObjectPrx_ice_oneway), NULL}, @@ -264,7 +264,7 @@ ZEND_FUNCTION(Ice_ObjectPrx_ice_isA) // Populate the context (if necessary). // Ice::Context ctx; - if(arr && !getContext(arr, ctx TSRMLS_CC)) + if(arr && !extractContext(arr, ctx TSRMLS_CC)) { RETURN_FALSE; } @@ -309,7 +309,7 @@ ZEND_FUNCTION(Ice_ObjectPrx_ice_ping) // Populate the context (if necessary). // Ice::Context ctx; - if(arr && !getContext(arr, ctx TSRMLS_CC)) + if(arr && !extractContext(arr, ctx TSRMLS_CC)) { RETURN_NULL(); } @@ -348,7 +348,7 @@ ZEND_FUNCTION(Ice_ObjectPrx_ice_id) // Populate the context (if necessary). // Ice::Context ctx; - if(arr && !getContext(arr, ctx TSRMLS_CC)) + if(arr && !extractContext(arr, ctx TSRMLS_CC)) { RETURN_NULL(); } @@ -387,7 +387,7 @@ ZEND_FUNCTION(Ice_ObjectPrx_ice_ids) // Populate the context (if necessary). // Ice::Context ctx; - if(arr && !getContext(arr, ctx TSRMLS_CC)) + if(arr && !extractContext(arr, ctx TSRMLS_CC)) { RETURN_NULL(); } @@ -413,50 +413,6 @@ ZEND_FUNCTION(Ice_ObjectPrx_ice_ids) } } -ZEND_FUNCTION(Ice_ObjectPrx_ice_facets) -{ - if(ZEND_NUM_ARGS() > 1) - { - WRONG_PARAM_COUNT; - } - - zval* arr = NULL; - - if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|a", &arr) == FAILURE) - { - RETURN_NULL(); - } - - // - // Populate the context (if necessary). - // - Ice::Context ctx; - if(arr && !getContext(arr, ctx TSRMLS_CC)) - { - RETURN_NULL(); - } - - ice_object* obj = static_cast<ice_object*>(zend_object_store_get_object(getThis() TSRMLS_CC)); - assert(obj->ptr); - Proxy* _this = static_cast<Proxy*>(obj->ptr); - - try - { - Ice::FacetPath facets = _this->getProxy()->ice_facets(ctx); - array_init(return_value); - uint idx = 0; - for(vector<string>::const_iterator p = facets.begin(); p != facets.end(); ++p, ++idx) - { - add_index_stringl(return_value, idx, const_cast<char*>((*p).c_str()), (*p).length(), 1); - } - } - catch(const IceUtil::Exception& ex) - { - throwException(ex TSRMLS_CC); - RETURN_NULL(); - } -} - ZEND_FUNCTION(Ice_ObjectPrx_ice_getIdentity) { if(ZEND_NUM_ARGS() != 0) @@ -511,7 +467,7 @@ ZEND_FUNCTION(Ice_ObjectPrx_ice_newIdentity) } } -ZEND_FUNCTION(Ice_ObjectPrx_ice_getFacet) +ZEND_FUNCTION(Ice_ObjectPrx_ice_getContext) { if(ZEND_NUM_ARGS() != 0) { @@ -522,51 +478,30 @@ ZEND_FUNCTION(Ice_ObjectPrx_ice_getFacet) assert(obj->ptr); Proxy* _this = static_cast<Proxy*>(obj->ptr); - try - { - Ice::FacetPath facet = _this->getProxy()->ice_getFacet(); - array_init(return_value); - uint idx = 0; - for(vector<string>::const_iterator p = facet.begin(); p != facet.end(); ++p, ++idx) - { - add_index_stringl(return_value, idx, const_cast<char*>((*p).c_str()), (*p).length(), 1); - } - } - catch(const IceUtil::Exception& ex) - { - throwException(ex TSRMLS_CC); - RETURN_NULL(); - } + createContext(return_value, _this->getProxy()->ice_getContext() TSRMLS_CC); } -ZEND_FUNCTION(Ice_ObjectPrx_ice_newFacet) +ZEND_FUNCTION(Ice_ObjectPrx_ice_newContext) { if(ZEND_NUM_ARGS() != 1) { WRONG_PARAM_COUNT; } - zval* zarr; - if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a", &zarr) == FAILURE) + zval* arr = NULL; + + if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a", &arr) == FAILURE) { RETURN_NULL(); } - Ice::FacetPath facet; - HashTable* arr = Z_ARRVAL_P(zarr); - HashPosition pos; - zval** val; - - zend_hash_internal_pointer_reset_ex(arr, &pos); - while(zend_hash_get_current_data_ex(arr, (void**)&val, &pos) != FAILURE) + // + // Populate the context. + // + Ice::Context ctx; + if(arr && !extractContext(arr, ctx TSRMLS_CC)) { - if(Z_TYPE_PP(val) != IS_STRING) - { - zend_error(E_ERROR, "%s(): facet must be a string array", get_active_function_name(TSRMLS_C)); - RETURN_NULL(); - } - facet.push_back(string(Z_STRVAL_PP(val), Z_STRLEN_PP(val))); - zend_hash_move_forward_ex(arr, &pos); + RETURN_NULL(); } ice_object* obj = static_cast<ice_object*>(zend_object_store_get_object(getThis() TSRMLS_CC)); @@ -575,7 +510,7 @@ ZEND_FUNCTION(Ice_ObjectPrx_ice_newFacet) try { - Ice::ObjectPrx prx = _this->getProxy()->ice_newFacet(facet); + Ice::ObjectPrx prx = _this->getProxy()->ice_newContext(ctx); if(!createProxy(return_value, prx TSRMLS_CC)) { RETURN_NULL(); @@ -588,7 +523,30 @@ ZEND_FUNCTION(Ice_ObjectPrx_ice_newFacet) } } -ZEND_FUNCTION(Ice_ObjectPrx_ice_appendFacet) +ZEND_FUNCTION(Ice_ObjectPrx_ice_getFacet) +{ + if(ZEND_NUM_ARGS() != 0) + { + WRONG_PARAM_COUNT; + } + + ice_object* obj = static_cast<ice_object*>(zend_object_store_get_object(getThis() TSRMLS_CC)); + assert(obj->ptr); + Proxy* _this = static_cast<Proxy*>(obj->ptr); + + try + { + string facet = _this->getProxy()->ice_getFacet(); + ZVAL_STRINGL(return_value, const_cast<char*>(facet.c_str()), facet.length(), 1); + } + catch(const IceUtil::Exception& ex) + { + throwException(ex TSRMLS_CC); + RETURN_NULL(); + } +} + +ZEND_FUNCTION(Ice_ObjectPrx_ice_newFacet) { if(ZEND_NUM_ARGS() != 1) { @@ -609,9 +567,7 @@ ZEND_FUNCTION(Ice_ObjectPrx_ice_appendFacet) try { - Ice::FacetPath facet; - - Ice::ObjectPrx prx = _this->getProxy()->ice_appendFacet(name); + Ice::ObjectPrx prx = _this->getProxy()->ice_newFacet(name); if(!createProxy(return_value, prx TSRMLS_CC)) { RETURN_NULL(); @@ -1082,7 +1038,7 @@ do_cast(INTERNAL_FUNCTION_PARAMETERS, bool check) Ice::ObjectPrx prx = _this->getProxy(); if(facet) { - prx = prx->ice_appendFacet(facet); + prx = prx->ice_newFacet(facet); } if(check) @@ -1264,7 +1220,7 @@ IcePHP::Operation::invoke(INTERNAL_FUNCTION_PARAMETERS) // Populate the context (if necessary). // Ice::Context ctx; - if(ZEND_NUM_ARGS() == numParams + 1 && !getContext(*args[numParams], ctx TSRMLS_CC)) + if(ZEND_NUM_ARGS() == numParams + 1 && !extractContext(*args[numParams], ctx TSRMLS_CC)) { return; } diff --git a/php/src/ice/util.cpp b/php/src/ice/util.cpp index eee5b1905d9..79bc7e449fd 100644 --- a/php/src/ice/util.cpp +++ b/php/src/ice/util.cpp @@ -210,6 +210,74 @@ IcePHP::extractIdentity(zval* zv, Ice::Identity& id TSRMLS_DC) return true; } +bool +IcePHP::createContext(zval* zv, const Ice::Context& ctx TSRMLS_DC) +{ + zend_class_entry* cls = findClass("Ice_Identity" TSRMLS_CC); + assert(cls); + + array_init(zv); + for(Ice::Context::const_iterator p = ctx.begin(); p != ctx.end(); ++p) + { + zval* val; + MAKE_STD_ZVAL(val); + ZVAL_STRINGL(val, const_cast<char*>(p->second.c_str()), p->second.length(), 1); + add_assoc_zval_ex(zv, const_cast<char*>(p->first.c_str()), p->first.length() + 1, val); + } + + return true; +} + +bool +IcePHP::extractContext(zval* zv, Ice::Context& ctx TSRMLS_DC) +{ + if(Z_TYPE_P(zv) != IS_ARRAY) + { + string s = zendTypeToString(Z_TYPE_P(zv)); + zend_error(E_ERROR, "%s(): expected an array for the context argument but received %s", + get_active_function_name(TSRMLS_C), s.c_str()); + return false; + } + + HashTable* arr = Z_ARRVAL_P(zv); + HashPosition pos; + zval** val; + + zend_hash_internal_pointer_reset_ex(arr, &pos); + while(zend_hash_get_current_data_ex(arr, (void**)&val, &pos) != FAILURE) + { + // + // Get the key (which can be a long or a string). + // + char* keyStr; + uint keyLen; + ulong keyNum; + int keyType = zend_hash_get_current_key_ex(arr, &keyStr, &keyLen, &keyNum, 0, &pos); + + // + // Store the key in a zval, so that we can reuse the PrimitiveMarshaler logic. + // + if(keyType != HASH_KEY_IS_STRING) + { + zend_error(E_ERROR, "%s(): context key must be a string", get_active_function_name(TSRMLS_C)); + return false; + } + + zend_hash_get_current_data_ex(arr, (void**)&val, &pos); + if(Z_TYPE_PP(val) != IS_STRING) + { + zend_error(E_ERROR, "%s(): context value must be a string", get_active_function_name(TSRMLS_C)); + return false; + } + + ctx[keyStr] = Z_STRVAL_PP(val); + + zend_hash_move_forward_ex(arr, &pos); + } + + return true; +} + #ifdef WIN32 extern "C" #endif @@ -328,16 +396,7 @@ IcePHP::throwException(const IceUtil::Exception& ex TSRMLS_DC) // zval* facet; MAKE_STD_ZVAL(facet); - array_init(facet); - Ice::Int i = 0; - for(Ice::FacetPath::const_iterator p = e.facet.begin(); p != e.facet.end(); ++p, ++i) - { - string f = *p; - zval* val; - MAKE_STD_ZVAL(val); - ZVAL_STRINGL(val, const_cast<char*>(f.c_str()), f.length(), 1); - add_index_zval(facet, i, val); - } + ZVAL_STRINGL(facet, const_cast<char*>(e.facet.c_str()), e.facet.length(), 1); zend_update_property(cls, zex, "facet", sizeof("facet") - 1, facet TSRMLS_CC); // @@ -620,56 +679,6 @@ IcePHP::isNativeKey(const Slice::TypePtr& type) } bool -IcePHP::getContext(zval* zv, Ice::Context& ctx TSRMLS_DC) -{ - if(Z_TYPE_P(zv) != IS_ARRAY) - { - string s = zendTypeToString(Z_TYPE_P(zv)); - zend_error(E_ERROR, "%s(): expected an array for the context argument but received %s", - get_active_function_name(TSRMLS_C), s.c_str()); - return false; - } - - HashTable* arr = Z_ARRVAL_P(zv); - HashPosition pos; - zval** val; - - zend_hash_internal_pointer_reset_ex(arr, &pos); - while(zend_hash_get_current_data_ex(arr, (void**)&val, &pos) != FAILURE) - { - // - // Get the key (which can be a long or a string). - // - char* keyStr; - uint keyLen; - ulong keyNum; - int keyType = zend_hash_get_current_key_ex(arr, &keyStr, &keyLen, &keyNum, 0, &pos); - - // - // Store the key in a zval, so that we can reuse the PrimitiveMarshaler logic. - // - if(keyType != HASH_KEY_IS_STRING) - { - zend_error(E_ERROR, "%s(): context key must be a string", get_active_function_name(TSRMLS_C)); - return false; - } - - zend_hash_get_current_data_ex(arr, (void**)&val, &pos); - if(Z_TYPE_PP(val) != IS_STRING) - { - zend_error(E_ERROR, "%s(): context value must be a string", get_active_function_name(TSRMLS_C)); - return false; - } - - ctx[keyStr] = Z_STRVAL_PP(val); - - zend_hash_move_forward_ex(arr, &pos); - } - - return true; -} - -bool IcePHP::checkClass(zend_class_entry* ce, zend_class_entry* base) { while(ce != NULL) |