Subject: pgperl for 4.2?

From: [email-masked] (Robert Joop)
Date: Thu, 9 Jun 1994 00:38:40 +0200 (MET DST)

hi *,

has pgperl been ported to postgres 4.2 (and perl 4.036) already?

the code that's in 4.2's contrib can't be compiled because a symbol's
name (and meaning) has changed (it is commented out in a header file,
and substituting it with another #define that appears to have a similar
meaning, PORTALS_INITIAL_SIZE, leads to a pgperl that gets a SEGVIOL
during the `bmake runtest`. (actually, you'll only see this output if
you call `./pgperl testlibpq.pl` directly, because the pipe to tee
won't get flushed...):

~postgres/v4r2/src/contrib/pgperl> ./pgperl testlibpq.pl
Destroying database pgperltest
Creating database pgperltest
Accessing database pgperltest

Creating relation person:
query = create person (name = char16, age = int4, location = point)

Relation person before appends:
New tuple group:
name           age            location       

Appending to relation person:
query = append person (name = "fred", age = 50, location = "(50,10)"::point)
[...10 lines deleted...]

Relation person after appends:
New tuple group:
name           age            location       
fred           50             (50,10)        
[...10 lines deleted...]

Testing copy:

Relation person after copy:
New tuple group:
name           age            location       
fred           50             (50,10)        
[...12 lines deleted...]
sally          39             (5,6)          

Testing other things:
Opening 2 portals:
Number of portals open: 2
Segmentation fault
~postgres/v4r2/src/contrib/pgperl> 
)

so, if anybody already made the fix, please tell us about it!

best,
 rj

==============================================================================
   To add/remove yourself to/from the POSTGRES mailing list: send mail with 
   the subject line ADD or DEL to "[email-masked]"

   If this fails, send mail to "[email-masked]" and
   a human will deal with it.  DO NOT post to the "postgres" mailing list.
==============================================================================

---

From: [email-masked] (Paul M. Aoki)
Date: Thu, 16 Jun 94 04:40:32 -0700

[email-masked] (Robert Joop) writes:
> during the `bmake runtest`. 

this is my cheap hack for dealing with it.  your actual mileage, as 
always, may vary.

*** 1.5	1993/06/14 19:47:35
--- pg-libpq.mus	1994/06/16 11:41:10
***************
*** 1,7 ****
  /*
   * Interface to Postgres from Perl
   *
!  * $Header: /faerie/aoki/postgres/src/contrib/pgperl/RCS/pg-libpq.mus,v 1.5 1993/06/14 19:47:35 aoki Exp $
   */
  
  /* 
--- 1,7 ----
  /*
   * Interface to Postgres from Perl
   *
!  * $Header: /home2/aoki/master/src/contrib/pgperl/RCS/pg-libpq.mus,v 1.7 1994/06/16 11:37:21 aoki Exp $
   */
  
  /* 
***************
*** 47,52 ****
--- 47,58 ----
  #include "tmp/libpq.h"
  #include "tmp/libpq-fe.h"	/* superset of ones also in libpq-be.h */
  
+ #ifdef PORTNAME_ultrix4
+ #include "config.h"
+ #undef HAS_MEMCPY
+ #undef HAS_MEMSET
+ #endif /* PORTNAME_ultrix4 */
+ 
  #include "EXTERN.h"
  #include "perl.h"
  
***************
*** 400,436 ****
  	if (items != 1)
  	    fatal("Usage: &PQpnames($rule_p)");
  	else {
! 	    int nnames;
! 	    char portalnames[MAXPORTALS][PortalNameLength];
! 	    char *pnames[MAXPORTALS];
! 	    int		rule_p =	(int)		str_gnum(st[1]);
  
  	    /* Fill in the pname array */
!             {
! 	      int i;
!               for (i = 0; i < MAXPORTALS; i += 1) {
!                 pnames[i] = portalnames[i];
!               }
!             }
! 
! 	    (void)PQpnames(pnames, rule_p);
! 
! 	    /* Count the number of strings */
! 	    for (nnames = 0; pnames[nnames] != NULL; nnames += 1);
  
  	    /* Return an array of strings */
  	    if (nnames <= 0) {
  	      st[0] = str_2mortal(str_make("",0));
! 	      return sp;
              } else {
- 	      int i;
  	      astore(stack, sp + nnames, NULL); /* force stack to grow */
  	      st = stack->ary_array + sp;  /* stack may have changed */
  	      for (i = 1; i <= nnames; i++) {
  		  st[i-1] = str_2mortal(str_make( pnames[i-1], 0 ));
  	      }
! 	      return sp + nnames - 1;
              }
  	}
  
  /*
--- 406,451 ----
  	if (items != 1)
  	    fatal("Usage: &PQpnames($rule_p)");
  	else {
! 	    int i, nnames, nportals;
! 	    char *p, *portalnames, **pnames;
! 	    int rule_p = (int) str_gnum(st[1]);
! 
! 	    /* Figure out the maximum number of portals we might have */
! 	    nportals = PQnportals(rule_p);
! 	    pnames = (char **) calloc(nportals, sizeof(char *));
! 	    portalnames = (char *) calloc(nportals, PortalNameLength + 1);
  
  	    /* Fill in the pname array */
! 	    for (i = 0, p = portalnames; i < nportals;
! 		 ++i, p += PortalNameLength + 1) {
! 		pnames[i] = p;
! 	    }
! 
! 	    PQpnames(pnames, rule_p);
! 
! 	    /* Count the number of valid strings */
! 	    nnames = 0;
! 	    for (i = 0; i < nportals; ++i) {
! 		if (pnames[i] && *pnames[i])
! 		    /* We don't care about the blank portal */
! 		    ++nnames;
! 	    }
  
  	    /* Return an array of strings */
  	    if (nnames <= 0) {
  	      st[0] = str_2mortal(str_make("",0));
! 	      i = sp;
              } else {
  	      astore(stack, sp + nnames, NULL); /* force stack to grow */
  	      st = stack->ary_array + sp;  /* stack may have changed */
  	      for (i = 1; i <= nnames; i++) {
  		  st[i-1] = str_2mortal(str_make( pnames[i-1], 0 ));
  	      }
! 	      i = sp + nnames - 1;
              }
+ 	    free(portalnames);
+ 	    free(pnames);
+ 	    return(i);
  	}
  
  /*
--
  Paul M. Aoki  |  CS Div., Dept. of EECS, UCB  |  [email-masked]
                |  Berkeley, CA 94720           |  ...!uunet!ucbvax!aoki