feature request: way to clone a sql connection object

I have a need in an application I'm working on for a way to create a  
new connection to a database given an existing sql connection object.  
There's no way to do that right now, is there? 

Re: localtime()->timezone ???

I believe Java's APIs work the other way as does the gnu/bsd tm struct  
member tm_gmtoff... but I guess that's beside the point. If someone  
else hasn't gotten around to fixing the docs, I'll take care of it  
when I get back in town this weekend.

Bill

On Aug 27, 2008, at 7:55 PM, Johan Sundström (Achtung Liebe!) @ Pike  
(-) importmöte för mailinglistan wrote:

> "Offset to UTC" might be better documentation, but something even more
> verbose and enlightening wouldn't hurt. AFAIK, all time zone APIs that
> give UTC offsets have the timestamp as the frame of reference, rather
> than UTC itself; add timestamp and UTC offset to get UTC time. You may
> try javascript:alert((new Date).getTimezoneOffset()) in your browser,
> for instance, for the browser object model equivalent (-120 in UTC+2).
>

Bill Welliver | 28 Aug 01:39

Re: localtime()->timezone ???

I'm not sure if you're applying humour here or not, so I'll assume you're 
serious.

That just confirms that it's backward for everyone... the docs say "offset 
from UTC", so shouldn't that be +7200? I would think that -7200 would 
represent the offset _to_ UTC, or am I missing something? At the very 
least, it's the opposite of how most people think of time zone offsets.

Bill

On Wed, 27 Aug 2008, Johan Sundström (Achtung Liebe!) @ Pike (-) importmöte för mailinglistan wrote:

> It does, but you're thinking in negative space. UTC+2 (here) is -7200.
>
>
Bill Welliver | 28 Aug 00:49

localtime()->timezone ???

I'm wondering if perhaps I've misunderstood something; perhaps someone can 
enlighten me... localtime() returns a mapping, of which one, timezone, is 
indicated to be the offset from gmt, in seconds. Fair enough. When I use 
localtime(), I get 14400 for the offset, which is 4 hours. The problem is 
that I'm GMT-4... shouldn't the timezone indicate the direction of 
the offset, not just the magnitude? This is Pike 7.6.112 on Solaris 
10/x86.

Bill

Felip Alàez Nadal | 26 Aug 17:49

Something strange with read on sockets. Help needed

Hello:

I'm in trouble with sockets. I've created a little multithreaded server class which I plan to use for games. I have problems reading from sockets. I create the server and, when It makes an accept(), returns an Stdio.File object which represents the socket, don't? Then the server can write to the socket. I know that the server works because I can do a telnet and connect to It. My problem is that I can't read anything from the socket. If I do mySocket->read(), It never returns. I write on the telnet terminal and the server never returns from the call to mySocket->read(). I also wrote a little telnet program in pike and I have the same problem: the server writes to the telnet program, but can't read anything from It.

Can somebody explain me which is the correct way to read data from a socket?

Thanks you.

--
Felip Alàez Nadal
cleverpig | 26 Aug 10:17

Where is complete tutorial of developing Roxen web application with pike?

The roxen manual has a little code to show how to use pike tag and
script,but there is not a complete reference for it.
I can do this with sample code:
<html>
	<head></head>
	<body>
	<?pike
	  //X <gtext>Server Info</gtext><br />
	  write(
	  	"This is %s running %s, and we've been up for %d seconds.",
	  	roxen.version, roxen["pike-version"], roxen.uptime
	  );
	
	  //X <br /><gtext>Cookies</gtext><br />
	  //X <pre><insert scope='cookie' variables='full' /></pre>
	  if(cookie.hi == "Hi!")
	    cookie.hi = "Ho!";
	  else
	    cookie.hi = "Hi!";
	?>
	</body>
</html>

But how to access roxen api? where can I get full roxen api for
pike,such as get request object and make response?
--

-- 
cleverpig
Location: Beijing
Address: Room 4018,No.A2 South Avenue Fuxingmen Beijing,P.R.China
Zipcode: 100031
MSN: great_liudan <at> hotmail.com
QQ: 149291732
Skype: cleverpigatmatrix
My Facebook ID:cleverpig
My Blog: www.morpheus.org.cn
My Tags: del.icio.us/cleverpig
My Twitter: twitter.com/cleverpig
My Organization: www.beijing-open-party.org
My Organ <at> Facebook: http://www.facebook.com/group.php?gid=8159558294

Felip Alàez Nadal | 24 Aug 21:15

Re: where is Math.Matrix->`/ ?

Thanks you!

I'll add lu decomposition and resolution of linear equations systems to Math.Matrix. Also the inverse of a matrix.

Bye!

--
Felip Alàez Nadal

Re: where is Math.Matrix->`/ ?

True, will change that for a future patch.

Re: where is Math.Matrix->`/ ?

get and set would probably be more in line with the terminology
elsewhere in Pike.

Re: where is Math.Matrix->`/ ?

Something like this, maybe?

Feel free to patch your Pike and test it out. I'm not checking this in
for the current 7.8.

/Mirar

 | > Math.Matrix m=Math.Matrix(3,4);
 | (2) Result: Math.Matrix( ({ ({      1,      0,      0}),
 |                             ({      0,      1,      0}),
 |                             ({      0,      0,      1}),
 |                             ({      0,      0,      0}) }) )
 | > for (int i=0; i<3; i++) for (int j=0; j<4; j++) m->poke(i,j,i*10+j); m;
 | Ok.
 | (3) Result: Math.Matrix( ({ ({      0,     10,     20}),
 |                             ({      1,     11,     21}),
 |                             ({      2,     12,     22}),
 |                             ({      3,     13,     23}) }) )
 | > m->peek(1,1);                                                          
 | (4) Result: 11.0
 | > m->peek(2,1);
 | (5) Result: 21.0

 | > object m=Math.Matrix(({1,2,3,4})/2);
 | > object m2=Math.Matrix(m);
 | > m2->poke(0,1,17);
 | (1) Result: Math.Matrix( ({ ({      1,      2}),
 |                             ({     17,      4}) }) )
 | > m;
 | (2) Result: Math.Matrix( ({ ({      1,      2}),
 |                             ({      3,      4}) }) )

Patch:

Index: math_matrix.c
===================================================================
RCS file: /pike/data/cvsroot/Pike/7.8/src/modules/Math/math_matrix.c,v
retrieving revision 1.40
diff -u -r1.40 math_matrix.c
--- math_matrix.c	18 Dec 2007 23:24:49 -0000	1.40
+++ math_matrix.c	24 Aug 2008 16:13:40 -0000
@@ -64,7 +64,9 @@
 #define Xmatrix(X) PIKE_CONCAT(X,imatrix)
 #define XmatrixY(X,Y) PIKE_CONCAT3(X,imatrix,Y)
 #define PUSH_ELEM( X )  push_int( (INT_TYPE)(X) )
+#define INT_ELEMS
 #include <matrix_code.h>
+#undef INT_ELEMS
 #undef PUSH_ELEM
 #undef Xmatrix
 #undef matrixX
@@ -81,7 +83,9 @@
 #define Xmatrix(X) PIKE_CONCAT(X,lmatrix)
 #define XmatrixY(X,Y) PIKE_CONCAT3(X,lmatrix,Y)
 #define PUSH_ELEM( X )  push_int64( (INT64)(X) )
+#define INT_ELEMS
 #include <matrix_code.h>
+#undef INT_ELEMS
 #undef PUSH_ELEM
 #undef Xmatrix
 #undef matrixX
@@ -114,7 +118,9 @@
 #define Xmatrix(X) PIKE_CONCAT(X,smatrix)
 #define XmatrixY(X,Y) PIKE_CONCAT3(X,smatrix,Y)
 #define PUSH_ELEM( X )  push_int( (INT_TYPE)(X) )
+#define INT_ELEMS
 #include <matrix_code.h>
+#undef INT_ELEMS
 #undef PUSH_ELEM
 #undef Xmatrix
 #undef matrixX
@@ -150,6 +156,10 @@
  *! rotation matrix.
  */

+/*! @decl void create(Matrix to_clone)
+ *! When given another @[Matrix] of similar type as argumnet, this is cloned.
+ */
+
 /* ---------------------------------------------------------------- */

 /*! @decl array(array) cast(string to_what)
@@ -237,6 +247,17 @@
  *!     Returns the height of the matrix.
  */

+/*! @decl Matrix poke(int x,int y,float value)
+ *! @decl Matrix poke(int column,int row,float value)
+ *!     Destructively change a value in the matrix. 0,0 is top left.
+ */
+
+/*! @decl float peek(int x,int y)
+ *! @decl float peek(int column,int row)
+ *!     Read out one value from the matrix. 0,0 is top left.
+ */
+
+
 /*! @endclass
  */

Index: matrix_code.h
===================================================================
RCS file: /pike/data/cvsroot/Pike/7.8/src/modules/Math/matrix_code.h,v
retrieving revision 1.20
diff -u -r1.20 matrix_code.h
--- matrix_code.h	28 Jun 2008 23:05:59 -0000	1.20
+++ matrix_code.h	24 Aug 2008 16:13:40 -0000
@@ -204,6 +204,26 @@
 done_made:
       ;
    }
+   else if (Pike_sp[-args].type==T_OBJECT)
+   {
+      struct matrixX(_storage) *mx=NULL;
+
+      if (Pike_sp[-args].type!=T_OBJECT ||
+	  !((mx=(struct matrixX(_storage)*)
+	     get_storage(Pike_sp[-1].u.object,XmatrixY(math_,_program)))))
+	 SIMPLE_BAD_ARG_ERROR(PNAME,1,"object(Math."PNAME")");
+      
+      THIS->xsize=xs=mx->xsize;
+      THIS->ysize=ys=mx->ysize;
+
+      THIS->m=m=malloc(sizeof(FTYPE)*xs*ys);
+      if (!m)
+	 SIMPLE_OUT_OF_MEMORY_ERROR(PNAME,
+				    sizeof(FTYPE)*xs*ys);
+      MEMCPY(THIS->m,
+	     mx->m,
+	     sizeof(FTYPE)*xs*ys);
+   }
    else if (Pike_sp[-args].type==T_STRING)
    {
       char *dummy;
@@ -939,6 +959,42 @@
 }

 
+static void matrixX(_poke)(INT32 args)
+{
+   INT_TYPE row,column;
+#ifdef INT_ELEMS
+   LONGEST value;
+   get_all_args("poke",args,"%i%i%l",&column,&row,&value);
+#else
+   FLOAT_TYPE value;
+   get_all_args("poke",args,"%i%i%F",&column,&row,&value);
+#endif
+
+   if (row<0 || row>=THIS->ysize)
+      SIMPLE_BAD_ARG_ERROR("poke",2, "No such row");
+   if (column<0 || column>=THIS->ysize)
+      SIMPLE_BAD_ARG_ERROR("poke",2, "No such column");
+
+   THIS->m[row*THIS->xsize+column]=(FTYPE)value;
+
+   pop_n_elems(args);
+   ref_push_object(THISOBJ);
+}
+
+static void matrixX(_peek)(INT32 args)
+{
+   INT_TYPE row,column;
+
+   get_all_args("poke",args,"%i%i",&column,&row);
+   if (row<0 || row>=THIS->ysize)
+      SIMPLE_BAD_ARG_ERROR("peek",2, "No such row");
+   if (column<0 || column>=THIS->ysize)
+      SIMPLE_BAD_ARG_ERROR("peek",2, "No such column");
+
+   pop_n_elems(args);
+   PUSH_ELEM(THIS->m[row*THIS->xsize+column]);
+}
+
 /* ---------------------------------------------------------------- */

 void Xmatrix(init_math_)(void)
@@ -959,9 +1015,10 @@
    set_exit_callback(Xmatrix(exit_));

    ADD_FUNCTION("create",matrixX(_create),
-		tOr4( tFunc(tArr(tArr(tOr(tInt,tFloat))), tVoid),
+		tOr5( tFunc(tArr(tArr(tOr(tInt,tFloat))), tVoid),
 		      tFunc(tArr(tOr(tInt,tFloat)), tVoid),
 		      tFuncV(tStr, tMix, tVoid),
+		      tFunc(tObj, tVoid),
 		      tFunc(tInt1Plus tInt1Plus tOr4(tInt,tFloat,tString,tVoid), tVoid)), ID_PROTECTED);

    ADD_FUNCTION("cast",matrixX(_cast),
@@ -1008,6 +1065,9 @@
    ADD_FUNCTION("xsize", matrixX(_xsize), tFunc(tNone, tInt), 0);
    ADD_FUNCTION("ysize", matrixX(_ysize), tFunc(tNone, tInt), 0);

+   ADD_FUNCTION("poke", matrixX(_poke), tFunc(tInt tInt tOr(tFloat,tInt),tObj), 0);
+   ADD_FUNCTION("peek", matrixX(_peek), tFunc(tInt tInt,PTYPE), 0);
+
    Pike_compiler->new_program->flags |= 
      PROGRAM_CONSTANT |
      PROGRAM_NO_EXPLICIT_DESTRUCT ;

Felip Alàez Nadal | 24 Aug 14:03

Re: where is Math.Matrix->`/ ?



2008/8/24 Mirar <at> Pike importmöte för mailinglistan <6341 <at> lyskom.lysator.liu.se>
It does? I'm not sure when you want to use it.

It should be easy to do with an intermediate object that remembers the
first indexing.

When implementing matrix methods, It should be faster to access directly to the underlying C array than casting to an pike array when you want to access to some element at the array. As an example, when you want to implement least squares, or to do some computations with scattering matrices, you need to access lots of times to the elements at the matrix to do lots of computations. You can have an immutable matrix object like Pike has, and It makes easier to do the already implemented operations on matrices, but It's harder to and inneficient to create new matrix objects everytime you need to do something.

That's why I need indexing. I thing using intermediate objects is too much slow. Think about a 5000x5000 matrix being accessed milions of times. That's too much overhead.

I'll send you any patch I develop. Bye!


--
Felip Alàez Nadal

Gmane