Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

If ASN_THREAD_SAFE and EMIT_ASN_DEBUG is set, per_opentype.c does not compile #15

Closed
hmundle opened this issue Jan 27, 2012 · 8 comments

Comments

@hmundle
Copy link

hmundle commented Jan 27, 2012

As soon as ASN_THREAD_SAFE and EMIT_ASN_DEBUG=1 is set, asn_debug_indent is defined to '0' in asn_internal.h (line 39). per_opentype.c does not compile anymore in line 21, 104, 106, 156 and 158.

My setup:
gcc (Ubuntu 4.4.3-4ubuntu5) 4.4.3
vlm-asn1c-3d6fcfe.tar.gz
CFLAGS += -DEMIT_ASN_DEBUG=1 -D_REENTRANT

To get my compiler working I replace the asn_debug_indent variable in per_opentype.c with asn_debug_indentX. But I don't know if there are negative side-effect with the generated code now.

@vlm
Copy link
Owner

vlm commented Feb 21, 2012

Please pull up and try again.

@vlm vlm closed this as completed Feb 21, 2012
@hmundle
Copy link
Author

hmundle commented Feb 24, 2012

Tested again with vlm-asn1c-b4c2ca8.tar.gz and with CFLAGS += -DEMIT_ASN_DEBUG=1 -D_REENTRANT.

I still get the same errors.

Actually I do not see any changes in the sources wrt. the described issue.

@vlm
Copy link
Owner

vlm commented Feb 24, 2012

Oops, forgot to push. Now, try.

@hmundle
Copy link
Author

hmundle commented Feb 27, 2012

Thanks, now I see the changes. I compiled four different cases; one is successful, one with compiler error and two with warning and linker error (see below).

The easiest issue is case 3, this is just a typo, probably 'increment' has to be replaced with 'i'.

Case 1 and 2 (EMIT_ASN_DEBUG != 1) does not define the ASN_DEBUG_INDENT_ADD macro, but I don't know what exactly has to be defined here. Actually I even do not understand your while(false) loop.

Case 4 with threading and ASN debug compiles and links fine.

Using vlm-asn1c-69c73dc.tar.gz.

Case 1:
cc -Wall -O0 -g ... -I. -fPIC -c -o per_opentype.o per_opentype.c
per_opentype.c: In function ‘uper_open_type_get_simple’:
per_opentype.c:102: warning: implicit declaration of function ‘ASN_DEBUG_INDENT_ADD’
...
Linker error:
libasn.a(per_opentype.o): In function uper_open_type_get_simple': per_opentype.c:102: undefined reference toASN_DEBUG_INDENT_ADD'
per_opentype.c:104: undefined reference to `ASN_DEBUG_INDENT_ADD'
collect2: ld returned 1 exit status

Case 2:
cc -Wall -O0 -g -D_REENTRANT ... -I. -fPIC -c -o per_opentype.o per_opentype.c
per_opentype.c: In function ‘uper_open_type_get_simple’:
per_opentype.c:102: warning: implicit declaration of function ‘ASN_DEBUG_INDENT_ADD’
...
Linker error:
libasn.a(per_opentype.o): In function uper_open_type_get_simple': per_opentype.c:102: undefined reference toASN_DEBUG_INDENT_ADD'
per_opentype.c:104: undefined reference to `ASN_DEBUG_INDENT_ADD'
collect2: ld returned 1 exit status

Case 3:
cc -Wall -O0 -g -DEMIT_ASN_DEBUG=1 ... -I. -fPIC -c -o per_opentype.o per_opentype.c
per_opentype.c: In function ‘uper_open_type_get_simple’:
per_opentype.c:102: error: ‘increment’ undeclared (first use in this function)
per_opentype.c:102: error: (Each undeclared identifier is reported only once
per_opentype.c:102: error: for each function it appears in.)
per_opentype.c: In function ‘uper_open_type_get_complex’:
per_opentype.c:154: error: ‘increment’ undeclared (first use in this function)

Case 4:
cc -Wall -O0 -g -D_REENTRANT -DEMIT_ASN_DEBUG=1 ... -I. -fPIC -c -o per_opentype.o per_opentype.c
compiles without warning

@vlm
Copy link
Owner

vlm commented Feb 27, 2012

Fixed, try again!

@hmundle
Copy link
Author

hmundle commented Mar 1, 2012

Case 1, 2 and 4 can be compiled now. At lease for me, case 3 results in a linker error:

cc  -Wall -O0 -g -DEMIT_ASN_DEBUG=1 ... -I. -fPIC   -c -o per_opentype.o per_opentype.c

Linker error:

./libasn.a(asn.o): In function `asn_decode':
./src/asn.c:49: multiple definition of `asn_debug_indent'
client.o:./src/client.c:31: first defined here
collect2: ld returned 1 exit status

As far as I see, the issue is, that I compile asn.o with gcc but client.c with g++ (just wondering, why extern "C" does not help).

To make the asn1c skeleton code a little bit clearer, I removed all changes from commit e2c05bf in file skeletons/per_opentype.c. But I added one single line in skeletons/asn_internal.h, see the EMIT_ASN_DEBUG != 1 block:

#ifndef ASN_DEBUG   /* If debugging code is not defined elsewhere... */
#if EMIT_ASN_DEBUG == 1 /* And it was asked to emit this code... */
#ifdef  __GNUC__
#ifdef  ASN_THREAD_SAFE
#define asn_debug_indent    0
#define ASN_DEBUG_INDENT_ADD(i) do{}while(0)
#else   /* !ASN_THREAD_SAFE */
int asn_debug_indent;
#define ASN_DEBUG_INDENT_ADD(i) do { asn_debug_indent += i; } while(0)
#endif  /* ASN_THREAD_SAFE */
#define ASN_DEBUG(fmt, args...) do {            \
        int adi = asn_debug_indent;     \
        while(adi--) fprintf(stderr, " ");  \
        fprintf(stderr, fmt, ##args);       \
        fprintf(stderr, " (%s:%d)\n",       \
            __FILE__, __LINE__);        \
    } while(0)
#else   /* !__GNUC__ */
void ASN_DEBUG_f(const char *fmt, ...);
#define ASN_DEBUG   ASN_DEBUG_f
#endif  /* __GNUC__ */
#else   /* EMIT_ASN_DEBUG != 1 */
#define ASN_DEBUG_INDENT_ADD(i) do{}while(0)
static inline void ASN_DEBUG(const char *fmt, ...) { (void)fmt; }
#endif  /* EMIT_ASN_DEBUG */
#endif  /* ASN_DEBUG */

@vlm
Copy link
Owner

vlm commented Mar 2, 2012

Fixed differently, please try again.

@hmundle
Copy link
Author

hmundle commented Mar 2, 2012

Thanks again vlm,
I think the code is much clearer now. The compilation results to the same as the previous push. Three cases work perfect, one fails with the linker error, due to the mixture of C++ and C objects. The may be a C++ vs. C issue and not a ASN1c issue. But I am curious, why "asn_debug_indent" is the only variable with multiple definition, there is no problem with tons of ASN1 compiled structs.

brchiu pushed a commit to brchiu/asn1c that referenced this issue Apr 20, 2017
Add OS X to the Travis CI builds
brchiu pushed a commit to brchiu/asn1c that referenced this issue Apr 20, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants