How do I set up a new class in the Phalcon PHP internals? - php-extension

I decided to get my feet wet in the Phalcon internals by making a simple validator. I followed the definition of the other validators almost verbatim. So here is what I have in phalcon.c and phalcon.h:
phalcon.c:
zend_class_entry *phalcon_mvc_model_validator_stringlength_ce;
...
PHALCON_REGISTER_CLASS_EX(Phalcon\\Mvc\\Model\\Validator, StringLength, mvc_model_validator_stringlength, "phalcon\\mvc\\model\\validator", phalcon_mvc_model_validator_stringlength_method_entry, 0);
phalcon.h:
extern zend_class_entry *phalcon_mvc_model_validator_stringlength_ce;
...
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_mvc_model_validator_stringlength_validate, 0, 0, 1)
ZEND_ARG_INFO(0, record)
ZEND_END_ARG_INFO()
...
PHALCON_INIT_FUNCS(phalcon_mvc_model_validator_stringlength_method_entry){
PHP_ME(Phalcon_Mvc_Model_Validator_StringLength, validate, arginfo_phalcon_mvc_model_validator_stringlength_validate, ZEND_ACC_PUBLIC)
PHP_FE_END
};
At runtime I get the following warning:
PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php5/20090626/phalcon.so' - /usr/lib/php5/20090626/phalcon.so: undefined symbol: zim_Phalcon_Mvc_Model_Validator_StringLength_validate in Unknown on line 0
What am I missing?

also it's needed to add the method (function) prototype to phalcon.h:
https://github.com/phalcon/cphalcon/blob/master/dev/phalcon.h#L391
Add your .c file to config.m4 (if you're on a Unix/Linux platform):
https://github.com/phalcon/cphalcon/blob/master/dev/config.m4#L5
After that, a full recompilation is required:
phpize --clean
export CFLAGS="-g -O2 -fno-delete-null-pointer-checks"
phpize
./configure --enable-phalcon
make
sudo make install

Related

Error installing a .pro file, with Eigen, libigl dependencies on Debian

Im trying to install a .pro file using 'make' on Debian-9. The dependencies are Qt5, GSL, libigl, Eigen and Boost, which their latest versions are installed.
I used the following:
# cd build
# qmake -qt=qt5 ../qt/myfile.pro
# make
And here is the error I get:
../libigl/include/igl/copyleft/boolean/../cgal/order_facets_around_edge.cpp:203:36: error: ‘Eigen::PlainObjectBase<Derived>::PlainObjectBase() [with Derived = Eigen::Matrix<int, -1, 1>]’ is protected within this context
Eigen::PlainObjectBase<DerivedI> positive_order, negative_order;
^~~~~~~~~~~~~~
In file included from /usr/local/include/eigen3/Eigen/Core:457:0,
from ../libigl/include/igl/copyleft/boolean/mesh_boolean.h:15,
from ../src/mesh.cpp:12:
/usr/local/include/eigen3/Eigen/src/Core/PlainObjectBase.h:484:25: note: declared protected here
EIGEN_STRONG_INLINE PlainObjectBase() : m_storage()
^~~~~~~~~~~~~~~
In file included from ../libigl/include/igl/copyleft/boolean/../cgal/order_facets_around_edge.h:75:0,
from ../libigl/include/igl/copyleft/boolean/../cgal/propagate_winding_numbers.cpp:18,
from ../libigl/include/igl/copyleft/boolean/../cgal/propagate_winding_numbers.h:101,
from ../libigl/include/igl/copyleft/boolean/mesh_boolean.cpp:13,
from ../libigl/include/igl/copyleft/boolean/mesh_boolean.h:172,
from ../src/mesh.cpp:12:
../libigl/include/igl/copyleft/boolean/../cgal/order_facets_around_edge.cpp:203:52: error: ‘Eigen::PlainObjectBase<Derived>::PlainObjectBase() [with Derived = Eigen::Matrix<int, -1, 1>]’ is protected within this context
Eigen::PlainObjectBase<DerivedI> positive_order, negative_order;
^~~~~~~~~~~~~~
In file included from /usr/local/include/eigen3/Eigen/Core:457:0,
from ../libigl/include/igl/copyleft/boolean/mesh_boolean.h:15,
from ../src/mesh.cpp:12:
/usr/local/include/eigen3/Eigen/src/Core/PlainObjectBase.h:484:25: note: declared protected here
EIGEN_STRONG_INLINE PlainObjectBase() : m_storage()
^~~~~~~~~~~~~~~
Makefile:891: recipe for target 'mesh.o' failed
Could someone please kindly help me solving the issue here?
This line
Eigen::PlainObjectBase<DerivedI> positive_order, negative_order;
won't compile. It may have once compiled for older Eigen versions -- but this is not how Eigen-Base types are supposed to be used, so it likely was never working as intended (that is also the reason why Base-constructors where made protected in Eigen).
However, that line does not exist in the most recent order_facets_around_edge.cpp, so you appear to be using an outdated libigl version.

Unable to use libcurl with cffi on Windows 10

I am playing with the CFFI tutorial on Windows 10 and have installed the libcurl-devel package using msys2. I found a file libcurl.dll.a in the directory c:\msys2\usr\lib\ and added this directory to *foreign-library-directories* using:
(pushnew #P"c:/msys64/usr/lib/" *foreign-library-directories*
:test #'equal)
But if I try (use-foreign-library libcurl) I get the following error:
Unable to load foreign library (LIBCURL).
Error opening shared object "libcurl.dll"
What am I missing? I tried to point to libcurl.dll.a directly but the error stays the same:
(define-foreign-library libcurl
(:darwin (:or "libcurl.3.dylib" "libcurl.dylib"))
(:unix (:or "libcurl.so.3" "libcurl.so"))
(t "libcurl.dll.a"))
Here is the complete code as given in the tutorial:
(asdf:load-system :cffi)
;;; Nothing special about the "CFFI-USER" package. We're just
;;; using it as a substitute for your own CL package.
(defpackage :cffi-user
(:use :common-lisp :cffi))
(in-package :cffi-user)
(pushnew #P"c:/msys64/usr/lib/" *foreign-library-directories*
:test #'equal)
(define-foreign-library libcurl
(:darwin (:or "libcurl.3.dylib" "libcurl.dylib"))
(:unix (:or "libcurl.so.3" "libcurl.so"))
(t (:default "libcurl")))
(use-foreign-library libcurl)
EDIT
I am using SBCL 1.4.16 from the portacle package.
EDIT 2
Just for the sake of completeness. If I change define-foreign-library to
(define-foreign-library libcurl
(:darwin (:or "libcurl.3.dylib" "libcurl.dylib"))
(:unix (:or "libcurl.so.3" "libcurl.so"))
(t "libcurl.dll.a"))
the errors changes:
Unable to load foreign library (LIBCURL).
Error opening shared object "c:\\msys64\\usr\\lib\\libcurl.dll.a":
%1 ist keine zulässige Win32-Anwendung.
As far as I understand at least the file is found but seems not to be in the right format. I didn't find any further information about the difference between dynamic (.dll) and static (.dll.a) files with respect to cffi and don't have the resources at the moment to further investigate this.
Instead of using use-foreign-library, try loading load-foreign-library. It is lower level code, but it will allow you to experiment with files and paths.
Also use cygcheck to figure out what libcurl.dll depends on. Then make sure you have the components installed, and that they are in PATH.
Finally, check where libcurl.dll lives in your MSYS2. On my system it is in /c/msys64/mingw64/bin/libcurl-4.dll

error: no member named 'emplace' , when compiling Liquibook using make all

In file included from ./Market.h:6:
In file included from
/Users/shubhamsharma/projects/liquibook/src/book/depth_order_book.h:6:
/Users/shubhamsharma/projects/liquibook/src/book/order_book.h:559:17:
error: no member named 'emplace' in
'std::__1::multimap<liquibook::book::ComparablePrice,
liquibook::book::OrderTracker<std::__1::shared_ptr<orderentry::Order> >,
std::__1::less<liquibook::book::ComparablePrice>, std::__1::allocator<std::__1::pair<const
liquibook::book::ComparablePrice, liquibook::book::OrderTracker<std::__1::shared_ptr<orderentry::Order> > > >
>'
stopBids_.emplace(key, std::move(tracker));
I have set all the environment variables, Makefile is generated using MPC, The error comes after make all. I have tried upgrading my gcc to 4.9 but still the same error occurs. Please help!

geoCouch install: compiling failed

I have trouble with including geoCouch to running couchDB (1.6.1).
I followed the Instruction: https://github.com/couchbase/geocouch/#for-apache-couchdb
In the GeoCouch directory ($HOME/geocouch) I tried to compile:
COUCH_SRC=$HOME/apache-couchdb-1.6.1/src/couchdb make couchdb
and get the message:
/rebar -C rebar_couchdb.config compile
==> vtree (compile)
Compiling /home/ec2-user/geocouch/vtree/src/vtree_cleanup.erl failed:
/home/ec2-user/geocouch/vtree/src/vtree_cleanup.erl:16: can't find include file "couch_db.hrl"
/home/ec2-user/geocouch/vtree/src/vtree_cleanup.erl:41: undefined macro 'LOG_DEBUG/2'
/home/ec2-user/geocouch/vtree/src/vtree_cleanup.erl:18: function cleanup/2 undefined
/home/ec2-user/geocouch/vtree/src/vtree_cleanup.erl:26: spec for undefined function vtree_cleanup:cleanup/2
/home/ec2-user/geocouch/vtree/src/vtree_cleanup.erl:47: function cleanup_multiple/3 is unused
/home/ec2-user/geocouch/vtree/src/vtree_cleanup.erl:54: function cleanup_nodes/2 is unused
/home/ec2-user/geocouch/vtree/src/vtree_cleanup.erl:62: function member_of_nodes/2 is unused
/home/ec2-user/geocouch/vtree/src/vtree_cleanup.erl:75: function partition_nodes/3 is unused
"couch_db.hrl" is located in /home/ec2-user/apache-couchdb-1.6.1/src/couchdb
Does anyone know how to fix that? Help/idea?

GHC :: Linking agains sqlite3 fails on Windows

I created simple application, which uses sqlite3 as it's datastore back-end. I faced no problems when building and running it on Linux, but after I tried to build it on Windows, I see weird linking error:
Linking dist\build\hnotes\hnotes.exe ...
C:\Documents and Settings\Admin\Application Data\cabal\sqlite-0.5.2.2\ghc-7.0.4/libHSsqlite-0.5.2.2.
a(sqlite3-local.o):sqlite3-local.c:(.text+0x21): undefined reference to `sqlite3_temp_directory'
C:\Documents and Settings\Admin\Application Data\cabal\sqlite-0.5.2.2\ghc-7.0.4/libHSsqlite-0.5.2.2.
a(sqlite3-local.o):sqlite3-local.c:(.text+0x40): undefined reference to `sqlite3_temp_directory'
collect2: v ld 1
cabal.EXE: Error: some packages failed to install:
hnotes-0.1 failed during the building phase. The exception was:
ExitFailure 1
What may be wrong there? I suspect that qalite3.dll has to be added to linking stage, but have no idea how to do that. Adding --extra-lib-dirs=path-to-sqlite-dll doesn't help either (perhaps because I need to update my cabal file somehow, to support this?).
Not sure if It's a bug or not, but the error comes from the sqlite3.h include of the sqlite package.
A look in the file shows this
/*
** CAPI3REF: Name Of The Folder Holding Temporary Files {H10310} <S20000>
**
** If this global variable is made to point to a string which is
** the name of a folder (a.k.a. directory), then all temporary files
** created by SQLite will be placed in that directory. If this variable
** is a NULL pointer, then SQLite performs a search for an appropriate
** temporary file directory.
**
** It is not safe to modify this variable once a [database connection]
** has been opened. It is intended that this variable be set once
** as part of process initialization and before any SQLite interface
** routines have been call and remain unchanged thereafter.
*/
SQLITE_EXTERN char *sqlite3_temp_directory;
so it's declared as an extern. So simple test:
module Main where
import Database.SQLite
main
= do hwd <- openConnection "test"
closeConnection hwd
putStrLn "done"
This crashes during linking as expected with the error you have above.
So I created a small C test file foo.c
#include "sqlite-0.5.2.2\\include\\sqlite3-local.h"
char* sqlite3_temp_directory = "C:\\test2";
So I'm defining a temp_directory and then I pass the c file along during compilation of the haskell source
$ ghc test.hs foo.c
[1 of 1] Compiling Main ( test.hs, test.o )
Linking test.exe ...
and then running it also returns the expected result
$ ./test
done
So it seems that you just need to give a value for the sqlite3_temp_directory, which if you set it to a NULL pointer will use the TMP/TEMP etc variables as defined in the SQLLITE manual.
edit, follow up on why it worked on Linux but not on windows
In the sqlite package, there's a file sqlite3.c under the folder sqlite3.6. This provides a bunch of defaults for the sqlite package.
when on linux OS_UNIX is defined and when on linux it uses the defines under OS_WIN.
The function we're interested in is the function which sets the temporary directory. for unix this'll be unixGetTempname and for windows winGetTempname.
If you look at the implementation of both these functions, for the unix one it has list of directories that it'll try
static const char *azDirs[] = {
0,
"/var/tmp",
"/usr/tmp",
"/tmp",
".",
};
it tries to access them in order and the one it can write to it uses to generate a temporary folder in.
For windows however one of the first lines are:
if( sqlite3_temp_directory ){
sqlite3_snprintf(MAX_PATH-30, zTempPath, "%s", sqlite3_temp_directory);
}else if( isNT() ){
so for windows sqlite3_temp_directory is actually used. This is why it doesn't compile if It can't find it.

Resources