Created
February 3, 2014 08:27
-
-
Save ptarjan/8780480 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/hphp/runtime/ext/ext_pdo.cpp b/hphp/runtime/ext/ext_pdo.cpp | |
index c49fd8f..81a4d73 100644 | |
--- a/hphp/runtime/ext/ext_pdo.cpp | |
+++ b/hphp/runtime/ext/ext_pdo.cpp | |
@@ -2025,7 +2025,7 @@ static bool do_fetch(sp_PDOStatement stmt, bool do_bind, Variant &ret, | |
static int register_bound_param(CVarRef paramno, VRefParam param, int64_t type, | |
int64_t max_value_len, CVarRef driver_params, | |
sp_PDOStatement stmt, bool is_param) { | |
- SmartResource<PDOBoundParam> p(new PDOBoundParam); | |
+ SmartResource<PDOBoundParam> p(NEWOBJ(PDOBoundParam)); | |
// need to make sure this is NULL, in case a fatal errors occurs before its set | |
// inside really_register_bound_param | |
p->stmt = NULL; | |
@@ -2640,7 +2640,7 @@ Variant c_PDOStatement::t_execute(CArrRef params /* = null_array */) { | |
if (!params.empty()) { | |
m_stmt->bound_params.reset(); | |
for (ArrayIter iter(params); iter; ++iter) { | |
- SmartResource<PDOBoundParam> param(new PDOBoundParam); | |
+ SmartResource<PDOBoundParam> param(NEWOBJ(PDOBoundParam)); | |
param->param_type = PDO_PARAM_STR; | |
param->parameter = iter.second(); | |
param->stmt = NULL; | |
diff --git a/hphp/runtime/ext/pdo_driver.cpp b/hphp/runtime/ext/pdo_driver.cpp | |
index 9b527dc..e44e867 100644 | |
--- a/hphp/runtime/ext/pdo_driver.cpp | |
+++ b/hphp/runtime/ext/pdo_driver.cpp | |
@@ -180,6 +180,10 @@ PDOBoundParam::PDOBoundParam() | |
} | |
PDOBoundParam::~PDOBoundParam() { | |
+ sweep(); | |
+} | |
+ | |
+void PDOBoundParam::sweep() { | |
/* tell the driver that it is going away */ | |
if (stmt && stmt->support(PDOStatement::MethodParamHook)) { | |
stmt->paramHook(this, PDO_PARAM_EVT_FREE); | |
@@ -203,6 +207,10 @@ PDOStatement::~PDOStatement() { | |
} | |
} | |
+void PDOStatement::sweep() { | |
+ // nothing, but kids can overwrite | |
+} | |
+ | |
bool PDOStatement::support(SupportedMethod method) { | |
return false; | |
} | |
diff --git a/hphp/runtime/ext/pdo_driver.h b/hphp/runtime/ext/pdo_driver.h | |
index 93829e4..d790d28 100644 | |
--- a/hphp/runtime/ext/pdo_driver.h | |
+++ b/hphp/runtime/ext/pdo_driver.h | |
@@ -237,6 +237,9 @@ typedef SmartResource<PDOStatement> sp_PDOStatement; | |
/* represents a connection to a database */ | |
class PDOConnection : public SweepableResourceData { | |
public: | |
+ // This is special and doesn't use DECLARE_RESOURCE_ALLOCATION because it has | |
+ // to live across requests. It is also the weirdest SweepableResourceData | |
+ // as it can't use any PHP objects and delete's itself during sweep(). | |
static const char *PersistentKey; | |
enum SupportedMethod { | |
@@ -391,6 +394,7 @@ typedef SmartResource<PDOConnection> sp_PDOConnection; | |
/* describes a column */ | |
class PDOColumn : public ResourceData { | |
public: | |
+ DECLARE_RESOURCE_ALLOCATION_NO_SWEEP(PDOColumn); | |
PDOColumn(); | |
~PDOColumn(); | |
@@ -408,8 +412,9 @@ public: | |
/////////////////////////////////////////////////////////////////////////////// | |
/* describes a bound parameter */ | |
-class PDOBoundParam : public ResourceData { | |
+class PDOBoundParam : public SweepableResourceData { | |
public: | |
+ DECLARE_RESOURCE_ALLOCATION(PDOBoundParam); | |
PDOBoundParam(); | |
~PDOBoundParam(); | |
@@ -441,8 +446,9 @@ class c_pdo; | |
typedef SmartObject<c_pdo> sp_pdo; | |
/* represents a prepared statement */ | |
-class PDOStatement : public ResourceData { | |
+class PDOStatement : public SweepableResourceData { | |
public: | |
+ DECLARE_RESOURCE_ALLOCATION(PDOStatement); | |
enum SupportedMethod { | |
MethodExecuter, | |
MethodFetcher, | |
diff --git a/hphp/runtime/ext/pdo_mysql.cpp b/hphp/runtime/ext/pdo_mysql.cpp | |
index f0452b1..6e0fadf 100644 | |
--- a/hphp/runtime/ext/pdo_mysql.cpp | |
+++ b/hphp/runtime/ext/pdo_mysql.cpp | |
@@ -84,6 +84,7 @@ private: | |
class PDOMySqlStatement : public PDOStatement { | |
public: | |
+ DECLARE_RESOURCE_ALLOCATION(PDOMySqlStatement); | |
PDOMySqlStatement(PDOMySqlConnection *conn, MYSQL *server); | |
virtual ~PDOMySqlStatement(); | |
@@ -474,7 +475,7 @@ int PDOMySqlConnection::handleError(const char *file, int line, | |
bool PDOMySqlConnection::preparer(const String& sql, sp_PDOStatement *stmt, | |
CVarRef options) { | |
- PDOMySqlStatement *s = new PDOMySqlStatement(this, m_server); | |
+ PDOMySqlStatement *s = NEWOBJ(PDOMySqlStatement)(this, m_server); | |
*stmt = s; | |
if (m_emulate_prepare) { | |
@@ -808,6 +809,10 @@ PDOMySqlStatement::PDOMySqlStatement(PDOMySqlConnection *conn, MYSQL *server) | |
} | |
PDOMySqlStatement::~PDOMySqlStatement() { | |
+ sweep(); | |
+} | |
+ | |
+void PDOMySqlStatement::sweep() { | |
if (m_result) { | |
/* free the resource */ | |
mysql_free_result(m_result); | |
@@ -1001,7 +1006,7 @@ bool PDOMySqlStatement::describer(int colno) { | |
if (columns.empty()) { | |
for (int i = 0; i < column_count; i++) { | |
- columns.set(i, Resource(new PDOColumn())); | |
+ columns.set(i, Resource(NEWOBJ(PDOColumn))); | |
} | |
} | |
@@ -1276,6 +1281,7 @@ PDOMySql::PDOMySql() : PDODriver("mysql") { | |
} | |
PDOConnection *PDOMySql::createConnectionObject() { | |
+ // Doesn't use NEWOBJ because PDOConnection is malloced | |
return new PDOMySqlConnection(); | |
} | |
diff --git a/hphp/runtime/ext/pdo_sqlite.cpp b/hphp/runtime/ext/pdo_sqlite.cpp | |
index 9af121d..bd6f4a6 100644 | |
--- a/hphp/runtime/ext/pdo_sqlite.cpp | |
+++ b/hphp/runtime/ext/pdo_sqlite.cpp | |
@@ -30,6 +30,7 @@ IMPLEMENT_DEFAULT_EXTENSION_VERSION(pdo_sqlite, 1.0.1); | |
class PDOSqliteStatement : public PDOStatement { | |
public: | |
+ DECLARE_RESOURCE_ALLOCATION(PDOSqliteStatement); | |
PDOSqliteStatement(sqlite3 *db, sqlite3_stmt* stmt); | |
virtual ~PDOSqliteStatement(); | |
@@ -188,7 +189,7 @@ bool PDOSqliteConnection::preparer(const String& sql, sp_PDOStatement *stmt, | |
if (sqlite3_prepare(m_db, sql.data(), sql.size(), &rawstmt, &tail) | |
== SQLITE_OK) { | |
- PDOSqliteStatement *s = new PDOSqliteStatement(m_db, rawstmt); | |
+ PDOSqliteStatement *s = NEWOBJ(PDOSqliteStatement)(m_db, rawstmt); | |
*stmt = s; | |
return true; | |
} | |
@@ -317,6 +318,10 @@ PDOSqliteStatement::PDOSqliteStatement(sqlite3 *db, sqlite3_stmt* stmt) | |
} | |
PDOSqliteStatement::~PDOSqliteStatement() { | |
+ sweep(); | |
+} | |
+ | |
+void PDOSqliteStatement::sweep() { | |
if (m_stmt) { | |
sqlite3_finalize(m_stmt); | |
} | |
@@ -406,7 +411,7 @@ bool PDOSqliteStatement::describer(int colno) { | |
if (columns.empty()) { | |
for (int i = 0; i < column_count; i++) { | |
- columns.set(i, Resource(new PDOColumn())); | |
+ columns.set(i, Resource(NEWOBJ(PDOColumn))); | |
} | |
} | |
@@ -614,6 +619,7 @@ PDOSqlite::PDOSqlite() : PDODriver("sqlite") { | |
} | |
PDOConnection *PDOSqlite::createConnectionObject() { | |
+ // Doesn't use NEWOBJ because PDOConnection is malloced | |
return new PDOSqliteConnection(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment