chiark / gitweb /
Can parse a key file. Cleared up raw confusion.
[chiark-tcl.git] / dgram / dgram.c
index a2a2f974d7bce0655d52858f2ade07fbe8b5a29f..bb538bf2f1b4d11c9ff39d6ee0be7de6cd602aa7 100644 (file)
@@ -198,7 +198,7 @@ int pat_sockid(Tcl_Interp *ip, Tcl_Obj *o, DgramSocket **val) {
   int rc, sockix;
   DgramSocket *sock;
   
-  rc= Tcl_ConvertToType(ip,o,&sockid_type);
+  rc= Tcl_ConvertToType(ip,o,&dgramsockid_type);
   if (rc) return rc;
 
   sockix= o->internalRep.longValue;
@@ -217,7 +217,7 @@ Tcl_Obj *ret_sockid(Tcl_Interp *ip, DgramSocket *val) {
   o= Tcl_NewObj();
   Tcl_InvalidateStringRep(o);
   o->internalRep.longValue= val->ix;
-  o->typePtr= &sockid_type;
+  o->typePtr= &dgramsockid_type;
   return o;
 }
 
@@ -228,13 +228,13 @@ static void sockid_t_dup(Tcl_Obj *src, Tcl_Obj *dup) {
 }
 
 static void sockid_t_ustr(Tcl_Obj *o) {
-  char buf[100];
-  int l;
+  char buf[75];
 
-  snprintf(buf,sizeof(buf),"dgramsock%d", (int)o->internalRep.longValue);
-  l= o->length= strlen(buf);
-  o->bytes= TALLOC(l+1);
-  strcpy(o->bytes, buf);
+  snprintf(buf,sizeof(buf), "%d", (int)o->internalRep.longValue);
+  obj_updatestr_vstringls(o,
+                         "dgramsock",9,
+                         buf, strlen(buf),
+                         (char*)0);
 }
 
 static int sockid_t_sfa(Tcl_Interp *ip, Tcl_Obj *o) {
@@ -246,11 +246,14 @@ static int sockid_t_sfa(Tcl_Interp *ip, Tcl_Obj *o) {
   errno=0; ul=strtoul(str+9,&ep,10);
   if (errno || *ep) return staticerr(ip,"bad dgram socket id number");
   if (ul > INT_MAX) return staticerr(ip,"out of range dgram socket id");
+
+  objfreeir(o);
   o->internalRep.longValue= ul;
+  o->typePtr= &dgramsockid_type;
   return TCL_OK;
 }
 
-Tcl_ObjType sockid_type = {
-  "sockid-nearly",
+Tcl_ObjType dgramsockid_type = {
+  "dgramsockid",
   sockid_t_free, sockid_t_dup, sockid_t_ustr, sockid_t_sfa
 };