diff options
author | Emiel Bruijntjes <emiel.bruijntjes@copernica.com> | 2014-03-04 08:41:57 +0100 |
---|---|---|
committer | Emiel Bruijntjes <emiel.bruijntjes@copernica.com> | 2014-03-04 08:41:57 +0100 |
commit | ecc297108d2851af885c1fb28434769f9478649d (patch) | |
tree | b7a0ad547ab5a1a9bc5394683a455cde31bcf0b3 /src | |
parent | 70986b4bcdf7793c4bb8a4e14d91e6531c95f651 (diff) |
all Value::call() and Value::exec() method no longer accept a std::string, but a const char* instead, because in the real world they are most likely called with hard coded strings
Diffstat (limited to 'src')
-rw-r--r-- | src/object.cpp | 32 | ||||
-rw-r--r-- | src/value.cpp | 26 |
2 files changed, 24 insertions, 34 deletions
diff --git a/src/object.cpp b/src/object.cpp index 99de4a0..aa99c0d 100644 --- a/src/object.cpp +++ b/src/object.cpp @@ -12,37 +12,27 @@ namespace Php { /** - * Constructor + * Internal method to instantiate an object * @param name */ -Object::Object(const char *name) +void Object::instantiate(const char *name) { - // step 1: convert the name into a class_entry + // convert the name into a class_entry auto *entry = zend_fetch_class(name, strlen(name), 0); - if (!entry) throw Php::Exception("Unknown class name"); + if (!entry) throw Php::Exception(std::string("Unknown class name ") + name); // initiate the zval (which was already allocated in the base constructor) object_init_ex(_val, entry); -// // is there a special function to create the object? -// if (entry->create_object) -// { -// // create the object -// zend_object_value value = entry->create_object(entry); -// -// // wrap this in the zval (which was already allocated in the base constructor) -// Z_TYPE_P(_val) = IS_OBJECT; -// Z_OBJVAL_P(_val) = value; -// } -// else -// { -// } + // @todo should we call methods like allocating hashtables, copying and + // initializing properties, et cetera????? In all example you always + // see such complicated and next-to-impossible-to-understand + // sequences of functions being called, but this object_init_ex + // also seems to work... - // @todo should we call methods like allocating hashtables, copyint and - // initializing properties, et cetera????? + // @todo is this a memory leak? the base class first initializes a stdClass, + // and then we overwrite it with a specific class - // call the constructor - call("__construct"); } /** diff --git a/src/value.cpp b/src/value.cpp index ab4c350..8047dee 100644 --- a/src/value.cpp +++ b/src/value.cpp @@ -895,7 +895,7 @@ Value Value::operator()(Value p0, Value p1, Value p2, Value p3, Value p4, Value * @param name name of the method to call * @return Value */ -Value Value::call(const std::string &name) +Value Value::call(const char *name) { // call with zero parameters return exec(name, 0, NULL); @@ -907,7 +907,7 @@ Value Value::call(const std::string &name) * @param p0 The first parameter * @return Value */ -Value Value::call(const std::string &name, Value p0) +Value Value::call(const char *name, Value p0) { // array of parameters zval **params[] = { &p0._val }; @@ -923,7 +923,7 @@ Value Value::call(const std::string &name, Value p0) * @param p1 The second parameter * @return Value */ -Value Value::call(const std::string &name, Value p0, Value p1) +Value Value::call(const char *name, Value p0, Value p1) { // array of parameters zval **params[] = { &p0._val, &p1._val }; @@ -940,7 +940,7 @@ Value Value::call(const std::string &name, Value p0, Value p1) * @param p2 The third parameter * @return Value */ -Value Value::call(const std::string &name, Value p0, Value p1, Value p2) +Value Value::call(const char *name, Value p0, Value p1, Value p2) { // array of parameters zval **params[] = { &p0._val, &p1._val, &p2._val }; @@ -958,7 +958,7 @@ Value Value::call(const std::string &name, Value p0, Value p1, Value p2) * @param p3 The fourth parameter * @return Value */ -Value Value::call(const std::string &name, Value p0, Value p1, Value p2, Value p3) +Value Value::call(const char *name, Value p0, Value p1, Value p2, Value p3) { // array of parameters zval **params[] = { &p0._val, &p1._val, &p2._val, &p3._val }; @@ -977,7 +977,7 @@ Value Value::call(const std::string &name, Value p0, Value p1, Value p2, Value p * @param p4 The fifth parameter * @return Value */ -Value Value::call(const std::string &name, Value p0, Value p1, Value p2, Value p3, Value p4) +Value Value::call(const char *name, Value p0, Value p1, Value p2, Value p3, Value p4) { // array of parameters zval **params[] = { &p0._val, &p1._val, &p2._val, &p3._val, &p4._val }; @@ -997,7 +997,7 @@ Value Value::call(const std::string &name, Value p0, Value p1, Value p2, Value p * @param p5 The sixth parameter * @return Value */ -Value Value::call(const std::string &name, Value p0, Value p1, Value p2, Value p3, Value p4, Value p5) +Value Value::call(const char *name, Value p0, Value p1, Value p2, Value p3, Value p4, Value p5) { // array of parameters zval **params[] = { &p0._val, &p1._val, &p2._val, &p3._val, &p4._val, &p5._val }; @@ -1018,7 +1018,7 @@ Value Value::call(const std::string &name, Value p0, Value p1, Value p2, Value p * @param p6 The seventh parameter * @return Value */ -Value Value::call(const std::string &name, Value p0, Value p1, Value p2, Value p3, Value p4, Value p5, Value p6) +Value Value::call(const char *name, Value p0, Value p1, Value p2, Value p3, Value p4, Value p5, Value p6) { // array of parameters zval **params[] = { &p0._val, &p1._val, &p2._val, &p3._val, &p4._val, &p5._val, &p6._val }; @@ -1040,7 +1040,7 @@ Value Value::call(const std::string &name, Value p0, Value p1, Value p2, Value p * @param p7 The eighth parameter * @return Value */ -Value Value::call(const std::string &name, Value p0, Value p1, Value p2, Value p3, Value p4, Value p5, Value p6, Value p7) +Value Value::call(const char *name, Value p0, Value p1, Value p2, Value p3, Value p4, Value p5, Value p6, Value p7) { // array of parameters zval **params[] = { &p0._val, &p1._val, &p2._val, &p3._val, &p4._val, &p5._val, &p6._val, &p7._val }; @@ -1063,7 +1063,7 @@ Value Value::call(const std::string &name, Value p0, Value p1, Value p2, Value p * @param p8 The ninth parameter * @return Value */ -Value Value::call(const std::string &name, Value p0, Value p1, Value p2, Value p3, Value p4, Value p5, Value p6, Value p7, Value p8) +Value Value::call(const char *name, Value p0, Value p1, Value p2, Value p3, Value p4, Value p5, Value p6, Value p7, Value p8) { // array of parameters zval **params[] = { &p0._val, &p1._val, &p2._val, &p3._val, &p4._val, &p5._val, &p6._val, &p7._val, &p8._val }; @@ -1087,7 +1087,7 @@ Value Value::call(const std::string &name, Value p0, Value p1, Value p2, Value p * @param p9 The tenth parameter * @return Value */ -Value Value::call(const std::string &name, Value p0, Value p1, Value p2, Value p3, Value p4, Value p5, Value p6, Value p7, Value p8, Value p9) +Value Value::call(const char *name, Value p0, Value p1, Value p2, Value p3, Value p4, Value p5, Value p6, Value p7, Value p8, Value p9) { // array of parameters zval **params[] = { &p0._val, &p1._val, &p2._val, &p3._val, &p4._val, &p5._val, &p6._val, &p7._val, &p8._val, &p9._val }; @@ -1127,7 +1127,7 @@ Value Value::exec(int argc, zval ***params) const * @param argv The parameters * @return Value */ -Value Value::exec(const std::string &name, int argc, struct _zval_struct ***params) +Value Value::exec(const char *name, int argc, struct _zval_struct ***params) { // the method to call and the return value zval *method; @@ -1141,7 +1141,7 @@ Value Value::exec(const std::string &name, int argc, struct _zval_struct ***para // add the object and the method to call add_index_zval(method, 0, _val); - add_index_stringl(method, 1, name.c_str(), name.length(), 0); + add_index_stringl(method, 1, name, strlen(name), 0); // the current exception zval *oldException = EG(exception); |