Hhvm: Fatal error: Call to undefined function with pgsql extension

Created on 8 Sep 2016  路  14Comments  路  Source: facebook/hhvm

HHVM Version

3.15 (and prior builds with the PocketRent/hhvm-pgsql pgsql.so extension)

Standalone code, or other way to reproduce the problem

  • pg_set_error_verbosity()
  • pg_set_client_encoding()

    Expected result

no errors

Actual result

Working on HHVM testing with pgsql I get the following errors with the PocketRent/hhvm-pgsql extension that is now included in the core as of 3.15

Fatal error: Call to undefined function pg_set_error_verbosity() in /joomla-cms/libraries/joomla/database/driver/postgresql.php on line 140
Fatal error: Call to unimplemented native function pg_set_client_encoding() in /joomla-cms/libraries/joomla/database/driver/postgresql.php on line 890

build demonstrating the first error (the second one only shows after the first is fixed)
https://travis-ci.org/photodude/joomla-cms/jobs/132726691

I understand that the pg_set_error_verbosity() and pg_set_client_encoding() functions are not yet implemented for various reasons...

What is the work around for this? These missing functions are causing problems for our PostgreSQL driver as we set the client encoding to UTF8 and specify the error verbosity.

(this is a rereport of the issue from PocketRent/hhvm-pgsql as per request from @simonwelsh)

Full list of differences from the Zend pgsql module can be found at this link https://github.com/PocketRent/hhvm-pgsql

mid-pri php5 incompatibility php7 incompatibility

Most helpful comment

Finally got HHVM to compile at home again, so will check @aorenste's solution tonight.

All 14 comments

If possible, could you include the link to the original issue as well?

@simonwelsh The second error there means you declared it in the the .php as native but you never actually implemented the function on the C++ side :P

Unfortunately, https://github.com/PocketRent/hhvm-pgsql/issues/115 no longer exists so I can't link to it. (or maybe I can?)

@Orvid @simonwelsh I'm still learning c++ but would the fix for pg_set_client_encoding() be as follows? (based off the pg_client_encoding() method)

static Variant HHVM_FUNCTION(pg_set_client_encoding, const Resource& connection) {
  auto pgsql = PGSQL::Get(connection);

  if (!pgsql) {
    FAIL_RETURN;
  }

  String ret(pgsql->set(clientEncoding(), CopyString);

  return ret;
}

and add the following line to void moduleInit() override {

 HHVM_FE(pg_set_client_encoding);

@photodude - Unfortunately not quite. pgsql->get().clientEncoding() ends up calling PQclientEncoding() to get the value. This needs to thread the code through to end up calling PQsetClientEncoding().

You want something like this (totally untested - but it compiles):

diff --git a/fbcode/hphp/runtime/ext/pgsql/pgsql.cpp b/fbcode/hphp/runtime/ext/pgsql/pgsql.cpp
--- a/fbcode/hphp/runtime/ext/pgsql/pgsql.cpp
+++ b/fbcode/hphp/runtime/ext/pgsql/pgsql.cpp
@@ -808,6 +808,17 @@
   return ret;
 }

+static int HHVM_FUNCTION(pg_set_client_encoding,
+  const Resource& connection, const String& enc) {
+  auto pgsql = PGSQL::Get(connection);
+
+  if (!pgsql) {
+    return -1;
+  }
+
+  return pgsql->get().setClientEncoding(enc.c_str()) ? 0 : -1;
+}
+
 static int64_t HHVM_FUNCTION(pg_transaction_status,
   const Resource& connection) {
   auto pgsql = PGSQL::Get(connection);
@@ -1708,6 +1719,7 @@
     HHVM_FE(pg_send_prepare);
     HHVM_FE(pg_send_query_params);
     HHVM_FE(pg_send_query);
+    HHVM_FE(pg_set_client_encoding);
     HHVM_FE(pg_transaction_status);
     HHVM_FE(pg_unescape_bytea);
     HHVM_FE(pg_version);
diff --git a/fbcode/hphp/runtime/ext/pgsql/pq.h b/fbcode/hphp/runtime/ext/pgsql/pq.h
--- a/fbcode/hphp/runtime/ext/pgsql/pq.h
+++ b/fbcode/hphp/runtime/ext/pgsql/pq.h
@@ -343,6 +343,10 @@
     return pg_encoding_to_char(enc);
   }

+  bool setClientEncoding(const char* enc) {
+    PQsetClientEncoding(m_conn, enc) == 0;
+  }
+
   int backendPID() {
     return PQbackendPID(m_conn);
   }

If you have a DB to test it on and verify that it works please let me know and I'll submit it.

@aorenste I currently don't have a local for HHVM to compile and test with. As for a DB I'm just testing against the Joomla unit test suite which has a pgsql DB.

I'll defer to the project on fixing these missing functions.

cc @simonwelsh (I would assign you the issue but GH doesn't like that)

Finally got HHVM to compile at home again, so will check @aorenste's solution tonight.

@aorenste Only change I needed to make was to add a return to setClientEncoding.

If you want to submit your diff, I'll get pg_set_error_verbosity working.

Thanks @simonwelsh I look forward to these fixes

@aorenste Have you submitted the patch for pg_set_client_encoding() with the corrections @simonwelsh mention?

@photodude - yes. See 88a4196.

Thanks @aorenste, I hadn't noticed that the fix for pg_set_client_encoding was included in the patch for pg_set_error_verbosity

@photodude No worries. It was more confusing but easier for me to just tweak his patch internally rather than submitting my own. :)

Was this page helpful?
0 / 5 - 0 ratings