# pspell tweak.

- Thread: https://externals.io/message/39833
- Original archive: https://news-web.php.net/php.internals/39833
- Started by Phil Oleson on 2008-08-11T17:54:47+00:00
- Messages: 8
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #39833 — Phil Oleson — 2008-08-11T17:54:47+00:00

URL: https://externals.io/message/39833#39833

Was running pspell through g++ and found that a couple of error conditions segments in pspell.c
are using the wrong cleanup methods.  delete_pspell_manager()  should be delete_pspell_can_have_error()

	-Phil.


--- pspell.c    16 Jul 2008 18:35:41 -0000      1.61
+++ pspell.c    11 Aug 2008 17:39:03 -0000
@@ -374,7 +374,7 @@

         if(pspell_error_number(ret) != 0){
                 php_error_docref(NULL TSRMLS_CC, E_WARNING, "PSPELL couldn't open the dictionary. reason: %s", 
pspell_error_message(ret));
-               delete_pspell_manager(ret);
+               delete_pspell_can_have_error(ret);
                 RETURN_FALSE;
         }

@@ -492,7 +492,7 @@

         if(pspell_error_number(ret) != 0){
                 php_error_docref(NULL TSRMLS_CC, E_WARNING, "PSPELL couldn't open the dictionary. reason: %s", 
pspell_error_message(ret));
-               delete_pspell_manager(ret);
+               delete_pspell_can_have_error(ret);
                 RETURN_FALSE;
         }

@@ -526,7 +526,7 @@

         if(pspell_error_number(ret) != 0){
                 php_error_docref(NULL TSRMLS_CC, E_WARNING, "PSPELL couldn't open the dictionary. reason: %s", 
pspell_error_message(ret));
-               delete_pspell_manager(ret);
+               delete_pspell_can_have_error(ret);
                 RETURN_FALSE;
         }

---

## #39871 — Antony Dovgal — 2008-08-12T14:00:48+00:00

URL: https://externals.io/message/39833#39871 · In reply to: #39833

> Was running pspell through g++ and found that a couple of error conditions segments in pspell.c
> are using the wrong cleanup methods.  delete_pspell_manager()  should be delete_pspell_can_have_error()

We'd certainly need some more details to get this patch committed, not just "this should that".

-- 
Wbr, 
Antony Dovgal

---

## #39899 — Phil Oleson — 2008-08-12T21:31:52+00:00

URL: https://externals.io/message/39833#39899 · In reply to: #39871

Antony Dovgal wrote:
> 
> > […]
> 
> We'd certainly need some more details to get this patch committed, not 
> just "this should that".
> 

Well I thought the patch was fairly simple but if you'd like a full explination..

g++ -I. -I/usr/home/phil/vps2/user/contrib/php5/ext/pspell -DPHP_ATOM_INC -I/usr/home/phil/vps2/user/contrib/php5/ext/pspell/include -I/usr/home/phil/vps2/user/contrib/php5/ext/pspell/main -I/usr/home/phil/vps2/user/contrib/php5/ext/pspell -I/usr/local/php5/include/php -I/usr/local/php5/include/php/main -I/usr/local/php5/include/php/TSRM -I/usr/local/php5/include/php/Zend -I/usr/local/php5/include/php/ext -I/usr/local/php5/include/php/ext/date/lib -I/usr/local/include/pspell -DHAVE_CONFIG_H -g -O2 -c /usr/home/phil/vps2/user/contrib/php5/ext/pspell/pspell.c  -fPIC -DPIC -o .libs/pspell.o
/usr/home/phil/vps2/user/contrib/php5/ext/pspell/pspell.c: In function `void zif_pspell_new(int, zval*, zval**, zval*, int)':
/usr/home/phil/vps2/user/contrib/php5/ext/pspell/pspell.c:254: error: cannot convert `AspellCanHaveError*' to `AspellSpeller*' for argument `1' to `void delete_aspell_speller(AspellSpeller*)'
/usr/home/phil/vps2/user/contrib/php5/ext/pspell/pspell.c: In function `void zif_pspell_new_personal(int, zval*, zval**, zval*, int)':
/usr/home/phil/vps2/user/contrib/php5/ext/pspell/pspell.c:377: error: cannot convert `AspellCanHaveError*' to `AspellSpeller*' for argument `1' to `void delete_aspell_speller(AspellSpeller*)'
/usr/home/phil/vps2/user/contrib/php5/ext/pspell/pspell.c: In function `void zif_pspell_new_config(int, zval*, zval**, zval*, int)':
/usr/home/phil/vps2/user/contrib/php5/ext/pspell/pspell.c:411: error: cannot convert `AspellCanHaveError*' to `AspellSpeller*' for argument `1' to `void delete_aspell_speller(AspellSpeller*)'

as you can see we are using the wrong destructor in these three cases.  Looking at the code you find:

        PspellCanHaveError *ret;
<snip>
        ret = new_pspell_manager(config);
        delete_pspell_config(config);

        if(pspell_error_number(ret) != 0){
                php_error_docref(NULL TSRMLS_CC, E_WARNING, "PSPELL couldn't open the dictionary. reason: %s ", pspell_error_message(ret));
                delete_pspell_manager(ret);
                RETURN_FALSE;
        }

----
do a little grep'ing and we find the prototype is..

> grep delete_pspell_manager /usr/local/include/pspell/pspell.h
#define delete_pspell_manager delete_aspell_speller

> grep delete_aspell_speller /usr/local/include/aspell.h
void delete_aspell_speller(struct AspellSpeller * ths);

I do a little detective work and find...

> grep delete_aspell_can_have_error  /usr/local/include/aspell.h
void delete_aspell_can_have_error(struct AspellCanHaveError * ths);

transpose this to the pspell wrapper..
> grep delete_aspell_can_have_error /usr/local/include/pspell/pspell.h
#define delete_pspell_can_have_error delete_aspell_can_have_error

Thus the diff -u I sent in.. which resolves the above compiler failure with g++.


	-Phil.

---

## #39907 — Antony Dovgal — 2008-08-13T08:11:16+00:00

URL: https://externals.io/message/39833#39907 · In reply to: #39899

> Thus the diff -u I sent in.. which resolves the above compiler failure with g++.

Committed, thanks!

Btw, how and why did you manage to get g++ compiling plain C code?

-- 
Wbr, 
Antony Dovgal

---

## #39932 — Phil Oleson — 2008-08-13T22:06:52+00:00

URL: https://externals.io/message/39833#39932 · In reply to: #39907

Antony Dovgal wrote:
> 
> > […]
> 
> Committed, thanks!
> 
> Btw, how and why did you manage to get g++ compiling plain C code?
> 


umm.. how?

cd ext/pspell
/usr/local/php5/bin/phpize
env CC=g++ CFLAGS=-fuse-cxa-atexit ./configure --with-php-config=/usr/local/php5/bin/php-config
make

C++ is a superset of C thus any C code can be complied as C++ as long as it doesn't use any
C++ reserved words.  Plus, C++ has much stronger type checking and it is worth a run through
at least occasionally to double checking that code is sane.

as to why? well that is more complicated.. I'm mainly tilting at windmills.. 
but I've been trying to find a simpler resolution to my php setup crashing with
a SEGFAULT when Zend Optimizer is installed and pspell is a shared extension.

I'm starting to suspect it is something misbehaving in the Optimizer, but I need
to organize my research before I present any theories publicly. 


	-Phil.

---

## #39934 — Nuno Lopes — 2008-08-13T22:18:34+00:00

URL: https://externals.io/message/39833#39934 · In reply to: #39932

> Antony Dovgal wrote:
> > […]
>
> umm.. how?
>
> cd ext/pspell
> /usr/local/php5/bin/phpize
> env CC=g++ CFLAGS=-fuse-cxa-atexit 
> ./configure --with-php-config=/usr/local/php5/bin/php-config
> make
>
> C++ is a superset of C thus any C code can be complied as C++ as long as 
> it doesn't use any
> C++ reserved words.

That is not true at all, although it's a common misconception.
Just try the following in C and in C++:
printf("sizeof('x') == %d\n", (int)sizeof('x'));

(hint: they will give you different results). And there are many more 
differences..

Nuno

---

## #39941 — Phil Oleson — 2008-08-13T22:57:14+00:00

URL: https://externals.io/message/39833#39941 · In reply to: #39934

Nuno Lopes wrote:
> > […]
> 
> That is not true at all, although it's a common misconception.
> Just try the following in C and in C++:
> printf("sizeof('x') == %d\n", (int)sizeof('x'));
> 
> (hint: they will give you different results). And there are many more 
> differences..
> 
> Nuno

Yes.. there are some differences, but if your very careful with your typing..
C can be compiled with a C++ compiler.

printf("sizeof('x') == %d\n", (int) sizeof((char)'x'));

gives the same output of 1, with gcc and g++.

I really don't want to be a troll.  I still espouse that compiling a C program
with a C++ compiler even if you never actually run it that way is a definite
advantage to catch type checking problems.

	-Phil.

---

## #39943 — Nuno Lopes — 2008-08-13T23:37:49+00:00

URL: https://externals.io/message/39833#39943 · In reply to: #39941

> > […]
>
> Yes.. there are some differences, but if your very careful with your 
> typing..
> C can be compiled with a C++ compiler.
>
> printf("sizeof('x') == %d\n", (int) sizeof((char)'x'));
>
> gives the same output of 1, with gcc and g++.
>
> I really don't want to be a troll.  I still espouse that compiling a C 
> program
> with a C++ compiler even if you never actually run it that way is a 
> definite
> advantage to catch type checking problems.

Yes sure. I was just warning that compiling foreign C code with a C++ 
compiler is dangerous because you don't know if it's using some C specific 
feature or not.
Anyway this is already too much offtopic :)

Nuno
