Skip to content

Commit

Permalink
back port encoding patch
Browse files Browse the repository at this point in the history
  • Loading branch information
JerrySievert committed Mar 27, 2016
1 parent a624a59 commit cc29067
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 16 deletions.
14 changes: 7 additions & 7 deletions META.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "plv8",
"abstract": "A procedural language in JavaScript powered by V8",
"description": "plv8 is a trusted procedural language that is safe to use, fast to run and easy to develop.",
"version": "1.4.5",
"version": "1.4.6",
"maintainer": [
"Jerry Sievert <code@legitimatesounding.com>",
"Hitoshi Harada <umi.tanuki@gmail.com>"
Expand All @@ -24,21 +24,21 @@
},
"provides": {
"plv8": {
"file": "plv8--1.4.5.sql",
"file": "plv8--1.4.6.sql",
"docfile": "doc/plv8.md",
"version": "1.4.5",
"version": "1.4.6",
"abstract": "A procedural language in JavaScript"
},
"plcoffee": {
"file": "plcoffee--1.4.5.sql",
"file": "plcoffee--1.4.6.sql",
"docfile": "doc/plv8.md",
"version": "1.4.5",
"version": "1.4.6",
"abstract": "A procedural language in CoffeeScript"
},
"plls": {
"file": "plls--1.4.5.sql",
"file": "plls--1.4.6.sql",
"docfile": "doc/plv8.md",
"version": "1.4.5",
"version": "1.4.6",
"abstract": "A procedural language in LiveScript"
}
},
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# 'make static' will download v8 and build, then statically link to it.
#
#-----------------------------------------------------------------------------#
PLV8_VERSION = 1.4.5
PLV8_VERSION = 1.4.6

PG_CONFIG = pg_config
PGXS := $(shell $(PG_CONFIG) --pgxs)
Expand Down Expand Up @@ -52,7 +52,7 @@ endif
ifdef ENABLE_DEBUGGER_SUPPORT
OPT_ENABLE_DEBUGGER_SUPPORT = -DENABLE_DEBUGGER_SUPPORT
endif
OPTFLAGS = -O2
OPTFLAGS = -O2 -std=c++11 -fno-rtti
CCFLAGS = -Wall $(OPTFLAGS) $(OPT_ENABLE_DEBUGGER_SUPPORT)

ifdef V8_SRCDIR
Expand Down
2 changes: 2 additions & 0 deletions plv8.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <v8-debug.h>
#endif // ENABLE_DEBUGGER_SUPPORT
#include <vector>
#include <string>

extern "C" {
#include "postgres.h"
Expand Down Expand Up @@ -102,6 +103,7 @@ class CString
operator const char* () const { return m_str; }
const char* str(const char *ifnull = NULL) const
{ return m_str ? m_str : ifnull; }
static bool toStdString(v8::Handle<v8::Value> value, std::string &out);

private:
CString(const CString&);
Expand Down
18 changes: 11 additions & 7 deletions plv8_func.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "plv8.h"
#include "plv8_param.h"
#include <sstream>
#include <string>

extern "C" {
#define delete delete_
Expand Down Expand Up @@ -299,16 +300,19 @@ plv8_Elog(const Arguments& args)
return ThrowError("invalid error level");
}

std::ostringstream stream;

std::string msg;
std::string buf;
for (int i = 1; i < args.Length(); i++)
{
if (i > 1)
stream << ' ';
stream << CString(args[i]);
if (i > 1){
msg += " ";
}
if (!CString::toStdString(args[i],buf)){
return Undefined();
}
msg += buf;
}

const char *message = stream.str().c_str();
const char *message = msg.c_str();

if (elevel != ERROR)
{
Expand Down
12 changes: 12 additions & 0 deletions plv8_type.cc
Original file line number Diff line number Diff line change
Expand Up @@ -805,3 +805,15 @@ CString::~CString()
if (m_str != *m_utf8)
pfree(m_str);
}

bool CString::toStdString(v8::Handle<v8::Value> value, std::string &out)
{
if(value.IsEmpty()) return false;
auto obj = value->ToString();
String::Utf8Value utf8(obj);
if(*utf8) {
out = *utf8;
return true;
}
return false;
}

0 comments on commit cc29067

Please sign in to comment.