Revert "Do copying with the AttachLiteral constructors."
Revert "Explicit CopyString, remove (const char*) constructors."
Esse commit está contido em:
@@ -781,7 +781,7 @@ void FunctionScope::setParamName(int index, const std::string &name) {
|
||||
void FunctionScope::setParamDefault(int index, const char* value, int64_t len,
|
||||
const std::string &text) {
|
||||
assert(index >= 0 && index < (int)m_paramNames.size());
|
||||
StringData* sd = new StringData(value, len, CopyString);
|
||||
StringData* sd = new StringData(value, len, AttachLiteral);
|
||||
sd->setStatic();
|
||||
m_paramDefaults[index] = String(sd);
|
||||
m_paramDefaultTexts[index] = text;
|
||||
|
||||
@@ -391,13 +391,13 @@ std::string Option::MangleFilename(const std::string &name, bool id) {
|
||||
|
||||
bool Option::IsFileExcluded(const std::string &file,
|
||||
const std::set<std::string> &patterns) {
|
||||
String sfile(file.c_str(), file.size(), CopyString);
|
||||
String sfile(file.c_str(), file.size(), AttachLiteral);
|
||||
for (set<string>::const_iterator iter = patterns.begin();
|
||||
iter != patterns.end(); ++iter) {
|
||||
const std::string &pattern = *iter;
|
||||
Variant matches;
|
||||
Variant ret = preg_match(String(pattern.c_str(), pattern.size(),
|
||||
CopyString), sfile, matches);
|
||||
AttachLiteral), sfile, matches);
|
||||
if (ret.toInt64() > 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -375,7 +375,7 @@ inline bool same(const StringData *v1, CStrRef v2) {
|
||||
return same(v1, v2.get());
|
||||
}
|
||||
inline bool same(const StringData *v1, litstr v2) {
|
||||
StackStringData sd2(v2, CopyString);
|
||||
StackStringData sd2(v2);
|
||||
return same(v1, &sd2);
|
||||
}
|
||||
inline bool same(const StringData *v1, CArrRef v2) { return false; }
|
||||
@@ -396,7 +396,7 @@ inline bool equal(const StringData *v1, CStrRef v2) {
|
||||
return equal(v1, v2.get());
|
||||
}
|
||||
inline bool equal(const StringData *v1, litstr v2) {
|
||||
StackStringData sd2(v2, CopyString);
|
||||
StackStringData sd2(v2);
|
||||
return equal(v1, &sd2);
|
||||
}
|
||||
inline bool equal(const StringData *v1, CArrRef v2) {
|
||||
@@ -464,7 +464,7 @@ inline bool less(const StringData *v1, CStrRef v2) {
|
||||
return less(v1, v2.get());
|
||||
}
|
||||
inline bool less(const StringData *v1, litstr v2) {
|
||||
StackStringData sd2(v2, CopyString);
|
||||
StackStringData sd2(v2);
|
||||
return less(v1, &sd2);
|
||||
}
|
||||
inline bool less(const StringData *v1, CArrRef v2) {
|
||||
@@ -501,7 +501,7 @@ inline bool more(const StringData *v1, CStrRef v2) {
|
||||
return more(v1, v2.get());
|
||||
}
|
||||
inline bool more(const StringData *v1, litstr v2) {
|
||||
StackStringData sd2(v2, CopyString);
|
||||
StackStringData sd2(v2);
|
||||
return more(v1, &sd2);
|
||||
}
|
||||
inline bool more(const StringData *v1, CArrRef v2) {
|
||||
@@ -607,7 +607,7 @@ inline bool same(litstr v1, int v2) { return same(String(v1), v2);}
|
||||
inline bool same(litstr v1, int64_t v2) { return same(String(v1), v2);}
|
||||
inline bool same(litstr v1, double v2) { return same(String(v1), v2);}
|
||||
inline bool same(litstr v1, const StringData *v2) {
|
||||
StackStringData sd1(v1, CopyString);
|
||||
StackStringData sd1(v1);
|
||||
return same(&sd1, v2);
|
||||
}
|
||||
inline bool same(litstr v1, CStrRef v2) { return same(String(v1), v2);}
|
||||
@@ -621,7 +621,7 @@ inline bool equal(litstr v1, int v2) { return equal(String(v1),v2);}
|
||||
inline bool equal(litstr v1, int64_t v2) { return equal(String(v1),v2);}
|
||||
inline bool equal(litstr v1, double v2) { return equal(String(v1),v2);}
|
||||
inline bool equal(litstr v1, const StringData *v2) {
|
||||
StackStringData sd1(v1, CopyString);
|
||||
StackStringData sd1(v1);
|
||||
return equal(&sd1, v2);
|
||||
}
|
||||
inline bool equal(litstr v1, CStrRef v2) { return equal(String(v1),v2);}
|
||||
@@ -640,7 +640,7 @@ inline bool equalAsStr(litstr v1, const StringData *v2) {
|
||||
inline bool equalAsStr(litstr v1, CStrRef v2) { return equalAsStr(v2, v1);}
|
||||
inline bool equalAsStr(litstr v1, litstr v2) { return same(v1, v2);}
|
||||
inline bool equalAsStr(litstr v1, CArrRef v2) {
|
||||
StackStringData sd1(v1, CopyString);
|
||||
StackStringData sd1(v1);
|
||||
return equalAsStr(&sd1, v2);
|
||||
}
|
||||
inline bool equalAsStr(litstr v1, CObjRef v2) {
|
||||
@@ -653,7 +653,7 @@ inline bool less(litstr v1, int v2) { return less(String(v1), v2);}
|
||||
inline bool less(litstr v1, int64_t v2) { return less(String(v1), v2);}
|
||||
inline bool less(litstr v1, double v2) { return less(String(v1), v2);}
|
||||
inline bool less(litstr v1, const StringData *v2) {
|
||||
StackStringData sd1(v1, CopyString);
|
||||
StackStringData sd1(v1);
|
||||
return less(&sd1, v2);
|
||||
}
|
||||
inline bool less(litstr v1, CStrRef v2) { return less(String(v1), v2);}
|
||||
@@ -667,7 +667,7 @@ inline bool more(litstr v1, int v2) { return more(String(v1), v2);}
|
||||
inline bool more(litstr v1, int64_t v2) { return more(String(v1), v2);}
|
||||
inline bool more(litstr v1, double v2) { return more(String(v1), v2);}
|
||||
inline bool more(litstr v1, const StringData *v2) {
|
||||
StackStringData sd1(v1, CopyString);
|
||||
StackStringData sd1(v1);
|
||||
return more(&sd1, v2);
|
||||
}
|
||||
inline bool more(litstr v1, CStrRef v2) { return more(String(v1), v2);}
|
||||
|
||||
@@ -479,9 +479,9 @@ static bool matchHdfPattern(const std::string &value, Hdf hdfPattern) {
|
||||
string pattern = hdfPattern.getString();
|
||||
if (!pattern.empty()) {
|
||||
Variant ret = preg_match(String(pattern.c_str(), pattern.size(),
|
||||
CopyString),
|
||||
AttachLiteral),
|
||||
String(value.c_str(), value.size(),
|
||||
CopyString));
|
||||
AttachLiteral));
|
||||
if (ret.toInt64() <= 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -31,9 +31,9 @@ FilesMatch::FilesMatch(Hdf vh) {
|
||||
bool FilesMatch::match(const std::string &filename) const {
|
||||
if (!m_pattern.empty()) {
|
||||
Variant ret = preg_match(String(m_pattern.c_str(), m_pattern.size(),
|
||||
CopyString),
|
||||
AttachLiteral),
|
||||
String(filename.c_str(), filename.size(),
|
||||
CopyString));
|
||||
AttachLiteral));
|
||||
return ret.toInt64() > 0;
|
||||
}
|
||||
return false;
|
||||
|
||||
@@ -173,7 +173,7 @@ void HttpProtocol::PrepareSystemVariables(Transport *transport,
|
||||
} else {
|
||||
// For literal we disregard RuntimeOption::AlwaysPopulateRawPostData
|
||||
if (uint32_t(size) <= StringData::MaxSize) {
|
||||
g->GV(HTTP_RAW_POST_DATA) = String((char*)data, size, CopyString);
|
||||
g->GV(HTTP_RAW_POST_DATA) = String((char*)data, size, AttachLiteral);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -400,10 +400,10 @@ bool HttpRequestHandler::handleProxyRequest(Transport *transport, bool force) {
|
||||
|
||||
bool HttpRequestHandler::MatchAnyPattern
|
||||
(const std::string &path, const std::vector<std::string> &patterns) {
|
||||
String spath(path.c_str(), path.size(), CopyString);
|
||||
String spath(path.c_str(), path.size(), AttachLiteral);
|
||||
for (unsigned int i = 0; i < patterns.size(); i++) {
|
||||
Variant ret = preg_match(String(patterns[i].c_str(), patterns[i].size(),
|
||||
CopyString),
|
||||
AttachLiteral),
|
||||
spath);
|
||||
if (ret.toInt64() > 0) return true;
|
||||
}
|
||||
|
||||
@@ -199,7 +199,7 @@ bool RPCRequestHandler::executePHPFunction(Transport *transport,
|
||||
int size;
|
||||
const void *data = transport->getPostData(size);
|
||||
if (data && size) {
|
||||
params.append(String((char*)data, size, CopyString));
|
||||
params.append(String((char*)data, size, AttachLiteral));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -81,11 +81,11 @@ public:
|
||||
}
|
||||
|
||||
virtual bool shouldHandle(const std::string &cmd) {
|
||||
String url(cmd.c_str(), cmd.size(), CopyString);
|
||||
String url(cmd.c_str(), cmd.size(), AttachLiteral);
|
||||
for (set<string>::const_iterator iter = m_allowedURLs.begin();
|
||||
iter != m_allowedURLs.end(); ++iter) {
|
||||
Variant ret = preg_match
|
||||
(String(iter->c_str(), iter->size(), CopyString), url);
|
||||
(String(iter->c_str(), iter->size(), AttachLiteral), url);
|
||||
if (ret.toInt64() > 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -54,12 +54,12 @@ Server::Server(const std::string &address, int port, int threadCount)
|
||||
}
|
||||
|
||||
bool Server::shouldHandle(const std::string &cmd) {
|
||||
String url(cmd.c_str(), cmd.size(), CopyString);
|
||||
String url(cmd.c_str(), cmd.size(), AttachLiteral);
|
||||
for (std::set<string>::const_iterator iter =
|
||||
SatelliteServerInfo::InternalURLs.begin();
|
||||
iter != SatelliteServerInfo::InternalURLs.end(); ++iter) {
|
||||
Variant ret = preg_match
|
||||
(String(iter->c_str(), iter->size(), CopyString), url);
|
||||
(String(iter->c_str(), iter->size(), AttachLiteral), url);
|
||||
if (ret.toInt64() > 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -158,8 +158,8 @@ void ServerStats::Filter(list<TimeSlot*> &slots, const std::string &keys,
|
||||
const string &rule = riter->first;
|
||||
if (rule[0] == ':') {
|
||||
Variant ret = preg_match(String(rule.c_str(), rule.size(),
|
||||
CopyString),
|
||||
String(key.c_str(), key.size(), CopyString));
|
||||
AttachLiteral),
|
||||
String(key.c_str(), key.size(), AttachLiteral));
|
||||
if (!same(ret, false) && more(ret, 0)) {
|
||||
wantedKeys[key] |= riter->second;
|
||||
}
|
||||
@@ -307,7 +307,7 @@ void ServerStats::FreeSlots(list<TimeSlot*> &slots) {
|
||||
|
||||
class Writer {
|
||||
public:
|
||||
explicit Writer(ostream &out) : m_out(out), m_indent(0) {}
|
||||
Writer(ostream &out) : m_out(out), m_indent(0) {}
|
||||
virtual ~Writer() {}
|
||||
|
||||
virtual void writeFileHeader() = 0;
|
||||
@@ -350,7 +350,8 @@ protected:
|
||||
|
||||
class XMLWriter : public Writer {
|
||||
public:
|
||||
explicit XMLWriter(ostream &out) : Writer(out) {}
|
||||
XMLWriter(ostream &out) : Writer(out) {}
|
||||
|
||||
|
||||
virtual void writeFileHeader() {
|
||||
m_out << "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
|
||||
@@ -482,7 +483,10 @@ protected:
|
||||
}
|
||||
|
||||
public:
|
||||
explicit JSONWriter(ostream &out) : Writer(out), m_justIndented(true) {
|
||||
|
||||
JSONWriter(ostream &out) : Writer(out),
|
||||
m_justIndented(true) {
|
||||
|
||||
// A valid json object begins in the nameless context. See
|
||||
// json.org for JSON state machine.
|
||||
m_namelessContextStack.push(true);
|
||||
@@ -529,8 +533,9 @@ public:
|
||||
};
|
||||
|
||||
class HTMLWriter : public Writer {
|
||||
|
||||
public:
|
||||
explicit HTMLWriter(ostream &out) : Writer(out) {}
|
||||
HTMLWriter(ostream &out) : Writer(out) {}
|
||||
|
||||
virtual void writeFileHeader() {
|
||||
m_out << "<!doctype html>\n<html>\n<head>\n"
|
||||
|
||||
@@ -37,7 +37,7 @@ SourceRootInfo::SourceRootInfo(const char *host)
|
||||
Variant matches;
|
||||
Variant r = preg_match(String(RuntimeOption::SandboxPattern.c_str(),
|
||||
RuntimeOption::SandboxPattern.size(),
|
||||
CopyString), host, matches);
|
||||
AttachLiteral), host, matches);
|
||||
if (!r.same(1)) {
|
||||
m_sandboxCond = SandboxOff;
|
||||
return;
|
||||
|
||||
@@ -614,7 +614,7 @@ void Transport::prepareHeaders(bool compressed, const void *data, int size) {
|
||||
addHeaderImpl("Content-Encoding", "gzip");
|
||||
removeHeaderImpl("Content-Length");
|
||||
if (m_responseHeaders.find("Content-MD5") != m_responseHeaders.end()) {
|
||||
String response((const char *)data, size, CopyString);
|
||||
String response((const char *)data, size, AttachLiteral);
|
||||
removeHeaderImpl("Content-MD5");
|
||||
addHeaderImpl("Content-MD5", StringUtil::Base64Encode(
|
||||
StringUtil::MD5(response, true)).c_str());
|
||||
@@ -663,7 +663,7 @@ void Transport::prepareHeaders(bool compressed, const void *data, int size) {
|
||||
|
||||
String Transport::prepareResponse(const void *data, int size, bool &compressed,
|
||||
bool last) {
|
||||
String response((const char *)data, size, CopyString);
|
||||
String response((const char *)data, size, AttachLiteral);
|
||||
|
||||
// we don't use chunk encoding to send anything pre-compressed
|
||||
assert(!compressed || !m_chunkedEncoding);
|
||||
|
||||
@@ -263,9 +263,9 @@ void VirtualHost::init(Hdf vh) {
|
||||
bool VirtualHost::match(const string &host) const {
|
||||
if (!m_pattern.empty()) {
|
||||
Variant ret = preg_match(String(m_pattern.c_str(), m_pattern.size(),
|
||||
CopyString),
|
||||
AttachLiteral),
|
||||
String(host.c_str(), host.size(),
|
||||
CopyString));
|
||||
AttachLiteral));
|
||||
return ret.toInt64() > 0;
|
||||
} else if (!m_prefix.empty()) {
|
||||
return strncasecmp(host.c_str(), m_prefix.c_str(), m_prefix.size()) == 0;
|
||||
@@ -304,7 +304,7 @@ bool VirtualHost::rewriteURL(CStrRef host, String &url, bool &qsa,
|
||||
subject = host;
|
||||
}
|
||||
Variant ret = preg_match(String(it->pattern.c_str(), it->pattern.size(),
|
||||
CopyString), subject);
|
||||
AttachLiteral), subject);
|
||||
if (!ret.same(it->negate ? 0 : 1)) {
|
||||
passed = false;
|
||||
break;
|
||||
@@ -379,9 +379,9 @@ std::string VirtualHost::serverName(const std::string &host) const {
|
||||
if (!m_pattern.empty()) {
|
||||
Variant matches;
|
||||
Variant ret = preg_match(String(m_pattern.c_str(), m_pattern.size(),
|
||||
CopyString),
|
||||
AttachLiteral),
|
||||
String(host.c_str(), host.size(),
|
||||
CopyString),
|
||||
AttachLiteral),
|
||||
matches);
|
||||
if (ret.toInt64() > 0) {
|
||||
String prefix = matches[1].toString();
|
||||
@@ -414,9 +414,9 @@ std::string VirtualHost::filterUrl(const std::string &url) const {
|
||||
if (!filter.urlPattern.empty()) {
|
||||
Variant ret = preg_match(String(filter.urlPattern.c_str(),
|
||||
filter.urlPattern.size(),
|
||||
CopyString),
|
||||
AttachLiteral),
|
||||
String(url.c_str(), url.size(),
|
||||
CopyString));
|
||||
AttachLiteral));
|
||||
match = (ret.toInt64() > 0);
|
||||
}
|
||||
|
||||
@@ -429,9 +429,9 @@ std::string VirtualHost::filterUrl(const std::string &url) const {
|
||||
int count = preg_replace(ret, filter.namePattern.c_str(),
|
||||
String(filter.replaceWith.c_str(),
|
||||
filter.replaceWith.size(),
|
||||
CopyString),
|
||||
AttachLiteral),
|
||||
String(url.c_str(), url.size(),
|
||||
CopyString));
|
||||
AttachLiteral));
|
||||
if (!same(ret, false) && count > 0) {
|
||||
return ret.toString().data();
|
||||
}
|
||||
|
||||
@@ -325,7 +325,7 @@ static int64_t get_int64_value(StoreValue* sval) {
|
||||
v = sval->var->toLocal();
|
||||
} else {
|
||||
assert(sval->inFile());
|
||||
String s(sval->sAddr, sval->getSerializedSize(), CopyString);
|
||||
String s(sval->sAddr, sval->getSerializedSize(), AttachLiteral);
|
||||
v = apc_unserialize(s);
|
||||
}
|
||||
return v.toInt64();
|
||||
@@ -498,7 +498,7 @@ void ConcurrentTableSharedStore::prime
|
||||
continue;
|
||||
}
|
||||
if (RuntimeOption::APCSizeCountPrime) {
|
||||
StackStringData sd(copy, CopyString);
|
||||
StackStringData sd(copy);
|
||||
stats_on_add(&sd, &acc->second, 0, true, false);
|
||||
}
|
||||
}
|
||||
@@ -601,7 +601,7 @@ void ConcurrentTableSharedStore::dump(std::ostream & out, bool keyOnly,
|
||||
assert(sval->inFile());
|
||||
// we need unserialize and serialize again because the format was
|
||||
// APCSerialize
|
||||
String s(sval->sAddr, sval->getSerializedSize(), CopyString);
|
||||
String s(sval->sAddr, sval->getSerializedSize(), AttachLiteral);
|
||||
value = apc_unserialize(s);
|
||||
}
|
||||
try {
|
||||
|
||||
@@ -140,7 +140,7 @@ Variant SharedVariant::toLocal() {
|
||||
{
|
||||
if (getSerializedArray()) {
|
||||
return apc_unserialize(String(m_data.str->data(), m_data.str->size(),
|
||||
CopyString));
|
||||
AttachLiteral));
|
||||
}
|
||||
return NEW(SharedMap)(this);
|
||||
}
|
||||
@@ -156,7 +156,7 @@ Variant SharedVariant::toLocal() {
|
||||
return m_data.obj->getObject();
|
||||
}
|
||||
return apc_unserialize(String(m_data.str->data(), m_data.str->size(),
|
||||
CopyString));
|
||||
AttachLiteral));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -106,12 +106,12 @@ StringData* StringData::FindStaticString(const StringData* str) {
|
||||
}
|
||||
|
||||
StringData *StringData::GetStaticString(const std::string &str) {
|
||||
StackStringData sd(str.c_str(), str.size(), CopyString);
|
||||
StackStringData sd(str.c_str(), str.size(), AttachLiteral);
|
||||
return GetStaticString(&sd);
|
||||
}
|
||||
|
||||
StringData *StringData::GetStaticString(const char *str) {
|
||||
StackStringData sd(str, strlen(str), CopyString);
|
||||
StackStringData sd(str, strlen(str), AttachLiteral);
|
||||
return GetStaticString(&sd);
|
||||
}
|
||||
|
||||
@@ -166,6 +166,25 @@ Array StringData::GetConstants() {
|
||||
return a;
|
||||
}
|
||||
|
||||
void StringData::initLiteral(const char* data) {
|
||||
return initLiteral(data, strlen(data));
|
||||
}
|
||||
|
||||
void StringData::initLiteral(const char* data, int len) {
|
||||
if (uint32_t(len) > MaxSize) {
|
||||
throw InvalidArgumentException("len > 2^31-2", len);
|
||||
}
|
||||
// Do not copy literals, this StringData can have a shorter lifetime than
|
||||
// the literal, and the client can count on this->data() giving back
|
||||
// the literal ptr with the longer lifetime. Sketchy!
|
||||
m_hash = 0;
|
||||
_count = 0;
|
||||
m_len = len;
|
||||
m_cdata = data;
|
||||
m_big.cap = len | IsLiteral;
|
||||
assert(checkSane());
|
||||
}
|
||||
|
||||
void StringData::enlist() {
|
||||
assert(isShared());
|
||||
SweepNode& head = MemoryManager::TheMemoryManager()->m_strings;
|
||||
@@ -384,7 +403,7 @@ void StringData::append(const char *s, int len) {
|
||||
// TODO: t1122987: in any of the cases below where we need a bigger buffer,
|
||||
// we can probably assume we're in a concat-loop and pick a good buffer
|
||||
// size to avoid O(N^2) copying cost.
|
||||
if (isShared()) {
|
||||
if (isShared() || isLiteral()) {
|
||||
// buffer is immutable, don't modify it.
|
||||
StringSlice r = slice();
|
||||
char* newdata = smart_concat(r.ptr, r.len, s, len);
|
||||
@@ -514,8 +533,12 @@ StringData *StringData::copy(bool sharedMemory /* = false */) const {
|
||||
// which will be freed at the end of the request, and so must be
|
||||
// copied.
|
||||
return new StringData(data(), size(), CopyMalloc);
|
||||
} else {
|
||||
if (isLiteral()) {
|
||||
return NEW(StringData)(data(), size(), AttachLiteral);
|
||||
}
|
||||
return NEW(StringData)(data(), size(), CopyString);
|
||||
}
|
||||
return NEW(StringData)(data(), size(), CopyString);
|
||||
}
|
||||
|
||||
MutableSlice StringData::escalate(uint32_t cap) {
|
||||
@@ -545,7 +568,8 @@ StringData *StringData::Escalate(StringData *in) {
|
||||
void StringData::dump() const {
|
||||
StringSlice s = slice();
|
||||
|
||||
printf("StringData(%d) (%s%s%d): [", _count,
|
||||
printf("StringData(%d) (%s%s%s%d): [", _count,
|
||||
isLiteral() ? "literal " : "",
|
||||
isShared() ? "shared " : "",
|
||||
isStatic() ? "static " : "",
|
||||
s.len);
|
||||
@@ -565,7 +589,7 @@ static StringData** precompute_chars() {
|
||||
StringData** raw = new StringData*[256];
|
||||
for (int i = 0; i < 256; i++) {
|
||||
char s[2] = { (char)i, 0 };
|
||||
StackStringData str(s, 1, CopyString);
|
||||
StackStringData str(s, 1, AttachLiteral);
|
||||
raw[i] = StringData::GetStaticString(&str);
|
||||
}
|
||||
return raw;
|
||||
|
||||
@@ -50,6 +50,12 @@ struct Slice {
|
||||
typedef Slice<const char> StringSlice;
|
||||
typedef Slice<char> MutableSlice;
|
||||
|
||||
// const char* points to a string which must remain valid for the lifetime
|
||||
// of the StringData. It is fragile to rely on StringData.data() returning
|
||||
// the same pointer after construction -- this invariant will probably be
|
||||
// deprecated to enable copying of small strings.
|
||||
enum AttachLiteralMode { AttachLiteral };
|
||||
|
||||
// Aggressively copy small strings and free the passed-in buffer immediately;
|
||||
// otherwise keep the buffer for long strings, and free it when the string
|
||||
// is mutated or released.
|
||||
@@ -83,7 +89,7 @@ enum CopyMallocMode { CopyMalloc };
|
||||
* big: m_data:8, _count:4, m_len:4, m_hash:4,
|
||||
* junk[12], node:16, shared:8, cap:8
|
||||
*
|
||||
* If the format is IsShared, we always use the "big" layout.
|
||||
* If the format is IsLiteral or IsShared, we always use the "big" layout.
|
||||
* resemblences to fbstring are not accidental.
|
||||
*/
|
||||
class StringData {
|
||||
@@ -93,9 +99,10 @@ class StringData {
|
||||
|
||||
enum Format {
|
||||
IsSmall = 0, // short str overlaps m_big
|
||||
IsShared = 0x1000000000000000, // shared memory string
|
||||
IsMalloc = 0x2000000000000000, // m_big.data is malloc'd
|
||||
IsSmart = 0x3000000000000000, // m_big.data is smart_malloc'd
|
||||
IsLiteral = 0x1000000000000000, // literal string
|
||||
IsShared = 0x2000000000000000, // shared memory string
|
||||
IsMalloc = 0x3000000000000000, // m_big.data is malloc'd
|
||||
IsSmart = 0x4000000000000000, // m_big.data is smart_malloc'd
|
||||
IsMask = 0xF000000000000000
|
||||
};
|
||||
|
||||
@@ -147,12 +154,22 @@ class StringData {
|
||||
* Different ways of constructing StringData. Default constructor at above
|
||||
* is actually only for SmartAllocator to pre-allocate the objects.
|
||||
*/
|
||||
explicit StringData(const char* data) {
|
||||
initLiteral(data);
|
||||
}
|
||||
StringData(const char *data, AttachLiteralMode) {
|
||||
initLiteral(data);
|
||||
}
|
||||
StringData(const char *data, AttachStringMode) {
|
||||
initAttach(data);
|
||||
}
|
||||
StringData(const char *data, CopyStringMode) {
|
||||
initCopy(data);
|
||||
}
|
||||
|
||||
StringData(const char *data, int len, AttachLiteralMode) {
|
||||
initLiteral(data, len);
|
||||
}
|
||||
StringData(const char* data, int len, AttachStringMode) {
|
||||
initAttach(data, len);
|
||||
}
|
||||
@@ -246,9 +263,13 @@ public:
|
||||
return StringSlice(m_data, m_len);
|
||||
}
|
||||
bool empty() const { return size() == 0;}
|
||||
bool isLiteral() const { return format() == IsLiteral; }
|
||||
bool isShared() const { return format() == IsShared; }
|
||||
bool isSmall() const { return format() == IsSmall; }
|
||||
bool isImmutable() const { return isShared() || isStatic(); }
|
||||
bool isImmutable() const {
|
||||
Format f = format();
|
||||
return f == IsLiteral || f == IsShared || isStatic();
|
||||
}
|
||||
DataType isNumericWithVal(int64_t &lval, double &dval, int allow_errors) const;
|
||||
bool isNumeric() const;
|
||||
bool isInteger() const;
|
||||
@@ -386,8 +407,10 @@ public:
|
||||
/**
|
||||
* Helpers.
|
||||
*/
|
||||
void initLiteral(const char* data);
|
||||
void initAttach(const char* data);
|
||||
void initCopy(const char* data);
|
||||
void initLiteral(const char* data, int len);
|
||||
void initAttach(const char* data, int len);
|
||||
void initCopy(const char* data, int len);
|
||||
void initMalloc(const char* data, int len);
|
||||
@@ -418,14 +441,12 @@ public:
|
||||
class StackStringData : public StringData {
|
||||
public:
|
||||
StackStringData() { incRefCount(); }
|
||||
explicit StackStringData(const char* s) : StringData(s) { incRefCount(); }
|
||||
template <class T>
|
||||
StackStringData(const char* s, T p) : StringData(s, p) {
|
||||
incRefCount();
|
||||
}
|
||||
StackStringData(const char* s, T p) : StringData(s, p) { incRefCount(); }
|
||||
template <class T>
|
||||
StackStringData(const char* s, int len, T p) : StringData(s, len, p) {
|
||||
incRefCount();
|
||||
}
|
||||
StackStringData(const char* s, int len, T p) :
|
||||
StringData(s, len, p) { incRefCount(); }
|
||||
|
||||
~StackStringData() {
|
||||
// verify that no references escaped
|
||||
|
||||
@@ -301,7 +301,7 @@ Variant StringUtil::ChunkSplit(CStrRef body, int chunklen /* = 76 */,
|
||||
String StringUtil::CEncode(CStrRef input, CStrRef charlist) {
|
||||
String chars = charlist;
|
||||
if (chars.isNull()) {
|
||||
chars = String("\\\x00\x01..\x1f\x7f..\xff", 10, CopyString);
|
||||
chars = String("\\\x00\x01..\x1f\x7f..\xff", 10, AttachLiteral);
|
||||
}
|
||||
if (input.empty() || chars.empty()) return input;
|
||||
int len = input.size();
|
||||
|
||||
@@ -151,7 +151,7 @@ Array TimeZone::GetNames() {
|
||||
|
||||
Array ret;
|
||||
for (int i = 0; i < item_count; ++i) {
|
||||
ret.append(String(table[i].id, CopyString));
|
||||
ret.append(String(table[i].id, AttachLiteral));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
@@ -176,7 +176,7 @@ Array TimeZone::GetAbbreviations() {
|
||||
element.set(s_dst, (bool)entry->type);
|
||||
element.set(s_offset, entry->gmtoffset);
|
||||
if (entry->full_tz_name) {
|
||||
element.set(s_timezone_id, String(entry->full_tz_name, CopyString));
|
||||
element.set(s_timezone_id, String(entry->full_tz_name, AttachLiteral));
|
||||
} else {
|
||||
element.set(s_timezone_id, uninit_null());
|
||||
}
|
||||
|
||||
@@ -51,9 +51,7 @@ inline char toByte(short v) { return v;}
|
||||
inline char toByte(int v) { return v;}
|
||||
inline char toByte(int64_t v) { return v;}
|
||||
inline char toByte(double v) { return (char)v;}
|
||||
inline char toByte(litstr v) {
|
||||
return StringData(v, CopyString).toByte();
|
||||
}
|
||||
inline char toByte(litstr v) { return StringData(v).toByte();}
|
||||
inline char toByte(const StringData *v) { return v ? v->toByte() : 0;}
|
||||
inline char toByte(CStrRef v) { return toByte(v.get());}
|
||||
inline char toByte(const ArrayData *v) { return (v && !v->empty()) ? 1 : 0;}
|
||||
@@ -68,9 +66,7 @@ inline short toInt16(short v) { return v;}
|
||||
inline short toInt16(int v) { return v;}
|
||||
inline short toInt16(int64_t v) { return v;}
|
||||
inline short toInt16(double v) { return (short)v;}
|
||||
inline short toInt16(litstr v) {
|
||||
return StringData(v, CopyString).toInt16();
|
||||
}
|
||||
inline short toInt16(litstr v) { return StringData(v).toInt16();}
|
||||
inline short toInt16(const StringData *v) { return v ? v->toInt16() : 0;}
|
||||
inline short toInt16(CStrRef v) { return toInt16(v.get());}
|
||||
inline short toInt16(const ArrayData *v) { return (v && !v->empty()) ? 1 : 0;}
|
||||
@@ -85,9 +81,7 @@ inline int toInt32(short v) { return v;}
|
||||
inline int toInt32(int v) { return v;}
|
||||
inline int toInt32(int64_t v) { return v;}
|
||||
inline int toInt32(double v) { return (int)v;}
|
||||
inline int toInt32(litstr v) {
|
||||
return StringData(v, CopyString).toInt32();
|
||||
}
|
||||
inline int toInt32(litstr v) { return StringData(v).toInt32();}
|
||||
inline int toInt32(const StringData *v) { return v ? v->toInt32() : 0;}
|
||||
inline int toInt32(CStrRef v) { return toInt32(v.get());}
|
||||
inline int toInt32(const ArrayData *v) { return (v && !v->empty()) ? 1 : 0;}
|
||||
@@ -109,9 +103,7 @@ inline int64_t toInt64(double v) {
|
||||
? (v > std::numeric_limits<uint64_t>::max() ? 0u : (uint64_t)v)
|
||||
: (v < 0 ? (int64_t)v : std::numeric_limits<int64_t>::min()));
|
||||
}
|
||||
inline int64_t toInt64(litstr v) {
|
||||
return StringData(v, CopyString).toInt64();
|
||||
}
|
||||
inline int64_t toInt64(litstr v) { return StringData(v).toInt64();}
|
||||
inline int64_t toInt64(const StringData *v) { return v ? v->toInt64() : 0;}
|
||||
inline int64_t toInt64(CStrRef v) { return toInt64(v.get());}
|
||||
inline int64_t toInt64(const ArrayData *v) { return (v && !v->empty()) ? 1 : 0;}
|
||||
@@ -126,9 +118,7 @@ inline double toDouble(short v) { return v;}
|
||||
inline double toDouble(int v) { return v;}
|
||||
inline double toDouble(int64_t v) { return v;}
|
||||
inline double toDouble(double v) { return v;}
|
||||
inline double toDouble(litstr v) {
|
||||
return StringData(v, CopyString).toDouble();
|
||||
}
|
||||
inline double toDouble(litstr v) { return StringData(v).toDouble();}
|
||||
inline double toDouble(const StringData *v) { return v? v->toDouble() : 0;}
|
||||
inline double toDouble(CStrRef v) { return toDouble(v.get());}
|
||||
inline double toDouble(const ArrayData *v) {
|
||||
|
||||
@@ -137,7 +137,7 @@ String::String(double n) {
|
||||
}
|
||||
|
||||
StringData* buildStringData(litstr s) {
|
||||
return NEW(StringData)(s, CopyString);
|
||||
return NEW(StringData)(s, AttachLiteral);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
@@ -284,7 +284,7 @@ char String::charAt(int pos) const {
|
||||
String &String::operator=(litstr s) {
|
||||
if (m_px) decRefStr(m_px);
|
||||
if (s) {
|
||||
m_px = NEW(StringData)(s, CopyString);
|
||||
m_px = NEW(StringData)(s, AttachLiteral);
|
||||
m_px->setRefCount(1);
|
||||
} else {
|
||||
m_px = nullptr;
|
||||
@@ -320,7 +320,7 @@ String &String::operator=(CVarRef var) {
|
||||
String &String::operator+=(litstr s) {
|
||||
if (s && *s) {
|
||||
if (empty()) {
|
||||
m_px = NEW(StringData)(s, CopyString);
|
||||
m_px = NEW(StringData)(s, AttachLiteral);
|
||||
m_px->setRefCount(1);
|
||||
} else if (m_px->getCount() == 1) {
|
||||
m_px->append(s, strlen(s));
|
||||
@@ -725,11 +725,12 @@ void String::dump() const {
|
||||
// StaticString
|
||||
|
||||
StaticString::StaticString(litstr s) {
|
||||
m_px = StringData::GetStaticString(s);
|
||||
StackStringData sd(s);
|
||||
m_px = StringData::GetStaticString(&sd);
|
||||
}
|
||||
|
||||
StaticString::StaticString(litstr s, int length) {
|
||||
StackStringData sd(s, length, CopyString);
|
||||
StackStringData sd(s, length, AttachLiteral);
|
||||
m_px = StringData::GetStaticString(&sd);
|
||||
}
|
||||
|
||||
|
||||
@@ -151,6 +151,13 @@ public:
|
||||
m_px = NEW(StringData)(s.data(), s.size(), CopyString);
|
||||
m_px->setRefCount(1);
|
||||
}
|
||||
// attach to null terminated string literal
|
||||
String(const char *s, AttachLiteralMode mode) {
|
||||
if (s) {
|
||||
m_px = NEW(StringData)(s, mode);
|
||||
m_px->setRefCount(1);
|
||||
}
|
||||
}
|
||||
// attach to null terminated malloc'ed string, maybe free it now.
|
||||
String(const char *s, AttachStringMode mode) {
|
||||
if (s) {
|
||||
@@ -165,6 +172,13 @@ public:
|
||||
m_px->setRefCount(1);
|
||||
}
|
||||
}
|
||||
// attach to binary string literal
|
||||
String(const char *s, int length, AttachLiteralMode mode) {
|
||||
if (s) {
|
||||
m_px = NEW(StringData)(s, length, mode);
|
||||
m_px->setRefCount(1);
|
||||
}
|
||||
}
|
||||
// attach to binary malloc'ed string
|
||||
String(const char *s, int length, AttachStringMode mode) {
|
||||
if (s) {
|
||||
@@ -250,6 +264,9 @@ public:
|
||||
bool isValidVariableName() const {
|
||||
return m_px ? m_px->isValidVariableName() : false;
|
||||
}
|
||||
bool isLiteral() const {
|
||||
return m_px ? m_px->isLiteral() : true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Take a sub-string from start with specified length. Note, read
|
||||
|
||||
@@ -77,7 +77,7 @@ static VarNR ToKey(CVarRef v) { return v.toKey(); }
|
||||
|
||||
Variant::Variant(litstr v) {
|
||||
m_type = KindOfString;
|
||||
m_data.pstr = NEW(StringData)(v, CopyString);
|
||||
m_data.pstr = NEW(StringData)(v);
|
||||
m_data.pstr->incRefCount();
|
||||
}
|
||||
|
||||
@@ -293,7 +293,7 @@ HOT_FUNC IMPLEMENT_SET(int64_t, m_type = KindOfInt64; m_data.num = v)
|
||||
IMPLEMENT_SET(double, m_type = KindOfDouble; m_data.dbl = v)
|
||||
IMPLEMENT_SET(litstr,
|
||||
m_type = KindOfString;
|
||||
m_data.pstr = NEW(StringData)(v, CopyString);
|
||||
m_data.pstr = NEW(StringData)(v);
|
||||
m_data.pstr->incRefCount())
|
||||
IMPLEMENT_SET(const StaticString&,
|
||||
StringData* s = v.get();
|
||||
@@ -1563,7 +1563,7 @@ bool Variant::same(double v2) const {
|
||||
}
|
||||
|
||||
bool Variant::same(litstr v2) const {
|
||||
StackStringData sd2(v2, CopyString);
|
||||
StackStringData sd2(v2);
|
||||
return same(&sd2);
|
||||
}
|
||||
|
||||
@@ -3100,12 +3100,12 @@ void Variant::unserialize(VariableUnserializer *uns,
|
||||
throw Exception("Mangled private object property");
|
||||
}
|
||||
}
|
||||
String k(kdata + subLen, ksize - subLen, CopyString);
|
||||
String k(kdata + subLen, ksize - subLen, AttachLiteral);
|
||||
if (kdata[1] == '*') {
|
||||
unserializeProp(uns, obj.get(), k, clsName, key, i + 1);
|
||||
} else {
|
||||
unserializeProp(uns, obj.get(), k,
|
||||
String(kdata + 1, subLen - 2, CopyString),
|
||||
String(kdata + 1, subLen - 2, AttachLiteral),
|
||||
key, i + 1);
|
||||
}
|
||||
} else {
|
||||
|
||||
@@ -69,7 +69,7 @@ void ThriftBuffer::write(CStrRef data) {
|
||||
|
||||
void ThriftBuffer::flush() {
|
||||
*m_p = '\0';
|
||||
String data(m_buf, m_p - m_buf, CopyString);
|
||||
String data(m_buf, m_p - m_buf, AttachLiteral);
|
||||
m_p = m_buf;
|
||||
flushImpl(data);
|
||||
}
|
||||
@@ -210,7 +210,7 @@ void ThriftBuffer::read(std::string &data) {
|
||||
}
|
||||
|
||||
void ThriftBuffer::write(const std::string &data) {
|
||||
write(String(data.data(), data.size(), CopyString));
|
||||
write(String(data.data(), data.size(), AttachLiteral));
|
||||
}
|
||||
|
||||
void ThriftBuffer::read(std::vector<std::string> &data) {
|
||||
|
||||
@@ -742,13 +742,13 @@ bool BreakPointInfo::MatchClass(const char *fcls, const std::string &bcls,
|
||||
return Match(fcls, 0, bcls, true, true);
|
||||
}
|
||||
|
||||
StackStringData sdBClsName(bcls.c_str(), CopyString);
|
||||
StackStringData sdBClsName(bcls.c_str());
|
||||
VM::Class* clsB = VM::Unit::lookupClass(&sdBClsName);
|
||||
StackStringData sdFClsName(fcls, CopyString);
|
||||
StackStringData sdFClsName(fcls);
|
||||
VM::Class* clsF = VM::Unit::lookupClass(&sdFClsName);
|
||||
if (!clsB) return false;
|
||||
if (clsB == clsF) return true;
|
||||
StackStringData sdFuncName(func, CopyString);
|
||||
StackStringData sdFuncName(func);
|
||||
VM::Func* f = clsB->lookupMethod(&sdFuncName);
|
||||
if (!f) return false;
|
||||
return (f->baseCls() == clsF);
|
||||
@@ -773,8 +773,8 @@ bool BreakPointInfo::Match(const char *haystack, int haystack_len,
|
||||
|
||||
Variant matches;
|
||||
Variant r = preg_match(String(needle.c_str(), needle.size(),
|
||||
CopyString),
|
||||
String(haystack, haystack_len, CopyString),
|
||||
AttachLiteral),
|
||||
String(haystack, haystack_len, AttachLiteral),
|
||||
matches);
|
||||
return r.same(1);
|
||||
}
|
||||
|
||||
@@ -222,7 +222,7 @@ void CmdInstrument::validateAndWriteToTable(DebuggerProxy *proxy) {
|
||||
(*tablePC)[(int64_t)pc] = inj;
|
||||
}
|
||||
if (ipi->m_locType == InstPointInfo::LocFuncEntry) {
|
||||
StackStringData sd(ipi->m_func.c_str(), ipi->m_func.size(), CopyString);
|
||||
StackStringData sd(ipi->m_func.c_str(), ipi->m_func.size(), AttachLiteral);
|
||||
const StringData* sdCache = VM::InjectionCache::GetStringData(&sd);
|
||||
if (tableFEntry == nullptr) {
|
||||
tableFEntry = new VM::InjectionTableSD();
|
||||
|
||||
@@ -1365,7 +1365,7 @@ void DebuggerClient::print(CStrRef msg) {
|
||||
name(msg); \
|
||||
} \
|
||||
void DebuggerClient::name(const std::string &msg) { \
|
||||
name(String(msg.data(), msg.length(), CopyString)); \
|
||||
name(String(msg.data(), msg.length(), AttachLiteral)); \
|
||||
} \
|
||||
|
||||
IMPLEMENT_COLOR_OUTPUT(help, stdout, HelpColor);
|
||||
@@ -1378,7 +1378,7 @@ IMPLEMENT_COLOR_OUTPUT(error, stderr, ErrorColor);
|
||||
|
||||
string DebuggerClient::wrap(const std::string &s) {
|
||||
TRACE(2, "DebuggerClient::wrap\n");
|
||||
String ret = StringUtil::WordWrap(String(s.c_str(), s.size(), CopyString),
|
||||
String ret = StringUtil::WordWrap(String(s.c_str(), s.size(), AttachLiteral),
|
||||
LineWidth - 4, "\n", true);
|
||||
return string(ret.data(), ret.size());
|
||||
}
|
||||
@@ -1423,8 +1423,8 @@ void DebuggerClient::helpCmds(const std::vector<const char *> &cmds) {
|
||||
|
||||
StringBuffer sb;
|
||||
for (unsigned int i = 0; i < cmds.size() - 1; i += 2) {
|
||||
String cmd(cmds[i], CopyString);
|
||||
String desc(cmds[i+1], CopyString);
|
||||
String cmd(cmds[i], AttachLiteral);
|
||||
String desc(cmds[i+1], AttachLiteral);
|
||||
|
||||
// two special formats
|
||||
if (cmd.empty() && desc.empty()) {
|
||||
|
||||
@@ -27,7 +27,7 @@ String DebuggerThriftBuffer::readImpl() {
|
||||
assert(m_size <= BUFFER_SIZE);
|
||||
int nread = m_socket->readImpl(m_buffer, m_size);
|
||||
m_buffer[nread] = '\0';
|
||||
return String(m_buffer, nread, CopyString);
|
||||
return String(m_buffer, nread, AttachLiteral);
|
||||
}
|
||||
|
||||
void DebuggerThriftBuffer::flushImpl(CStrRef data) {
|
||||
|
||||
@@ -479,7 +479,7 @@ void const_load_impl(struct cache_info *info,
|
||||
const char **p = objects;
|
||||
for (int i = 0; i < count; i++, p += 4) {
|
||||
String key(*p, (int)(int64_t)*(p+1), CopyString);
|
||||
String value(*(p+2), (int)(int64_t)*(p+3), CopyString);
|
||||
String value(*(p+2), (int)(int64_t)*(p+3), AttachLiteral);
|
||||
const_load_set(key, unserialize_from_string(value));
|
||||
}
|
||||
}
|
||||
@@ -491,7 +491,7 @@ void const_load_impl(struct cache_info *info,
|
||||
const char **p = thrifts;
|
||||
for (int i = 0; i < count; i++, p += 4) {
|
||||
String key(*p, (int)(int64_t)*(p+1), CopyString);
|
||||
String value(*(p+2), (int)(int64_t)*(p+3), CopyString);
|
||||
String value(*(p+2), (int)(int64_t)*(p+3), AttachLiteral);
|
||||
Variant success;
|
||||
Variant v = f_fb_thrift_unserialize(value, ref(success));
|
||||
if (same(success, false)) {
|
||||
@@ -507,7 +507,7 @@ void const_load_impl(struct cache_info *info,
|
||||
const char **p = others;
|
||||
for (int i = 0; i < count; i++, p += 4) {
|
||||
String key(*p, (int)(int64_t)*(p+1), CopyString);
|
||||
String value(*(p+2), (int)(int64_t)*(p+3), CopyString);
|
||||
String value(*(p+2), (int)(int64_t)*(p+3), AttachLiteral);
|
||||
Variant v = unserialize_from_string(value);
|
||||
if (same(v, false)) {
|
||||
throw Exception("bad apc archive, unserialize_from_string failed");
|
||||
@@ -574,7 +574,7 @@ void apc_load_impl(struct cache_info *info,
|
||||
item.key = *p;
|
||||
item.len = (int)(int64_t)*(p+1);
|
||||
// Strings would be copied into APC anyway.
|
||||
String value(*(p+2), (int)(int64_t)*(p+3), CopyString);
|
||||
String value(*(p+2), (int)(int64_t)*(p+3), AttachLiteral);
|
||||
value.checkStatic();
|
||||
s.constructPrime(value, item, false);
|
||||
}
|
||||
@@ -590,7 +590,7 @@ void apc_load_impl(struct cache_info *info,
|
||||
SharedStore::KeyValuePair &item = vars[i];
|
||||
item.key = *p;
|
||||
item.len = (int)(int64_t)*(p+1);
|
||||
String value(*(p+2), (int)(int64_t)*(p+3), CopyString);
|
||||
String value(*(p+2), (int)(int64_t)*(p+3), AttachLiteral);
|
||||
s.constructPrime(value, item, true);
|
||||
}
|
||||
s.prime(vars);
|
||||
@@ -605,7 +605,7 @@ void apc_load_impl(struct cache_info *info,
|
||||
SharedStore::KeyValuePair &item = vars[i];
|
||||
item.key = *p;
|
||||
item.len = (int)(int64_t)*(p+1);
|
||||
String value(*(p+2), (int)(int64_t)*(p+3), CopyString);
|
||||
String value(*(p+2), (int)(int64_t)*(p+3), AttachLiteral);
|
||||
Variant success;
|
||||
Variant v = f_fb_thrift_unserialize(value, ref(success));
|
||||
if (same(success, false)) {
|
||||
@@ -626,7 +626,7 @@ void apc_load_impl(struct cache_info *info,
|
||||
item.key = *p;
|
||||
item.len = (int)(int64_t)*(p+1);
|
||||
|
||||
String value(*(p+2), (int)(int64_t)*(p+3), CopyString);
|
||||
String value(*(p+2), (int)(int64_t)*(p+3), AttachLiteral);
|
||||
Variant v = unserialize_from_string(value);
|
||||
if (same(v, false)) {
|
||||
// we can't possibly get here if it was a boolean "false" that's
|
||||
@@ -727,7 +727,7 @@ void const_load_impl_compressed
|
||||
for (int i = 0; i < count; i++) {
|
||||
String key(p, object_lens[i + i + 2], CopyString);
|
||||
p += object_lens[i + i + 2] + 1;
|
||||
String value(p, object_lens[i + i + 3], CopyString);
|
||||
String value(p, object_lens[i + i + 3], AttachLiteral);
|
||||
const_load_set(key, unserialize_from_string(value));
|
||||
p += object_lens[i + i + 3] + 1;
|
||||
}
|
||||
@@ -745,7 +745,7 @@ void const_load_impl_compressed
|
||||
for (int i = 0; i < count; i++) {
|
||||
String key(p, thrift_lens[i + i + 2], CopyString);
|
||||
p += thrift_lens[i + i + 2] + 1;
|
||||
String value(p, thrift_lens[i + i + 3], CopyString);
|
||||
String value(p, thrift_lens[i + i + 3], AttachLiteral);
|
||||
Variant success;
|
||||
Variant v = f_fb_thrift_unserialize(value, ref(success));
|
||||
if (same(success, false)) {
|
||||
@@ -768,7 +768,7 @@ void const_load_impl_compressed
|
||||
for (int i = 0; i < count; i++) {
|
||||
String key(p, other_lens[i + i + 2], CopyString);
|
||||
p += other_lens[i + i + 2] + 1;
|
||||
String value(p, other_lens[i + i + 3], CopyString);
|
||||
String value(p, other_lens[i + i + 3], AttachLiteral);
|
||||
Variant v = unserialize_from_string(value);
|
||||
if (same(v, false)) {
|
||||
throw Exception("bad apc archive, unserialize_from_string failed");
|
||||
@@ -857,7 +857,7 @@ void apc_load_impl_compressed
|
||||
item.len = string_lens[i + i + 2];
|
||||
p += string_lens[i + i + 2] + 1; // skip \0
|
||||
// Strings would be copied into APC anyway.
|
||||
String value(p, string_lens[i + i + 3], CopyString);
|
||||
String value(p, string_lens[i + i + 3], AttachLiteral);
|
||||
value.checkStatic();
|
||||
s.constructPrime(value, item, false);
|
||||
p += string_lens[i + i + 3] + 1; // skip \0
|
||||
@@ -880,7 +880,7 @@ void apc_load_impl_compressed
|
||||
item.key = p;
|
||||
item.len = object_lens[i + i + 2];
|
||||
p += object_lens[i + i + 2] + 1; // skip \0
|
||||
String value(p, object_lens[i + i + 3], CopyString);
|
||||
String value(p, object_lens[i + i + 3], AttachLiteral);
|
||||
s.constructPrime(value, item, true);
|
||||
p += object_lens[i + i + 3] + 1; // skip \0
|
||||
}
|
||||
@@ -902,7 +902,7 @@ void apc_load_impl_compressed
|
||||
item.key = p;
|
||||
item.len = thrift_lens[i + i + 2];
|
||||
p += thrift_lens[i + i + 2] + 1; // skip \0
|
||||
String value(p, thrift_lens[i + i + 3], CopyString);
|
||||
String value(p, thrift_lens[i + i + 3], AttachLiteral);
|
||||
Variant success;
|
||||
Variant v = f_fb_thrift_unserialize(value, ref(success));
|
||||
if (same(success, false)) {
|
||||
@@ -929,7 +929,7 @@ void apc_load_impl_compressed
|
||||
item.key = p;
|
||||
item.len = other_lens[i + i + 2];
|
||||
p += other_lens[i + i + 2] + 1; // skip \0
|
||||
String value(p, other_lens[i + i + 3], CopyString);
|
||||
String value(p, other_lens[i + i + 3], AttachLiteral);
|
||||
Variant v = unserialize_from_string(value);
|
||||
if (same(v, false)) {
|
||||
// we can't possibly get here if it was a boolean "false" that's
|
||||
|
||||
@@ -646,10 +646,10 @@ public:
|
||||
|
||||
switch (t->method) {
|
||||
case PHP_CURL_STDOUT:
|
||||
echo(String(data, length, CopyString));
|
||||
echo(String(data, length, AttachLiteral));
|
||||
break;
|
||||
case PHP_CURL_FILE:
|
||||
return t->fp->write(String(data, length, CopyString), length);
|
||||
return t->fp->write(String(data, length, AttachLiteral), length);
|
||||
case PHP_CURL_RETURN:
|
||||
if (length > 0) {
|
||||
t->buf.append(data, (int)length);
|
||||
@@ -680,11 +680,11 @@ public:
|
||||
if (ch->m_write.method == PHP_CURL_RETURN && length > 0) {
|
||||
ch->m_write.buf.append(data, (int)length);
|
||||
} else {
|
||||
echo(String(data, length, CopyString));
|
||||
echo(String(data, length, AttachLiteral));
|
||||
}
|
||||
break;
|
||||
case PHP_CURL_FILE:
|
||||
return t->fp->write(String(data, length, CopyString), length);
|
||||
return t->fp->write(String(data, length, AttachLiteral), length);
|
||||
case PHP_CURL_USER:
|
||||
{
|
||||
Variant ret = ch->do_callback(
|
||||
|
||||
@@ -47,11 +47,11 @@ String f_intl_get_error_message() {
|
||||
if (!s_intl_error->m_error.custom_error_message.empty()) {
|
||||
return s_intl_error->m_error.custom_error_message;
|
||||
}
|
||||
return String(u_errorName(s_intl_error->m_error.code), CopyString);
|
||||
return String(u_errorName(s_intl_error->m_error.code), AttachLiteral);
|
||||
}
|
||||
|
||||
String f_intl_error_name(int64_t error_code) {
|
||||
return String(u_errorName((UErrorCode)error_code), CopyString);
|
||||
return String(u_errorName((UErrorCode)error_code), AttachLiteral);
|
||||
}
|
||||
|
||||
bool f_intl_is_failure(int64_t error_code) {
|
||||
@@ -222,7 +222,7 @@ int64_t c_Collator::t_geterrorcode() {
|
||||
}
|
||||
|
||||
String c_Collator::t_geterrormessage() {
|
||||
return String(u_errorName(m_errcode.code), CopyString);
|
||||
return String(u_errorName(m_errcode.code), AttachLiteral);
|
||||
}
|
||||
|
||||
String c_Collator::t_getlocale(int64_t type /* = 0 */) {
|
||||
@@ -234,7 +234,7 @@ String c_Collator::t_getlocale(int64_t type /* = 0 */) {
|
||||
String ret(
|
||||
(char*)ucol_getLocaleByType(m_ucoll, (ULocDataLocaleType)type,
|
||||
&(m_errcode.code)),
|
||||
CopyString);
|
||||
AttachLiteral);
|
||||
if (U_FAILURE(m_errcode.code)) {
|
||||
m_errcode.custom_error_message = "Error getting locale by type";
|
||||
s_intl_error->m_error.code = m_errcode.code;
|
||||
|
||||
@@ -2414,7 +2414,7 @@ int pdo_parse_params(PDOStatement *stmt, CStrRef in, String &out) {
|
||||
if (query_type != PDO_PLACEHOLDER_POSITIONAL && bindno > params.size()) {
|
||||
int ok = 1;
|
||||
for (plc = placeholders; plc; plc = plc->next) {
|
||||
if (!params.exists(String(plc->pos, plc->len, CopyString))) {
|
||||
if (!params.exists(String(plc->pos, plc->len, AttachLiteral))) {
|
||||
ok = 0;
|
||||
break;
|
||||
}
|
||||
@@ -2442,7 +2442,7 @@ safe:
|
||||
if (query_type == PDO_PLACEHOLDER_POSITIONAL) {
|
||||
vparam = params[plc->bindno];
|
||||
} else {
|
||||
vparam = params[String(plc->pos, plc->len, CopyString)];
|
||||
vparam = params[String(plc->pos, plc->len, AttachLiteral)];
|
||||
}
|
||||
if (vparam.isNull()) {
|
||||
/* parameter was not defined */
|
||||
@@ -2545,7 +2545,7 @@ rewrite:
|
||||
|
||||
for (plc = placeholders; plc; plc = plc->next) {
|
||||
int skip_map = 0;
|
||||
String name(plc->pos, plc->len, CopyString);
|
||||
String name(plc->pos, plc->len, AttachLiteral);
|
||||
|
||||
/* check if bound parameter is already available */
|
||||
if (!strcmp(name.c_str(), "?") ||
|
||||
@@ -2577,7 +2577,7 @@ rewrite:
|
||||
newbuffer_len = in.size();
|
||||
|
||||
for (plc = placeholders; plc; plc = plc->next) {
|
||||
String name(plc->pos, plc->len, CopyString);
|
||||
String name(plc->pos, plc->len, AttachLiteral);
|
||||
stmt->bound_param_map.set(plc->bindno, name);
|
||||
plc->quoted = "?";
|
||||
}
|
||||
|
||||
@@ -466,7 +466,7 @@ void f_passthru(CStrRef command, VRefParam return_var /* = null */) {
|
||||
if (len == -1 && errno == EINTR) continue;
|
||||
if (len <= 0) break; // break on error or EOF
|
||||
buffer[len] = '\0';
|
||||
echo(String(buffer, len, CopyString));
|
||||
echo(String(buffer, len, AttachLiteral));
|
||||
}
|
||||
int ret = ctx.exit();
|
||||
if (WIFEXITED(ret)) ret = WEXITSTATUS(ret);
|
||||
|
||||
@@ -316,7 +316,7 @@ String SessionModule::create_sid() {
|
||||
to_read : (int)sizeof(buf)));
|
||||
if (n <= 0) break;
|
||||
if (!f_hash_update(context,
|
||||
String((const char *)rbuf, n, CopyString))) {
|
||||
String((const char *)rbuf, n, AttachLiteral))) {
|
||||
Logger::Error("hash_update() failed");
|
||||
::close(fd);
|
||||
return String();
|
||||
|
||||
@@ -965,7 +965,7 @@ void c_SimpleXMLElement::t_offsetunset(CVarRef index) {
|
||||
|
||||
if (m_attributes.toArray().exists(name) && m_node) {
|
||||
for (xmlAttrPtr attr = m_node->properties; attr; attr = attr->next) {
|
||||
if (String((char*)attr->name, xmlStrlen(attr->name), CopyString) ==
|
||||
if (String((char*)attr->name, xmlStrlen(attr->name), AttachLiteral) ==
|
||||
name) {
|
||||
xmlUnlinkNode((xmlNodePtr)attr);
|
||||
break;
|
||||
|
||||
@@ -476,9 +476,9 @@ static bool do_request(c_SoapClient *client, xmlDoc *request,
|
||||
client->m_last_request = String((char*)buf, buf_size, CopyString);
|
||||
}
|
||||
response = client->o_invoke_few_args(s___dorequest, -1, 5,
|
||||
String(buf, buf_size, CopyString),
|
||||
String(location, CopyString),
|
||||
String(action, CopyString),
|
||||
String(buf, buf_size, AttachLiteral),
|
||||
String(location, AttachLiteral),
|
||||
String(action, AttachLiteral),
|
||||
version, one_way);
|
||||
if (!response.isString()) {
|
||||
if (client->m_soap_fault.isNull()) {
|
||||
@@ -1774,7 +1774,7 @@ static void send_soap_server_fault(sdlFunctionPtr function, Variant fault,
|
||||
xmlChar *buf; int size;
|
||||
xmlDocDumpMemory(doc_return, &buf, &size);
|
||||
if (buf) {
|
||||
echo(String((const char *)buf, size, CopyString));
|
||||
echo(String((const char *)buf, size, AttachLiteral));
|
||||
xmlFree(buf);
|
||||
}
|
||||
xmlFreeDoc(doc_return);
|
||||
@@ -2087,16 +2087,16 @@ void c_SoapServer::t_handle(CStrRef request /* = null_string */) {
|
||||
if (!data || !*data || !size) {
|
||||
return;
|
||||
}
|
||||
req = String(data, size, CopyString);
|
||||
req = String(data, size, AttachLiteral);
|
||||
|
||||
SystemGlobals *g = (SystemGlobals*)get_global_variables();
|
||||
if (g->GV(_SERVER).toArray().exists(s_HTTP_CONTENT_ENCODING)) {
|
||||
String encoding = g->GV(_SERVER)[s_HTTP_CONTENT_ENCODING];
|
||||
Variant ret;
|
||||
if (encoding == "gzip" || encoding == "x-gzip") {
|
||||
ret = f_gzinflate(String(data, size, CopyString));
|
||||
ret = f_gzinflate(String(data, size, AttachLiteral));
|
||||
} else if (encoding == "deflate") {
|
||||
ret = f_gzuncompress(String(data, size, CopyString));
|
||||
ret = f_gzuncompress(String(data, size, AttachLiteral));
|
||||
} else {
|
||||
raise_warning("Request is encoded with unknown compression '%s'",
|
||||
encoding.data());
|
||||
@@ -2252,7 +2252,7 @@ void c_SoapServer::t_handle(CStrRef request /* = null_string */) {
|
||||
}
|
||||
output_xml_header(soap_version);
|
||||
if (buf) {
|
||||
echo(String((char*)buf, size, CopyString));
|
||||
echo(String((char*)buf, size, AttachLiteral));
|
||||
xmlFree(buf);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -105,7 +105,7 @@ Variant f_stream_copy_to_stream(CObjRef source, CObjRef dest,
|
||||
if (rbytes == 0) break;
|
||||
if (rbytes < 0) return false;
|
||||
buf[rbytes] = '\0';
|
||||
if (destFile->write(String(buf, rbytes, CopyString)) != rbytes) {
|
||||
if (destFile->write(String(buf, rbytes, AttachLiteral)) != rbytes) {
|
||||
return false;
|
||||
}
|
||||
cbytes += rbytes;
|
||||
|
||||
@@ -145,7 +145,7 @@ static void url_encode_array(StringBuffer &ret, CVarRef varr,
|
||||
new_prefix += key_suffix;
|
||||
new_prefix += "%5B";
|
||||
url_encode_array(ret, data, seen_arrs, String(),
|
||||
new_prefix.detach(), String("%5D", CopyString),
|
||||
new_prefix.detach(), String("%5D", AttachLiteral),
|
||||
arg_sep);
|
||||
} else {
|
||||
if (!ret.empty()) {
|
||||
|
||||
@@ -874,7 +874,7 @@ int64_t f_xml_get_error_code(CObjRef parser) {
|
||||
|
||||
String f_xml_error_string(int code) {
|
||||
char * str = (char *)XML_ErrorString((XML_Error)/*(int)*/code);
|
||||
return String(str, CopyString);
|
||||
return String(str, AttachLiteral);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@@ -1130,7 +1130,7 @@ Variant parse_php_serialized(AsmState& as) {
|
||||
// String wants a null, and dereferences one past the size we give
|
||||
// it.
|
||||
buffer.push_back('\0');
|
||||
String data(&buffer[0], buffer.size() - 1, CopyString);
|
||||
String data(&buffer[0], buffer.size() - 1, AttachLiteral);
|
||||
return unserialize_from_string(data);
|
||||
}
|
||||
|
||||
|
||||
@@ -112,8 +112,8 @@ const Injection* InjectionCache::getInjectionImpl(const StringData* code,
|
||||
|
||||
const Injection* InjectionCache::getInjectionImpl(const std::string& code,
|
||||
const std::string& desc) {
|
||||
StackStringData sdCode(code.c_str(), code.size(), CopyString);
|
||||
StackStringData sdDesc(desc.c_str(), desc.size(), CopyString);
|
||||
StackStringData sdCode(code.c_str(), code.size(), AttachLiteral);
|
||||
StackStringData sdDesc(desc.c_str(), desc.size(), AttachLiteral);
|
||||
return getInjectionImpl(&sdCode, &sdDesc);
|
||||
}
|
||||
|
||||
|
||||
@@ -48,7 +48,7 @@ static inline void instHookSD(int type, const StringData* sd) {
|
||||
}
|
||||
|
||||
static inline void instHookStr(int type, const char* str) {
|
||||
StackStringData sd(str, CopyString);
|
||||
StackStringData sd(str, AttachLiteral);
|
||||
instHookSD(type, &sd);
|
||||
}
|
||||
|
||||
|
||||
@@ -14,9 +14,8 @@
|
||||
+----------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
#include "runtime/vm/repo_helpers.h"
|
||||
|
||||
#include "runtime/vm/repo.h"
|
||||
#include "runtime/vm/repo_helpers.h"
|
||||
#include "runtime/vm/blob_helper.h"
|
||||
#include "runtime/base/builtin_functions.h"
|
||||
|
||||
@@ -381,7 +380,7 @@ void RepoQuery::getStaticString(int iCol, StringData*& s) {
|
||||
const char* text;
|
||||
size_t size;
|
||||
getText(iCol, text, size);
|
||||
StackStringData sd(text, size, CopyString);
|
||||
StackStringData sd(text, size, AttachLiteral);
|
||||
s = StringData::GetStaticString(&sd);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,7 +21,6 @@
|
||||
#include <sqlite3.h>
|
||||
|
||||
#include "runtime/base/md5.h"
|
||||
#include "runtime/vm/core_types.h"
|
||||
|
||||
namespace HPHP {
|
||||
namespace VM {
|
||||
@@ -63,7 +62,7 @@ class RepoExc : public std::exception {
|
||||
|
||||
class RepoStmt {
|
||||
public:
|
||||
explicit RepoStmt(Repo& repo);
|
||||
RepoStmt(Repo& repo);
|
||||
~RepoStmt();
|
||||
private:
|
||||
void finalize();
|
||||
@@ -85,7 +84,7 @@ class RepoStmt {
|
||||
// queries outside of transactions are fraught with peril.
|
||||
class RepoQuery {
|
||||
public:
|
||||
explicit RepoQuery(RepoStmt& stmt)
|
||||
RepoQuery(RepoStmt& stmt)
|
||||
: m_stmt(stmt), m_row(false), m_done(false) {
|
||||
assert(m_stmt.prepared());
|
||||
}
|
||||
@@ -194,7 +193,7 @@ class RepoTxnQuery : public RepoQuery {
|
||||
|
||||
class RepoProxy {
|
||||
public:
|
||||
explicit RepoProxy(Repo& repo) : m_repo(repo) {}
|
||||
RepoProxy(Repo& repo) : m_repo(repo) {}
|
||||
~RepoProxy() {}
|
||||
|
||||
protected:
|
||||
|
||||
@@ -4330,7 +4330,7 @@ void CodeGenerator::cgLdClsPropAddrCached(IRInstruction* inst) {
|
||||
|
||||
string sds(Util::toLower(clsNameString->data()) + ":" +
|
||||
string(propNameString->data(), propNameString->size()));
|
||||
StackStringData sd(sds.c_str(), sds.size(), CopyString);
|
||||
StackStringData sd(sds.c_str(), sds.size(), AttachLiteral);
|
||||
CacheHandle ch = SPropCache::alloc(&sd);
|
||||
|
||||
auto dstReg = dst->getReg();
|
||||
|
||||
@@ -7778,7 +7778,7 @@ void TranslatorX64::emitStaticPropInlineLookup(const NormalizedInstruction& i,
|
||||
const StringData* clsName = cls->preClass()->name();
|
||||
string sds(Util::toLower(clsName->data()) + ":" +
|
||||
string(propName->data(), propName->size()));
|
||||
StackStringData sd(sds.c_str(), sds.size(), CopyString);
|
||||
StackStringData sd(sds.c_str(), sds.size(), AttachLiteral);
|
||||
ch = SPropCache::alloc(&sd);
|
||||
SKTRACE(1, i.source, "SPropInlineLookup %s %d\n", sd.data(), int(ch));
|
||||
|
||||
@@ -8677,9 +8677,12 @@ TranslatorX64::translateFPushFunc(const Tracelet& t,
|
||||
int startOfActRec = int(sizeof(Cell)) - int(sizeof(ActRec));
|
||||
size_t funcOff = AROFF(m_func) + startOfActRec;
|
||||
size_t thisOff = AROFF(m_this) + startOfActRec;
|
||||
const Func* (*f)(CacheHandle, StringData*, const void*) = FuncCache::lookup;
|
||||
if (false) { // typecheck
|
||||
StackStringData sd("foo");
|
||||
const UNUSED Func* f = FuncCache::lookup(ch, &sd);
|
||||
}
|
||||
SKTRACE(1, i.source, "ch %d\n", ch);
|
||||
EMIT_CALL(a, f, IMM(ch), V(inLoc), IMM(0));
|
||||
EMIT_CALL(a, FuncCache::lookup, IMM(ch), V(inLoc));
|
||||
recordCall(i);
|
||||
emitVStackStore(a, i, rax, funcOff, sz::qword);
|
||||
emitVStackStoreImm(a, i, 0, thisOff, sz::qword, &m_regMap);
|
||||
@@ -9458,8 +9461,14 @@ TranslatorX64::translateFPushFuncD(const Tracelet& t,
|
||||
a.test_reg64_reg64(r(scratch), r(scratch));
|
||||
{
|
||||
UnlikelyIfBlock ifNull(CC_Z, a, astubs);
|
||||
const Func* (*func)(StringData*) = FixedFuncCache::lookupUnknownFunc;
|
||||
EMIT_CALL(astubs, TCA(func), IMM(uintptr_t(name)));
|
||||
|
||||
if (false) { // typecheck
|
||||
StackStringData sd("foo");
|
||||
FixedFuncCache::lookupUnknownFunc(&sd);
|
||||
}
|
||||
|
||||
EMIT_CALL(astubs, TCA(FixedFuncCache::lookupUnknownFunc),
|
||||
IMM(uintptr_t(name)));
|
||||
recordReentrantStubCall(i);
|
||||
emitMovRegReg(astubs, rax, r(scratch));
|
||||
}
|
||||
|
||||
@@ -202,7 +202,7 @@ bool TestCppBase::TestString() {
|
||||
VS(String("test").rvalAt(2).c_str(), "s");
|
||||
String s = "test";
|
||||
s.lvalAt(2) = "";
|
||||
VS(s, String("te\0t", 4, CopyString));
|
||||
VS(s, String("te\0t", 4, AttachLiteral));
|
||||
s.lvalAt(2) = "zz";
|
||||
VS(s, "tezt");
|
||||
s.lvalAt(5) = "q";
|
||||
|
||||
@@ -213,7 +213,7 @@ bool TestExtFb::test_fb_utf8ize() {
|
||||
}
|
||||
{
|
||||
// We intentionally consider null bytes invalid sequences.
|
||||
Variant s = String("abc\0def", 7, CopyString);
|
||||
Variant s = String("abc\0def", 7, AttachLiteral);
|
||||
VERIFY(f_fb_utf8ize(ref(s)));
|
||||
if (RuntimeOption::Utf8izeReplace) {
|
||||
VS(s, "abc\uFFFD""def");
|
||||
@@ -259,7 +259,7 @@ bool TestExtFb::test_fb_utf8_strlen() {
|
||||
// byte then continues parsing.
|
||||
RuntimeOption::Utf8izeReplace = (i == 0);
|
||||
{
|
||||
Variant s = String("abc\0def", 7, CopyString);
|
||||
Variant s = String("abc\0def", 7, AttachLiteral);
|
||||
VS(s.toString().size(), 7);
|
||||
VS(f_fb_utf8_strlen(s), 7);
|
||||
|
||||
|
||||
@@ -373,7 +373,7 @@ bool TestExtIcu_ucsdet::test_utf16() {
|
||||
"d\x00!\x00";
|
||||
|
||||
// Take off 1 byte for the NUL at the end of the char[].
|
||||
String utf16Str(utf16, sizeof utf16 - 1, CopyString);
|
||||
String utf16Str(utf16, sizeof utf16 - 1, AttachLiteral);
|
||||
VERIFY(detect_and_convert_to_utf8(
|
||||
utf16Str,
|
||||
"\ufeffHello, world!") == true);
|
||||
|
||||
@@ -213,10 +213,10 @@ bool TestExtMisc::test_unpack() {
|
||||
// Also covered in TestCodeRun::TestExtMisc
|
||||
|
||||
String iFF = f_str_repeat("\xFF", sizeof(int));
|
||||
String le32_FF("\xFF\x00\x00\x00", 4, CopyString);
|
||||
String be32_FF("\x00\x00\x00\xFF", 4, CopyString);
|
||||
String le16_FF("\xFF\x00", 2, CopyString);
|
||||
String be16_FF("\x00\xFF", 2, CopyString);
|
||||
String le32_FF("\xFF\x00\x00\x00", 4, AttachLiteral);
|
||||
String be32_FF("\x00\x00\x00\xFF", 4, AttachLiteral);
|
||||
String le16_FF("\xFF\x00", 2, AttachLiteral);
|
||||
String be16_FF("\x00\xFF", 2, AttachLiteral);
|
||||
|
||||
uint32_t endian_check = 1;
|
||||
bool le = ((char*)&endian_check)[0];
|
||||
|
||||
@@ -299,7 +299,7 @@ bool TestExtProcess::test_proc_open() {
|
||||
{
|
||||
File *f = pipes[0].toObject().getTyped<File>();
|
||||
VERIFY(f->valid());
|
||||
String s("<?php print(getenv('some_option')); ?>", CopyString);
|
||||
String s("<?php print(getenv('some_option')); ?>", AttachLiteral);
|
||||
f->write(s);
|
||||
f->close();
|
||||
}
|
||||
|
||||
@@ -133,7 +133,7 @@ bool TestExtString::test_stringdata() {
|
||||
|
||||
bool TestExtString::test_addcslashes() {
|
||||
VS(f_addcslashes("ABCDEFGH\n", "A..D\n"), "\\A\\B\\C\\DEFGH\\n");
|
||||
VS(f_addcslashes(String("\x00\x0D\n", 3, CopyString), null_string),
|
||||
VS(f_addcslashes(String("\x00\x0D\n", 3, AttachLiteral), null_string),
|
||||
"\\000\\r\\n");
|
||||
return Count(true);
|
||||
}
|
||||
@@ -441,8 +441,8 @@ bool TestExtString::test_str_pad() {
|
||||
VS(f_str_pad(input, 10, "-=", k_STR_PAD_LEFT), "-=-=-Alien");
|
||||
VS(f_str_pad(input, 10, "_", k_STR_PAD_BOTH), "__Alien___");
|
||||
VS(f_str_pad(input, 6 , "___"), "Alien_");
|
||||
VS(f_str_pad(input, 6 , String("\0", 1, CopyString)),
|
||||
String("Alien\0", 6, CopyString));
|
||||
VS(f_str_pad(input, 6 , String("\0", 1, AttachLiteral)),
|
||||
String("Alien\0", 6, AttachLiteral));
|
||||
return Count(true);
|
||||
}
|
||||
|
||||
@@ -517,7 +517,7 @@ bool TestExtString::test_htmlspecialchars() {
|
||||
VS(f_bin2hex(f_htmlspecialchars("\xA0", k_ENT_COMPAT)), "a0");
|
||||
VS(f_bin2hex(f_htmlspecialchars("\xc2\xA0", k_ENT_COMPAT, "")), "c2a0");
|
||||
VS(f_bin2hex(f_htmlspecialchars("\xc2\xA0", k_ENT_COMPAT, "UTF-8")), "c2a0");
|
||||
String zfoo = String("\0foo", 4, CopyString);
|
||||
String zfoo = String("\0foo", 4, AttachLiteral);
|
||||
VS(f_htmlspecialchars(zfoo, k_ENT_COMPAT), zfoo);
|
||||
VS(f_fb_htmlspecialchars(zfoo, k_ENT_COMPAT), zfoo);
|
||||
|
||||
|
||||
@@ -45,7 +45,7 @@ bool TestExtUrl::test_base64_decode() {
|
||||
VS(f_base64_decode("VGhpcyBpcyBhbiBlbmNvZGVkIHN0cmluZw=="),
|
||||
"This is an encoded string");
|
||||
VERIFY(same(f_base64_decode("BgAYdjk="),
|
||||
String("\006\0\030v9", 5, CopyString)));
|
||||
String("\006\0\030v9", 5, AttachLiteral)));
|
||||
VERIFY(!same(f_base64_decode("dGVzdA=="),
|
||||
f_base64_decode("dGVzdA==CORRUPT")));
|
||||
return Count(true);
|
||||
@@ -54,7 +54,7 @@ bool TestExtUrl::test_base64_decode() {
|
||||
bool TestExtUrl::test_base64_encode() {
|
||||
VS(f_base64_encode("This is an encoded string"),
|
||||
"VGhpcyBpcyBhbiBlbmNvZGVkIHN0cmluZw==");
|
||||
VS(f_base64_encode(String("\006\0\030v9", 5, CopyString)), "BgAYdjk=");
|
||||
VS(f_base64_encode(String("\006\0\030v9", 5, AttachLiteral)), "BgAYdjk=");
|
||||
return Count(true);
|
||||
}
|
||||
|
||||
|
||||
@@ -289,9 +289,7 @@ bool TestExtVariable::test_var_export() {
|
||||
VS(f_var_export(s, true), cr);
|
||||
}
|
||||
{
|
||||
Variant v = CREATE_MAP3(String("\0", 1, CopyString), "null",
|
||||
"", "empty",
|
||||
"0", "nul");
|
||||
Variant v = CREATE_MAP3(String("\0", 1, AttachLiteral),"null","","empty","0", "nul");
|
||||
VS(f_var_export(v, true),
|
||||
"array (\n"
|
||||
" '' . \"\\0\" . '' => 'null',\n"
|
||||
@@ -376,7 +374,7 @@ bool TestExtVariable::test_unserialize() {
|
||||
VS(obj.o_get("name"), "value");
|
||||
}
|
||||
{
|
||||
Variant v = unserialize_from_string(String("O:8:\"stdClass\":1:{s:7:\"\0*\0name\";s:5:\"value\";}", 45, CopyString));
|
||||
Variant v = unserialize_from_string(String("O:8:\"stdClass\":1:{s:7:\"\0*\0name\";s:5:\"value\";}", 45, AttachLiteral));
|
||||
VERIFY(v.is(KindOfObject));
|
||||
Object obj = v.toObject();
|
||||
VS(obj->o_getClassName(), "stdClass");
|
||||
|
||||
@@ -277,13 +277,13 @@ bool TestExtZlib::test_nzcompress() {
|
||||
}
|
||||
|
||||
bool TestExtZlib::test_nzuncompress() {
|
||||
String s("garbage stuff", CopyString);
|
||||
String s("garbage stuff", AttachLiteral);
|
||||
Variant v = f_nzuncompress(s);
|
||||
if (v != Variant(false)) {
|
||||
return Count(false);
|
||||
}
|
||||
|
||||
String empty("", CopyString);
|
||||
String empty("", AttachLiteral);
|
||||
String c(f_nzcompress(empty).asStrRef());
|
||||
String d(f_nzuncompress(c).asStrRef());
|
||||
if (d != empty) {
|
||||
@@ -307,13 +307,13 @@ bool TestExtZlib::test_lz4hccompress() {
|
||||
|
||||
bool TestExtZlib::test_lz4uncompress() {
|
||||
// first test uncompressing invalid string
|
||||
String s("invalid compressed string", CopyString);
|
||||
String s("invalid compressed string", AttachLiteral);
|
||||
Variant v = f_lz4uncompress(s);
|
||||
if (v != Variant(false)) {
|
||||
return Count(false);
|
||||
}
|
||||
// try uncompressing empty string
|
||||
String empty("", CopyString);
|
||||
String empty("", AttachLiteral);
|
||||
v = f_lz4uncompress(empty);
|
||||
if (v != Variant(false)) {
|
||||
return Count(false);
|
||||
|
||||
Referência em uma Nova Issue
Bloquear um usuário