Thanks for the input, Neil.

> Your code fails to compile because the function steps() is 
> masked with the
> parameter 'steps' inside the function two_step.

Unfortunately, after correcting my name masking errors as you pointed out,
it still did not work (strangely, it seems to have worked for you).

However, when I add the parameter "unsigned char partner" to the steps
subroutine, it works.  Examining the resulting .xs file, we find that the
prototype (is that the term for it?) for the steps subroutine at the end of
the file has now disappeared, taking the offending typeless argument
definition with it.  This is fine, because I don't want to pass or access
these parameters or call this subroutine from perl space, only c space (and
for this reason, I shouldn't need a typemap, because the c compiler should
know what to do with it, and I am not trying to pass this parameter from
perl, right?).  However, remove the extra parameter, and poof!, the steps
prototype reappears, as does the error.

Broken (will_not_work.pl/.xs) and fixed (works.pl/.xs) perl and .xs files
are provided below, demonstrating this now you see it now you don't
phenomena.  Can anyone explain why it is behaving this way, and how I can
control it to prevent the inavlid argument errors? 

Thanks,
Eric

----8<----works.pl---------------------------------
#!/usr/bin/perl -w

BEGIN{
  use Inline;
  $Inline::Config::CLEAN_AFTER_BUILD = 0;
}

use strict;

my $dance = 100;

two_step($dance);

exit;

use Inline C => <<'END_OF_C_CODE'; 

/* extra parameter "partner" prevents appearance of steps prototype
   in xs file, thus preventing a choke on the int*  (see xs file
   below 
*/

void steps(unsigned char partner,
           int *steps_array)
{
    printf("I can only hope to get this far\n"); 
}
      
void two_step(int isteps)
{
  int *dance = NULL;

  dance = (int*)malloc(isteps*sizeof(int));
  if (dance=NULL)
     handle_error(1, 1);

  steps(5, dance);

  free(dance);

}

handle_error (int err_no, int trap)
{
  printf("Could not allocated sufficient memory! (Error #1 at trap %d)\n\n",
trap);
  exit(0);
}

END_OF_C_CODE


----8<----works.xs---------------------------------
#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"
#include "INLINE.h"


void steps(unsigned char partner,
           int *steps_array)
{
    printf("I can only hope to get this far\n"); 
}
      
void two_step(int isteps)
{
  int *dance = NULL;

  dance = (int*)malloc(isteps*sizeof(int));
  if (dance=NULL)
     handle_error(1, 1);

  steps(5, dance);

  free(dance);

}

handle_error (int err_no, int trap)
{
  printf("Could not allocated sufficient memory! (Error #1 at trap %d)\n\n",
trap);
  exit(0);
}

MODULE = main_C_works_pl_5d14af05dcf1bafa6c65c7c048b7da0f       PACKAGE =
main

PROTOTYPES: DISABLE



/* (COMMENT ADDED): Note that void steps is not here (see below)*/


void
two_step (isteps)
        int     isteps
        PREINIT:
        I32* temp;
        PPCODE:
        temp = PL_markstack_ptr++;
        two_step(isteps);
        if (PL_markstack_ptr != temp) {
          /* truly void, because dXSARGS not invoked */
          PL_markstack_ptr = temp;
          XSRETURN_EMPTY; /* return empty stack */
        }
        /* must have used dXSARGS; list context implied */
        return; /* assume stack size is correct */


----8<----will_not_work.pl---------------------------------
will_not_work.pl
#!/usr/bin/perl -w

BEGIN{
  use Inline;
  $Inline::Config::CLEAN_AFTER_BUILD = 0;
}

use strict;

my $dance = 100;

two_step($dance);

exit;

use Inline C => <<'END_OF_C_CODE'; 

void steps(int *steps_array)
{
    printf("I can only hope to get this far\n"); 
}
      
void two_step(int isteps)
{
  int *dance = NULL;

  dance = (int*)malloc(isteps*sizeof(int));
  if (dance=NULL)
     handle_error(1, 1);

  steps(dance);

  free(dance);

}

handle_error (int err_no, int trap)
{
  printf("Could not allocated sufficient memory! (Error #1 at trap %d)\n\n",
trap);
  exit(0);
}

END_OF_C_CODE

----8<----will_not_work.xs---------------------------------
#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"
#include "INLINE.h"


void steps(int *steps_array)
{
    printf("I can only hope to get this far\n"); 
}
      
void two_step(int isteps)
{
  int *dance = NULL;

  dance = (int*)malloc(isteps*sizeof(int));
  if (dance=NULL)
     handle_error(1, 1);

  steps(dance);

  free(dance);

}

handle_error (int err_no, int trap)
{
  printf("Could not allocated sufficient memory! (Error #1 at trap %d)\n\n",
trap);
  exit(0);
}



MODULE = main_C_will_not_work_pl_e4a9f4d8b065bb7661afb02b3f64e6e9
PACKAGE = main

PROTOTYPES: DISABLE

void
steps (steps_array)
                steps_array  /* HERE IS THE PROBLEM */
        PREINIT:
        I32* temp;
        PPCODE:
        temp = PL_markstack_ptr++;
        steps(steps_array);
        if (PL_markstack_ptr != temp) {
          /* truly void, because dXSARGS not invoked */
          PL_markstack_ptr = temp;
          XSRETURN_EMPTY; /* return empty stack */
        }
        /* must have used dXSARGS; list context implied */
        return; /* assume stack size is correct */

void
two_step (isteps)
        int     isteps
        PREINIT:
        I32* temp;
        PPCODE:
        temp = PL_markstack_ptr++;
        two_step(isteps);
        if (PL_markstack_ptr != temp) {
          /* truly void, because dXSARGS not invoked */
          PL_markstack_ptr = temp;
          XSRETURN_EMPTY; /* return empty stack */
        }
        /* must have used dXSARGS; list context implied */
        return; /* assume stack size is correct */


----8<----error message from will_not_work.pl------------------------
A problem was encountered while attempting to compile and install your
Inline
C code. The command that failed was:
  make > out.make 2>&1

The build directory was:
/home/erikor/research/blib_I/main_C_will_not_work_pl_e4a9f4d8b065bb7661afb02
b3f64e6e9/

To debug the problem, cd to the build directory, and inspect the output
files.

 at will_not_work.pl line 16
BEGIN failed--compilation aborted at will_not_work.pl line 43.

Reply via email to