cURL / Mailing Lists / curl-users / Single Mail

curl-users

## macro question

From: <Priya.Ramakrishnan_at_WellsFargo.COM>
Date: Fri, 26 Jul 2002 18:44:20 -0700

Hi Daniel,
        We have come across a peculiar compilation problem with curl.h. We
are compiling on HP and SUN. We noticed that CINIT and CFINIT have been
altered to something different. Our compilers understand the ## macro, but
now that macro is no longer available. I understand that ## macro is ISO C.
But the ifdef statement used to separate the different definitions of CINIT
and CFINIT break our builds. We were using 7.9.5 with the single definition
of CINIT and CFINIT. 7.9.5 worked great. We have since upgraded to 7.9.8
(for async functionality) and now we cannot compile our code. We have a C++
code base and link to curl. Let me walk through some code.

curl.h
-------
(7.9.5 code)
#ifdef CINIT
#undef CINIT
#endif
#define CINIT(name,type,number) CURLOPT_ ## name = CURLOPTTYPE_ ## type +
number

^^^ this works on HP, SUN, and WINDOWS.

(7.9.8 code)
#ifdef CINIT
#undef CINIT
#endif
#if defined(__STDC__) || defined(_MSC_VER)
#define CINIT(name,type,number) CURLOPT_ ## name = CURLOPTTYPE_ ## type +
number
#else
/* The macro "##" is ISO C, we assume pre-ISO C doesn't support it. */
#define LONG CURLOPTTYPE_LONG
#define OBJECTPOINT CURLOPTTYPE_OBJECTPOINT
#define FUNCTIONPOINT CURLOPTTYPE_FUNCTIONPOINT
#define CINIT(name,type,number) CURLOPT_/**/name = type + number
#endif

^^^ This only works on WINDOWS because of _MSC_VER, but not on HP or SUN..

What if we tried this? It is just a suggestion. We are using aCC A.03.34
(HP) and gcc 3.0.4 (SUN) and cl.exe 12.00.8168 (windows/VC++ 6.0)

#ifdef CINIT
# undef CINIT
#endif

#if defined(ISO_C)
/* The macro "##" is ISO C, we assume pre-ISO C doesn't support it. */
# define LONG CURLOPTTYPE_LONG
# define OBJECTPOINT CURLOPTTYPE_OBJECTPOINT
# define FUNCTIONPOINT CURLOPTTYPE_FUNCTIONPOINT
# define CINIT(name,type,number) CURLOPT_/**/name = type + number
#else
# define CINIT(name,type,number) CURLOPT_ ## name = CURLOPTTYPE_ ##
type + number
#endif

-----Original Message-----
From: Daniel Stenberg [mailto:daniel_at_haxx.se]
Sent: Thursday, July 25, 2002 6:33 AM
To: Priya.Ramakrishnan_at_WellsFargo.COM
Cc: Curl Mailinglist
Subject: Re: curl_escape() memory leak

On Thu, 27 Jun 2002 Priya.Ramakrishnan_at_WellsFargo.COM wrote:

(I corrected the subject line for this mail)

> I am getting a memory leak when i am using curl_escape to URL encode the
> message.

curl_escape() returns a malloc()ed memory. You must make sure to free() that
memory when you've finished using it. libcurl will not do that for you.

The man page explains this.

--
  Cheers,
  Daniel Stenberg
-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
Received on 2002-07-27