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

perl.h:175:16: error: 'my_perl' undeclared #91

Closed
rzl opened this issue Sep 27, 2018 · 9 comments
Closed

perl.h:175:16: error: 'my_perl' undeclared #91

rzl opened this issue Sep 27, 2018 · 9 comments

Comments

@rzl
Copy link

rzl commented Sep 27, 2018

F:\perl\git\DBD-MariaDB-1.00\DBD-MariaDB-1.00>gmake
"F:\perl\Strawberry\perl\bin\perl.exe" -MExtUtils::Command::MM -e cp_nonempty -- MariaDB.bs blib\arch\auto\DBD\MariaDB\MariaDB.bs 644
gcc -c  -IF:\perl\Strawberry\perl\vendor\lib\auto\DBI -IF:\perl\STRAWB~1\c\bin\..\include\mysql50716 -DHAVE_DBI_1_634 -DHAVE_GET_OPTION -s -O2 -DWIN32
 -DWIN64 -DCONSERVATIVE -D__USE_MINGW_ANSI_STDIO -DPERL_TEXTMODE_SCRIPTS -DPERL_IMPLICIT_CONTEXT -DPERL_IMPLICIT_SYS -DUSE_PERLIO -fwrapv -fno-strict-
aliasing -mms-bitfields -s -O2   -DVERSION=\"1.00\" -DXS_VERSION=\"1.00\"  "-IF:\perl\STRAWB~1\perl\lib\CORE"   dbdimp.c
In file included from F:\perl\Strawberry\perl\vendor\lib\auto\DBI/DBIXS.h:38:0,
                 from dbdimp.h:20,
                 from dbdimp.c:16:
F:\perl\Strawberry\perl\vendor\lib\auto\DBI/dbipport.h:4471:0: warning: "WIDEST_UTYPE" redefined
 #  define WIDEST_UTYPE U64TYPE

In file included from F:\perl\STRAWB~1\perl\lib\CORE/perl.h:2465:0,
                 from F:\perl\Strawberry\perl\vendor\lib\auto\DBI/DBIXS.h:23,
                 from dbdimp.h:20,
                 from dbdimp.c:16:
F:\perl\STRAWB~1\perl\lib\CORE/handy.h:1064:0: note: this is the location of the previous definition
 #   define WIDEST_UTYPE U64

In file included from F:\perl\Strawberry\perl\vendor\lib\auto\DBI/DBIXS.h:23:0,
                 from dbdimp.h:20,
                 from dbdimp.c:16:
dbdimp.c: In function 'free_embedded_options':
F:\perl\STRAWB~1\perl\lib\CORE/perl.h:175:16: error: 'my_perl' undeclared (first use in this function); did you mean 'my_bool'?
 #  define aTHX my_perl
                ^
F:\perl\STRAWB~1\perl\lib\CORE/embedvar.h:38:18: note: in expansion of macro 'aTHX'
 #    define vTHX aTHX
                  ^~~~
F:\perl\STRAWB~1\perl\lib\CORE/embedvar.h:55:19: note: in expansion of macro 'vTHX'
 #define PL_Mem   (vTHX->IMem)
                   ^~~~
F:\perl\STRAWB~1\perl\lib\CORE/iperlsys.h:816:4: note: in expansion of macro 'PL_Mem'
  (*PL_Mem->pFree)(PL_Mem, (buf))
    ^~~~~~
F:\perl\STRAWB~1\perl\lib\CORE/XSUB.h:613:19: note: in expansion of macro 'PerlMem_free'
 #    define free  PerlMem_free
                   ^~~~~~~~~~~~
dbdimp.c:548:7: note: in expansion of macro 'free'
       free(options_list[i]);
       ^
F:\perl\STRAWB~1\perl\lib\CORE/perl.h:175:16: note: each undeclared identifier is reported only once for each function it appears in
 #  define aTHX my_perl
                ^
F:\perl\STRAWB~1\perl\lib\CORE/embedvar.h:38:18: note: in expansion of macro 'aTHX'
 #    define vTHX aTHX
                  ^~~~
F:\perl\STRAWB~1\perl\lib\CORE/embedvar.h:55:19: note: in expansion of macro 'vTHX'
 #define PL_Mem   (vTHX->IMem)
                   ^~~~
F:\perl\STRAWB~1\perl\lib\CORE/iperlsys.h:816:4: note: in expansion of macro 'PL_Mem'
  (*PL_Mem->pFree)(PL_Mem, (buf))
    ^~~~~~
F:\perl\STRAWB~1\perl\lib\CORE/XSUB.h:613:19: note: in expansion of macro 'PerlMem_free'
 #    define free  PerlMem_free
                   ^~~~~~~~~~~~
dbdimp.c:548:7: note: in expansion of macro 'free'
       free(options_list[i]);
       ^
gmake: *** [Makefile:349: dbdimp.o] Error 1

F:\perl\git\DBD-MariaDB-1.00\DBD-MariaDB-1.00>perl -v

This is perl 5, version 28, subversion 0 (v5.28.0) built for MSWin32-x64-multi-thread

strawberry-perl-5.28.0.1-64bit.msi

@rzl
Copy link
Author

rzl commented Sep 28, 2018

i try to add dTHX to free_embedded_options function , gmake success

int free_embedded_options(char ** options_list, int options_count)
{
  int i;
  dTHX;
  for (i= 0; i < options_count; i++)
  {
    if (options_list[i])
      free(options_list[i]);
  }
  free(options_list);

  return 1;
}

@pali
Copy link
Member

pali commented Sep 28, 2018

This is incorrect. Memory which is going to be freed by free() call in free_embedded_options is allocated in fill_out_embedded_options by calloc() call.

Perl headers file replaces malloc() and free() calls by own memory management. But does not replaces calloc() call.

On some systems those functions just calls system's malloc() and free() functions, therefore everything is safe. (Seems that all Linux machines which I tested). But error which you got on Windows indicates that it really has own memory management (needs that dTHX;) and calling Perl's free() on memory allocated by Windows native calloc() would for sure cause memory corruptions...

Correct way is to stop using calloc() and free() and uses Perl's Newz() and Safefree() replacment.

@rzl
Copy link
Author

rzl commented Sep 29, 2018

though I don't know what you are talking about, replace free to Safefree , gmake success.
thank you .

int free_embedded_options(char ** options_list, int options_count)
{
  int i;

  for (i= 0; i < options_count; i++)
  {
    if (options_list[i])
      Safefree(options_list[i]);
  }
  Safefree(options_list);

  return 1;
}

@rzl rzl closed this as completed Sep 29, 2018
@pali
Copy link
Member

pali commented Sep 29, 2018

though I don't know what you are talking about

That for allocation of memory calloc must be avoided and instead Newz should be used. And for releasing memory allocated by Newz should be used Safefree call.

@pali
Copy link
Member

pali commented Sep 29, 2018

Will you prepare a proper fix for it?

@pali pali reopened this Sep 29, 2018
@pali
Copy link
Member

pali commented Sep 29, 2018

Patch for guarding calloc for perl itself is in following RT ticket: https://rt.perl.org/Public/Bug/Display.html?id=133550

pali added a commit to pali/DBD-MariaDB that referenced this issue Oct 1, 2018
Use only Perl's alloc/free functions. Perl redefine C library alloc
functions (malloc, realloc, free) to its own memory allocation and
therefore it is not safe to use C library functions which allocate memory.

Memory allocates by calloc() must be released by free() from C library, but
because Perl's redefine free() there is no access to free() from C library.
And Perl does not redefine calloc().

See also: perl5-dbi#91
pali added a commit to pali/DBD-MariaDB that referenced this issue Oct 1, 2018
Use only Perl's alloc/free functions. Perl redefines C library alloc
functions (malloc, realloc, free) to its own memory allocation and
therefore it is not safe to use C library functions which allocate memory.

Perl doesn't redefine calloc() so its usage is not safe as far as it
allocates using C library memory management but frees with Perl's.

See also: perl5-dbi#91
@pali
Copy link
Member

pali commented Oct 1, 2018

Ok, I did in in pull request #94. Please check.

@rzl
Copy link
Author

rzl commented Oct 2, 2018

Ok, I did in in pull request #94. Please check.

git clone https://github.com/pali/DBD-MariaDB.git
perl Makefile.PL --mysql_config=c:/path/mysql_config.bat
gmake
gmake install

success

@pali
Copy link
Member

pali commented Oct 2, 2018

Ok, therefore it is fixed, closing.

@pali pali closed this as completed Oct 2, 2018
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