Changeset a796fb in git
- Timestamp:
- Mar 30, 2011, 1:49:51 PM (12 years ago)
- Branches:
- (u'jengelh-datetime', 'ceac47cbc86fe4a15902392bdbb9bd2ae0ea02c6')(u'spielwiese', 'a800fe4b3e9d37a38c5a10cc0ae9dfa0c15a4ee6')
- Children:
- 09b38e3ceb9920dc88bd2e2cdfd3d5940ea0c658
- Parents:
- 166ebd23be74a96b55b07ae3ee7b95a6fff5d62a
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
Singular/ssiLink.cc
r166ebd2 ra796fb 19 19 #include <ctype.h> /*for isdigit*/ 20 20 #include <netdb.h> 21 #include <sys/wait.h> 22 21 23 22 24 … … 76 78 77 79 link_list ssiToBeClosed=NULL; 80 sigset_t ssi_sigmask; 81 sigset_t ssi_oldmask; 82 #define SSI_BLOCK_CHLD sigprocmask(SIG_SETMASK, &ssi_sigmask, &ssi_oldmask) 83 #define SSI_UNBLOCK_CHLD sigprocmask(SIG_SETMASK, &ssi_oldmask, NULL) 78 84 79 85 // the helper functions: … … 96 102 void ssiWriteInt(ssiInfo *d,const int i) 97 103 { 104 SSI_BLOCK_CHLD; 98 105 fprintf(d->f_write,"%d ",i); 106 SSI_UNBLOCK_CHLD; 99 107 //if (d->f_debug!=NULL) fprintf(d->f_debug,"int: %d ",i); 100 108 } … … 102 110 void ssiWriteString(ssiInfo *d,const char *s) 103 111 { 112 SSI_BLOCK_CHLD; 104 113 fprintf(d->f_write,"%d %s ",strlen(s),s); 114 SSI_UNBLOCK_CHLD; 105 115 //if (d->f_debug!=NULL) fprintf(d->f_debug,"stringi: %d \"%s\" ",strlen(s),s); 106 116 } … … 112 122 // case 2 Q: 3 4 <int> 113 123 // or 3 3 <mpz_t nominator> 124 SSI_BLOCK_CHLD; 114 125 if(SR_HDL(n) & SR_INT) 115 126 { … … 126 137 } 127 138 else Werror("illiegal bigint"); 139 SSI_UNBLOCK_CHLD; 128 140 } 129 141 … … 139 151 // or 3 6 <mpz_t raw nom.> <mpz_t raw denom.> 140 152 // or 3 7 <mpz_t raw nom.> 153 SSI_BLOCK_CHLD; 141 154 if(rField_is_Zp(d->r)) 142 155 { … … 173 186 } 174 187 else WerrorS("coeff field not implemented"); 188 SSI_UNBLOCK_CHLD; 175 189 } 176 190 177 191 void ssiWriteRing(ssiInfo *d,const ring r) 178 192 { 179 /* 5 <ch> <N> <l1> < s1>....<ln> <sN>*/193 /* 5 <ch> <N> <l1> <v1> ...<lN> <vN> <number of orderings> <ord1> <block0_1> <block1_1> .... */ 180 194 if (d->r!=NULL) rKill(d->r); 181 195 d->r=r; 182 196 d->r->ref++; 197 SSI_BLOCK_CHLD; 183 198 fprintf(d->f_write,"%d %d ",r->ch,r->N); 184 199 … … 199 214 i++; 200 215 } 216 SSI_UNBLOCK_CHLD; 201 217 } 202 218 203 219 void ssiWritePoly(ssiInfo *d, int typ, poly p) 204 220 { 221 SSI_BLOCK_CHLD; 205 222 fprintf(d->f_write,"%d ",pLength(p));//number of terms 223 SSI_UNBLOCK_CHLD; 206 224 int i; 207 225 … … 210 228 ssiWriteNumber(d,pGetCoeff(p)); 211 229 //nWrite(fich,pGetCoeff(p)); 230 SSI_BLOCK_CHLD; 212 231 fprintf(d->f_write,"%ld ",p_GetComp(p,d->r));//component 213 232 … … 217 236 } 218 237 pIter(p); 238 SSI_UNBLOCK_CHLD; 219 239 } 220 240 } … … 225 245 // syntax: 8 <rows> <cols> <poly 1> <poly2>..... 226 246 matrix M=(matrix)I; 247 SSI_BLOCK_CHLD; 227 248 if (typ==MATRIX_CMD) 228 249 fprintf(d->f_write,"%d %d ", MATROWS(M),MATCOLS(M)); 229 250 else 230 251 fprintf(d->f_write,"%d ",IDELEMS(I)); 252 SSI_UNBLOCK_CHLD; 231 253 232 254 int i; … … 244 266 ssiInfo *d=(ssiInfo*)l->data; 245 267 // syntax: <num ops> <operation> <op1> <op2> .... 268 SSI_BLOCK_CHLD; 246 269 fprintf(d->f_write,"%d %d ",D->argc,D->op); 270 SSI_UNBLOCK_CHLD; 247 271 if (D->argc >0) ssiWrite(l, &(D->arg1)); 248 272 if (D->argc < 4) … … 261 285 { 262 286 ssiInfo *d=(ssiInfo*)l->data; 287 SSI_BLOCK_CHLD; 263 288 fprintf(d->f_write,"%d ",dd->nr+1); 289 SSI_UNBLOCK_CHLD; 264 290 int i; 265 291 for(i=0;i<=dd->nr;i++) … … 270 296 void ssiWriteIntvec(ssiInfo *d,intvec * v) 271 297 { 298 SSI_BLOCK_CHLD; 272 299 fprintf(d->f_write,"%d ",v->length()); 273 300 int i; … … 276 303 fprintf(d->f_write,"%d ",(*v)[i]); 277 304 } 305 SSI_UNBLOCK_CHLD; 278 306 } 279 307 … … 282 310 char *buf; 283 311 int l; 312 SSI_BLOCK_CHLD; 284 313 fscanf(d->f_read,"%d ",&l); 314 SSI_UNBLOCK_CHLD; 285 315 buf=(char*)omAlloc(l+1); 316 SSI_BLOCK_CHLD; 286 317 fread(buf,1,l,d->f_read); 318 SSI_UNBLOCK_CHLD; 287 319 buf[l]='\0'; 288 320 return buf; … … 292 324 { 293 325 int d; 326 SSI_BLOCK_CHLD; 294 327 fscanf(fich,"%d",&d); 328 SSI_UNBLOCK_CHLD; 295 329 return d; 296 330 } … … 298 332 number ssiReadBigInt(ssiInfo *d) 299 333 { 300 int sub_type=-1; 301 fscanf(d->f_read,"%d",&sub_type); 302 switch(sub_type) 303 { 334 int sub_type=-1; 335 SSI_BLOCK_CHLD; 336 fscanf(d->f_read,"%d",&sub_type); 337 SSI_UNBLOCK_CHLD; 338 switch(sub_type) 339 { 304 340 case 3: 305 341 {// read int or mpz_t or mpz_t, mpz_t 306 342 number n=nlRInit(0); 343 SSI_BLOCK_CHLD; 307 344 mpz_inp_str(n->z,d->f_read,0); 345 SSI_UNBLOCK_CHLD; 308 346 n->s=sub_type; 309 347 return n; 310 348 } 311 case 4: { int dd; fscanf(d->f_read,"%d",&dd); return INT_TO_SR(dd); } 312 default: Werror("error in reading bigint: invalid subtype %d",sub_type); 313 return NULL; 349 case 4: 350 { 351 int dd; 352 SSI_BLOCK_CHLD; 353 fscanf(d->f_read,"%d",&dd); 354 SSI_UNBLOCK_CHLD; 355 return INT_TO_SR(dd); 356 } 357 default: 358 Werror("error in reading bigint: invalid subtype %d",sub_type); 359 return NULL; 314 360 } 315 361 } … … 320 366 { 321 367 int sub_type=-1; 368 SSI_BLOCK_CHLD; 322 369 fscanf(d->f_read,"%d",&sub_type); 370 SSI_UNBLOCK_CHLD; 323 371 switch(sub_type) 324 372 { … … 326 374 case 1: 327 375 {// read mpz_t, mpz_t 328 number n=nlRInit(0); 329 mpz_init(n->n); 330 gmp_fscanf(d->f_read,"%Zd %Zd",n->z,n->n); 331 n->s=sub_type; 332 return n; 376 number n=nlRInit(0); 377 mpz_init(n->n); 378 SSI_BLOCK_CHLD; 379 gmp_fscanf(d->f_read,"%Zd %Zd",n->z,n->n); 380 SSI_UNBLOCK_CHLD; 381 n->s=sub_type; 382 return n; 333 383 } 334 384 … … 336 386 {// read mpz_t 337 387 number n=nlRInit(0); 388 SSI_BLOCK_CHLD; 338 389 gmp_fscanf(d->f_read,"%Zd",n->z); 390 SSI_UNBLOCK_CHLD; 339 391 n->s=3; /*sub_type*/ 340 392 return n; 341 393 } 342 case 4: { int dd; fscanf(d->f_read,"%d",&dd); return INT_TO_SR(dd); } 394 case 4: 395 { 396 int dd; 397 SSI_BLOCK_CHLD; 398 fscanf(d->f_read,"%d",&dd); 399 SSI_UNBLOCK_CHLD; 400 return INT_TO_SR(dd); 401 } 343 402 case 5: 344 403 case 6: 345 404 {// read raw mpz_t, mpz_t 346 number n=nlRInit(0); 347 mpz_init(n->n); 348 mpz_inp_str (n->z, d->f_read, 32); 349 mpz_inp_str (n->n, d->f_read, 32); 350 n->s=sub_type-5; 351 return n; 405 number n=nlRInit(0); 406 mpz_init(n->n); 407 SSI_BLOCK_CHLD; 408 mpz_inp_str (n->z, d->f_read, 32); 409 mpz_inp_str (n->n, d->f_read, 32); 410 SSI_UNBLOCK_CHLD; 411 n->s=sub_type-5; 412 return n; 352 413 } 353 414 case 8: 354 415 {// read raw mpz_t 355 number n=nlRInit(0); 356 mpz_inp_str (n->z, d->f_read, 32); 357 n->s=sub_type=3; /*subtype-5*/ 358 return n; 416 number n=nlRInit(0); 417 SSI_BLOCK_CHLD; 418 mpz_inp_str (n->z, d->f_read, 32); 419 SSI_UNBLOCK_CHLD; 420 n->s=sub_type=3; /*subtype-5*/ 421 return n; 359 422 } 360 423 … … 367 430 // read int 368 431 int dd; 432 SSI_BLOCK_CHLD; 369 433 fscanf(d->f_read,"%d",&dd); 434 SSI_UNBLOCK_CHLD; 370 435 return (number)dd; 371 436 } … … 376 441 ring ssiReadRing(ssiInfo *d) 377 442 { 378 /* syntax is <ch> <N> <l1> < s1> ....<lN> <sN>*/443 /* syntax is <ch> <N> <l1> <v1> ...<lN> <vN> <number of orderings> <ord1> <block0_1> <block1_1> .... */ 379 444 int ch, N,i,l; 380 445 char **names; 446 SSI_BLOCK_CHLD; 381 447 fscanf(d->f_read,"%d %d ",&ch,&N); 448 SSI_UNBLOCK_CHLD; 382 449 names=(char**)omAlloc(N*sizeof(char*)); 383 450 for(i=0;i<N;i++) … … 387 454 // read the orderings: 388 455 int num_ord; // number of orderings 456 SSI_BLOCK_CHLD; 389 457 fscanf(d->f_read,"%d",&num_ord); 458 SSI_UNBLOCK_CHLD; 390 459 int *ord=(int *)omAlloc0((num_ord+1)*sizeof(int)); 391 460 int *block0=(int *)omAlloc0((num_ord+1)*sizeof(int)); 392 461 int *block1=(int *)omAlloc0((num_ord+1)*sizeof(int)); 462 SSI_BLOCK_CHLD; 393 463 for(i=0;i<num_ord;i++) 394 464 { 395 465 fscanf(d->f_read,"%d %d %d",&ord[i],&block0[i],&block1[i]); 396 466 } 467 SSI_UNBLOCK_CHLD; 397 468 return rDefault(ch,N,names,num_ord,ord,block0,block1); 398 469 } … … 415 486 pGetCoeff(p)=ssiReadNumber(D); 416 487 int d; 488 SSI_BLOCK_CHLD; 417 489 fscanf(D->f_read,"%d",&d); 490 SSI_UNBLOCK_CHLD; 418 491 p_SetComp(p,d,D->r); 419 492 for(i=1;i<=rVar(D->r);i++) 420 493 { 494 SSI_BLOCK_CHLD; 421 495 fscanf(D->f_read,"%d",&d); 496 SSI_UNBLOCK_CHLD; 422 497 p_SetExp(p,i,d,D->r); 423 498 } … … 435 510 int n,i; 436 511 ideal I; 512 SSI_BLOCK_CHLD; 437 513 fscanf(d->f_read,"%d",&n); 514 SSI_UNBLOCK_CHLD; 438 515 I=idInit(n,1); 439 516 for(i=0;i<IDELEMS(I);i++) // read n terms … … 447 524 { 448 525 int n,m,i,j; 526 SSI_BLOCK_CHLD; 449 527 fscanf(d->f_read,"%d %d",&m,&n); 528 SSI_UNBLOCK_CHLD; 450 529 matrix M=mpNew(m,n); 451 530 poly p; … … 465 544 command D=(command)omAlloc0(sizeof(*D)); 466 545 int argc,op; 546 SSI_BLOCK_CHLD; 467 547 fscanf(d->f_read,"%d %d",&argc,&op); 548 SSI_UNBLOCK_CHLD; 468 549 D->argc=argc; D->op=op; 469 550 leftv v; … … 518 599 ssiInfo *d=(ssiInfo*)l->data; 519 600 int nr; 601 SSI_BLOCK_CHLD; 520 602 fscanf(d->f_read,"%d",&nr); 603 SSI_UNBLOCK_CHLD; 521 604 lists L=(lists)omAlloc(sizeof(*L)); 522 605 L->Init(nr); … … 535 618 { 536 619 int nr; 620 SSI_BLOCK_CHLD; 537 621 fscanf(d->f_read,"%d",&nr); 622 SSI_UNBLOCK_CHLD; 538 623 intvec *v=new intvec(nr); 624 SSI_BLOCK_CHLD; 539 625 for(int i=0;i<nr;i++) 540 626 { 541 627 fscanf(d->f_read,"%d",&((*v)[i])); 542 628 } 629 SSI_UNBLOCK_CHLD; 543 630 return v; 544 631 } 545 632 546 633 //**************************************************************************/ 634 547 635 BOOLEAN ssiOpen(si_link l, short flag, leftv u) 548 636 { 549 637 const char *mode; 550 638 ssiInfo *d=(ssiInfo*)omAlloc0(sizeof(ssiInfo)); 639 sigprocmask(SIG_SETMASK, NULL, &ssi_sigmask); 640 sigaddset(&ssi_sigmask, SIGCHLD); 551 641 if (flag & SI_LINK_OPEN) 552 642 { … … 911 1001 if (d->f_write!=NULL) fclose(d->f_write); 912 1002 if (d->r!=NULL) rKill(d->r); 913 if (d->pid!=0) { kill(d->pid,15); kill(d->pid,9); } 1003 if (d->pid!=0) 1004 { 1005 int status; 1006 kill(d->pid,15); 1007 kill(d->pid,9); 1008 waitpid(d->pid,&status,0); 1009 } 914 1010 omFreeSize((ADDRESS)d,(sizeof *d)); 915 1011 } … … 926 1022 leftv res=(leftv)omAlloc0(sizeof(sleftv)); 927 1023 int t=0; 1024 SSI_BLOCK_CHLD; 928 1025 fscanf(d->f_read,"%d",&t); 1026 SSI_UNBLOCK_CHLD; 929 1027 //Print("got type %d\n",t); 930 1028 switch(t) … … 1005 1103 int n98_v,n98_m; 1006 1104 BITSET n98_o1,n98_o2; 1105 SSI_BLOCK_CHLD; 1007 1106 fscanf(d->f_read,"%d %d %u %u\n",&n98_v,&n98_m,&n98_o1,&n98_o2); 1107 SSI_UNBLOCK_CHLD; 1008 1108 if ((n98_v!=SSI_VERSION) ||(n98_m!=MAX_TOK)) 1009 1109 { … … 1033 1133 return res; 1034 1134 no_ring: WerrorS("no ring"); 1135 omFreeSize(res,sizeof(sleftv)); 1035 1136 return NULL; 1036 1137 } … … 1319 1420 s = pselect(max_fd, &mask, NULL, NULL, wt_ptr, &sigmask); 1320 1421 #else 1321 sigset_t origsigmask; 1322 1323 sigprocmask(SIG_SETMASK, &sigmask, &origsigmask); 1324 s = select(max_fd, &mask, NULL, NULL, wt_ptr); 1325 sigprocmask(SIG_SETMASK, &origsigmask, NULL); 1326 #endif 1422 SSI_BLOCK_CHLD; 1423 s = select(max_fd, &mask, NULL, NULL, wt_ptr); 1424 SSI_UNBLOCK_CHLD; 1425 #endif 1327 1426 1328 1427 if (s==-1) 1329 { 1428 { 1330 1429 WerrorS("error in select call"); 1331 1430 return -2; /*error*/
Note: See TracChangeset
for help on using the changeset viewer.