Bill Allombert on Sun, 06 Jun 2010 13:10:07 +0200

[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: C++ new and delete like malloc and free?

On Sat, Jun 05, 2010 at 08:57:13PM +0200, Daniel Allcock wrote:
> Hi all,
> I'll probably be spamming the list for a little while since I'm working on a project, 
> so thanks for your patience.
> I'm developing a program in C++ that uses libpari.  I know that pari has wrappers around
> malloc and free, namely pari_malloc and pari_free, and that using them protects against stack corruption problems
> in the presence of a SIGINT.

Well, this issue is mostly for the GP interpretor and is very technical:
GP try to recover from SIGINT and allow further computation. However, if SIGINT
is pressed while libpari of libc is updating a data structure, the system might
be in an inconsistent state, so we provide macros
BLOCK_SIGINT_START/BLOCK_SIGINT_END to protect them: if SIGINT is received 
inside a BLOCK_SIGINT_START/BLOCK_SIGINT_END block, then it is deferred until

pari_free simply call free() inside such a block to avoid a SIGINT during
free() letting the malloc engine state inconsistent.

> The docs say pari is C++ compatible, and 
> there is no mention of analogous problems for operators new and delete in C++.  
libpari is coded in C and do not use new and delete.

> Is the same issue present?  If so, what do I do to address it?  Just trying to be careful.

If new/delete use malloc internally, then I suppose the same problem exist.
What you can do is to overload them by methods that do
new ...