Compilation error encountered when using memory pool (MEM USE POOLS=1)

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Compilation error encountered when using memory pool (MEM USE POOLS=1)

lwip-users mailing list
Hi all,

I want to use the memory pool in lwip. I define the following macros to 1 to enable memory pool.
#define MEM_USE_POOLS 1
#define MEMP_USE_CUSTOM_POOLS 1
Also, I add a lwippool.h file to my project and define the following:
#ifndef __LWIPPOOLS_H__
#define __LWIPPOOLS_H__

LWIP_MALLOC_MEMPOOL_START
LWIP_MALLOC_MEMPOOL(20, 256)
LWIP_MALLOC_MEMPOOL_END

#endif /* __LWIPPOOLS_H__ */

However, when I compiled the project in MDK, an error encountered as following:
..\..\..\..\Utilities\Third_Party\lwip-2.1.0\src\include\lwip/priv/memp_priv.h(89): error:  #29: expected an expression.

memp_priv.h(89) is as following:
typedef enum {
    /* Get the first (via:
       MEMP_POOL_HELPER_START = ((u8_t) 1*MEMP_POOL_A + 0*MEMP_POOL_B + 0*MEMP_POOL_C + 0)*/
    MEMP_POOL_HELPER_FIRST = ((u8_t)
#define LWIP_MEMPOOL(name,num,size,desc)
#define LWIP_MALLOC_MEMPOOL_START 1
#define LWIP_MALLOC_MEMPOOL(num, size) * MEMP_POOL_##size + 0
#define LWIP_MALLOC_MEMPOOL_END
#include "lwip/priv/memp_std.h"
    ) ,

After preprocessing, the enumeration will be look like as this:
typedef enum {
    MEMP_POOL_HELPER_FIRST = ((u8_t)
1
 * MEMP_POOL_256 + 0
    ) ,

Since there is no definition of MEMP_POOL_256, so the compiler reports an error. 

Am I right? Is there anything I missing? How can I solve the issue?

Thanks,

York

_______________________________________________
lwip-users mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/lwip-users
Reply | Threaded
Open this post in threaded view
|

Re: Compilation error encountered when using memory pool (MEM USE POOLS=1)

goldsimon@gmx.de
Am 01.07.2020 um 12:34 schrieb yanhc519 via lwip-users:
> Hi all,
>
> I want to use the memory pool in lwip. I define the following macros to
> 1 to enable memory pool.
> #define MEM_USE_POOLS1
> #define MEMP_USE_CUSTOM_POOLS1
> Also, I add a lwippool.h file to my project and define the following:

You probably mean "lwippools.h" (note the s)?

> #ifndef __LWIPPOOLS_H__
> #define __LWIPPOOLS_H__

This file is special in that it is included multiple times with the
defines set to work differently each time. So you need to leave out the
include guard.

Regards,
Simon

>
> LWIP_MALLOC_MEMPOOL_START
> LWIP_MALLOC_MEMPOOL(20, 256)
> LWIP_MALLOC_MEMPOOL_END
>
> #endif /* __LWIPPOOLS_H__ */
>
> However, when I compiled the project in MDK, an error encountered as
> following:
> ..\..\..\..\Utilities\Third_Party\lwip-2.1.0\src\include\lwip/priv/memp_priv.h(89):
> error:  #29: expected an expression.
>
> memp_priv.h(89) is as following:
> typedef enum {
>     /* Get the first (via:
>        MEMP_POOL_HELPER_START = ((u8_t) 1*MEMP_POOL_A + 0*MEMP_POOL_B +
> 0*MEMP_POOL_C + 0)*/
>     MEMP_POOL_HELPER_FIRST = ((u8_t)
> #define LWIP_MEMPOOL(name,num,size,desc)
> #define LWIP_MALLOC_MEMPOOL_START 1
> #define LWIP_MALLOC_MEMPOOL(num, size) * MEMP_POOL_##size + 0
> #define LWIP_MALLOC_MEMPOOL_END
> #include "lwip/priv/memp_std.h"
>     ) ,
>
> After preprocessing, the enumeration will be look like as this:
> typedef enum {
>     MEMP_POOL_HELPER_FIRST = ((u8_t)
> 1
>  * MEMP_POOL_256 + 0
>     ) ,
>
> Since there is no definition of MEMP_POOL_256, so the compiler reports
> an error. 
>
> Am I right? Is there anything I missing? How can I solve the issue?
>
> Thanks,
>
> York
>
> _______________________________________________
> lwip-users mailing list
> [hidden email]
> https://lists.nongnu.org/mailman/listinfo/lwip-users
>


_______________________________________________
lwip-users mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/lwip-users
Reply | Threaded
Open this post in threaded view
|

Re: Compilation error encountered when using memory pool (MEM USE POOLS=1)

goldsimon@gmx.de
Hi York,

Please stay on the list next time.

Am 01.07.2020 um 14:55 schrieb yanhc519:
> Thanks Simon. Your suggestion solved my issue.
> However, I am wondering where defines the MEMP_POOL_256 macro. I tried
> and cannot find the definition.
> Could you give me a hint?

Call it "preprocessor magic". The parts in memp.h and memp_priv.h with
"MEMP_POOL_##size" (and similar) give you the required defines.

Regards,
Simon

>
> Thanks again,
> York
>
> On 7/1/2020 20:23,[hidden email]<[hidden email]>
> <mailto:[hidden email]> wrote:
>
>     Am 01.07.2020 um 12:34 schrieb yanhc519 via lwip-users:
>
>         Hi all,
>
>         I want to use the memory pool in lwip. I define the following
>         macros to
>         1 to enable memory pool.
>         #define MEM_USE_POOLS1
>         #define MEMP_USE_CUSTOM_POOLS1
>         Also, I add a lwippool.h file to my project and define the
>         following:
>
>
>     You probably mean "lwippools.h" (note the s)?
>
>         #ifndef __LWIPPOOLS_H__
>         #define __LWIPPOOLS_H__
>
>
>     This file is special in that it is included multiple times with the
>     defines set to work differently each time. So you need to leave out the
>     include guard.
>
>     Regards,
>     Simon
>
>
>         LWIP_MALLOC_MEMPOOL_START
>         LWIP_MALLOC_MEMPOOL(20, 256)
>         LWIP_MALLOC_MEMPOOL_END
>
>         #endif /* __LWIPPOOLS_H__ */
>
>         However, when I compiled the project in MDK, an error encountered as
>         following:
>         ..\..\..\..\Utilities\Third_Party\lwip-2.1.0\src\include\lwip/priv/memp_priv.h(89):
>         error:  #29: expected an expression.
>
>         memp_priv.h(89) is as following:
>         typedef enum {
>             /* Get the first (via:
>                MEMP_POOL_HELPER_START = ((u8_t) 1*MEMP_POOL_A +
>         0*MEMP_POOL_B +
>         0*MEMP_POOL_C + 0)*/
>             MEMP_POOL_HELPER_FIRST = ((u8_t)
>         #define LWIP_MEMPOOL(name,num,size,desc)
>         #define LWIP_MALLOC_MEMPOOL_START 1
>         #define LWIP_MALLOC_MEMPOOL(num, size) * MEMP_POOL_##size + 0
>         #define LWIP_MALLOC_MEMPOOL_END
>         #include "lwip/priv/memp_std.h"
>             ) ,
>
>         After preprocessing, the enumeration will be look like as this:
>         typedef enum {
>             MEMP_POOL_HELPER_FIRST = ((u8_t)
>         1
>          * MEMP_POOL_256 + 0
>             ) ,
>
>         Since there is no definition of MEMP_POOL_256, so the compiler
>         reports
>         an error. 
>
>         Am I right? Is there anything I missing? How can I solve the issue?
>
>         Thanks,
>
>         York
>
>         _______________________________________________
>         lwip-users mailing list
>         [hidden email]
>         https://lists.nongnu.org/mailman/listinfo/lwip-users
>
>
>
>     _______________________________________________
>     lwip-users mailing list
>     [hidden email]
>     https://lists.nongnu.org/mailman/listinfo/lwip-users
>


_______________________________________________
lwip-users mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/lwip-users
Reply | Threaded
Open this post in threaded view
|

Re: Compilation error encountered when using memory pool (MEM USE POOLS=1)

lwip-users mailing list
Hi Simon,

Thanks for your explanation. I know the C preprocessor mechanism. I just want to find which line of code exactly make this define and may be defined as follows to generate MEMP_POOL_256 for LWIP_MALLOC_MEMPOOL(20, 256):

#define LWIP_MALLOC_MEMPOOL(num, size)    MEMP_POOL_##size

However, I searched memp.h, memp_priv.h, memp_std.h, and cannot find the exact line of definition code.

Regards,
York
On 7/1/2020 21:05[hidden email] wrote:
Hi York,

Please stay on the list next time.

Am 01.07.2020 um 14:55 schrieb yanhc519:
Thanks Simon. Your suggestion solved my issue.
However, I am wondering where defines the MEMP_POOL_256 macro. I tried
and cannot find the definition.
Could you give me a hint?

Call it "preprocessor magic". The parts in memp.h and memp_priv.h with
"MEMP_POOL_##size" (and similar) give you the required defines.

Regards,
Simon


Thanks again,
York

On 7/1/2020 20:23,[hidden email]<[hidden email]>
<mailto:[hidden email]> wrote:

Am 01.07.2020 um 12:34 schrieb yanhc519 via lwip-users:

Hi all,

I want to use the memory pool in lwip. I define the following
macros to
1 to enable memory pool.
#define MEM_USE_POOLS1
#define MEMP_USE_CUSTOM_POOLS1
Also, I add a lwippool.h file to my project and define the
following:


You probably mean "lwippools.h" (note the s)?

#ifndef __LWIPPOOLS_H__
#define __LWIPPOOLS_H__


This file is special in that it is included multiple times with the
defines set to work differently each time. So you need to leave out the
include guard.

Regards,
Simon


LWIP_MALLOC_MEMPOOL_START
LWIP_MALLOC_MEMPOOL(20, 256)
LWIP_MALLOC_MEMPOOL_END

#endif /* __LWIPPOOLS_H__ */

However, when I compiled the project in MDK, an error encountered as
following:
..\..\..\..\Utilities\Third_Party\lwip-2.1.0\src\include\lwip/priv/memp_priv.h(89):
error:  #29: expected an expression.

memp_priv.h(89) is as following:
typedef enum {
    /* Get the first (via:
       MEMP_POOL_HELPER_START = ((u8_t) 1*MEMP_POOL_A +
0*MEMP_POOL_B +
0*MEMP_POOL_C + 0)*/
    MEMP_POOL_HELPER_FIRST = ((u8_t)
#define LWIP_MEMPOOL(name,num,size,desc)
#define LWIP_MALLOC_MEMPOOL_START 1
#define LWIP_MALLOC_MEMPOOL(num, size) * MEMP_POOL_##size + 0
#define LWIP_MALLOC_MEMPOOL_END
#include "lwip/priv/memp_std.h"
    ) ,

After preprocessing, the enumeration will be look like as this:
typedef enum {
    MEMP_POOL_HELPER_FIRST = ((u8_t)
1
 * MEMP_POOL_256 + 0
    ) ,

Since there is no definition of MEMP_POOL_256, so the compiler
reports
an error. 

Am I right? Is there anything I missing? How can I solve the issue?

Thanks,

York

_______________________________________________
lwip-users mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/lwip-users



_______________________________________________
lwip-users mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/lwip-users



_______________________________________________
lwip-users mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/lwip-users

_______________________________________________
lwip-users mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/lwip-users
Reply | Threaded
Open this post in threaded view
|

Re: Compilation error encountered when using memory pool (MEM USE POOLS=1)

lwip-users mailing list
Hi Simon,

I think I finally figured out where the MEMP_POOL_256 macro defined.

memp.c include memp.h. memp.h first include memp_std.h as follows:
/* run once with empty definition to handle all custom includes in lwippools.h */
#define LWIP_MEMPOOL(name,num,size,desc)
#include "lwip/priv/memp_std.h"

In memp_std.h, the follow definition will define LWIP_MALLOC_MEMPOOL(20, 256) as LWIP_MEMPOOL(POOL_256, 20, (256+ LWIP_MEM_ALIGN_SIZE(sizeof(struct memp_malloc_helper))), "MALLOC_256")
#ifndef LWIP_MALLOC_MEMPOOL
/* This treats "malloc pools" just like any other pool.
   The pools are a little bigger to provide 'size' as the amount of user data. */
#define LWIP_MALLOC_MEMPOOL(num, size) LWIP_MEMPOOL(POOL_##size, num, (size + LWIP_MEM_ALIGN_SIZE(sizeof(struct memp_malloc_helper))), "MALLOC_"#size)
#define LWIP_MALLOC_MEMPOOL_START
#define LWIP_MALLOC_MEMPOOL_END
#endif /* LWIP_MALLOC_MEMPOOL */

#if MEMP_USE_CUSTOM_POOLS
#include "lwippools.h"
#endif /* MEMP_USE_CUSTOM_POOLS */

//lwippools.h
LWIP_MALLOC_MEMPOOL_START
LWIP_MALLOC_MEMPOOL(20, 256)
LWIP_MALLOC_MEMPOOL_END

Now go back to memp.h. The following memp_t enumeration definition will first redefine LWIP_MEMPOOL to MEMP_##name. And then make the enumeration member. So the MEMP_POOL_256 will be an enumeration number.
/** Create the list of all memory pools managed by memp. MEMP_MAX represents a NULL pool at the end */
typedef enum {
#define LWIP_MEMPOOL(name,num,size,desc)  MEMP_##name,
#include "lwip/priv/memp_std.h"
  MEMP_MAX
} memp_t;

Am I right?

Regard, 
York
On 7/1/2020 22:40[hidden email] wrote:
Hi Simon,

Thanks for your explanation. I know the C preprocessor mechanism. I just want to find which line of code exactly make this define and may be defined as follows to generate MEMP_POOL_256 for LWIP_MALLOC_MEMPOOL(20, 256):

#define LWIP_MALLOC_MEMPOOL(num, size)    MEMP_POOL_##size

However, I searched memp.h, memp_priv.h, memp_std.h, and cannot find the exact line of definition code.

Regards,
York
On 7/1/2020 21:05[hidden email] wrote:
Hi York,

Please stay on the list next time.

Am 01.07.2020 um 14:55 schrieb yanhc519:
Thanks Simon. Your suggestion solved my issue.
However, I am wondering where defines the MEMP_POOL_256 macro. I tried
and cannot find the definition.
Could you give me a hint?

Call it "preprocessor magic". The parts in memp.h and memp_priv.h with
"MEMP_POOL_##size" (and similar) give you the required defines.

Regards,
Simon


Thanks again,
York

On 7/1/2020 20:23,[hidden email]<[hidden email]>
<mailto:[hidden email]> wrote:

Am 01.07.2020 um 12:34 schrieb yanhc519 via lwip-users:

Hi all,

I want to use the memory pool in lwip. I define the following
macros to
1 to enable memory pool.
#define MEM_USE_POOLS1
#define MEMP_USE_CUSTOM_POOLS1
Also, I add a lwippool.h file to my project and define the
following:


You probably mean "lwippools.h" (note the s)?

#ifndef __LWIPPOOLS_H__
#define __LWIPPOOLS_H__


This file is special in that it is included multiple times with the
defines set to work differently each time. So you need to leave out the
include guard.

Regards,
Simon


LWIP_MALLOC_MEMPOOL_START
LWIP_MALLOC_MEMPOOL(20, 256)
LWIP_MALLOC_MEMPOOL_END

#endif /* __LWIPPOOLS_H__ */

However, when I compiled the project in MDK, an error encountered as
following:
..\..\..\..\Utilities\Third_Party\lwip-2.1.0\src\include\lwip/priv/memp_priv.h(89):
error:  #29: expected an expression.

memp_priv.h(89) is as following:
typedef enum {
    /* Get the first (via:
       MEMP_POOL_HELPER_START = ((u8_t) 1*MEMP_POOL_A +
0*MEMP_POOL_B +
0*MEMP_POOL_C + 0)*/
    MEMP_POOL_HELPER_FIRST = ((u8_t)
#define LWIP_MEMPOOL(name,num,size,desc)
#define LWIP_MALLOC_MEMPOOL_START 1
#define LWIP_MALLOC_MEMPOOL(num, size) * MEMP_POOL_##size + 0
#define LWIP_MALLOC_MEMPOOL_END
#include "lwip/priv/memp_std.h"
    ) ,

After preprocessing, the enumeration will be look like as this:
typedef enum {
    MEMP_POOL_HELPER_FIRST = ((u8_t)
1
 * MEMP_POOL_256 + 0
    ) ,

Since there is no definition of MEMP_POOL_256, so the compiler
reports
an error. 

Am I right? Is there anything I missing? How can I solve the issue?

Thanks,

York

_______________________________________________
lwip-users mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/lwip-users



_______________________________________________
lwip-users mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/lwip-users



_______________________________________________
lwip-users mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/lwip-users

_______________________________________________
lwip-users mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/lwip-users