static void WriteBytesNativeString(void *addr, UInt count) { Obj target = TLS(SerializationObj); UInt size = GET_LEN_STRING(target); GROW_STRING(target, size + count + 1); memcpy(CSTR_STRING(target) + size, addr, count); SET_LEN_STRING(target, size + count); }
static Obj VIEWSTRING_MPD(Obj self, Obj f, Obj digits) { mp_prec_t prec = mpd_get_prec(GET_MPD(f)); Obj str = NEW_STRING(2*(prec*302/1000+10)+3); int slen = 0, n; TEST_IS_INTOBJ("STRING_MPD",digits); n = INT_INTOBJ(digits); if (n == 1) n = 2; char *c = CSTR_STRING(str); slen += PRINT_MPFR(c+slen, 0, n, GET_MPD(f)->re, GMP_RNDN); Obj im = NEW_MPFR(prec); mpfr_add(MPFR_OBJ(im), GET_MPD(f)->re, GET_MPD(f)->im, GMP_RNDN); mpfr_sub(MPFR_OBJ(im), MPFR_OBJ(im), MPD_OBJ(f)->re, GMP_RNDN); /* round off small im */ if (!mpfr_zero_p(MPFR_OBJ(im))) { if (mpfr_sgn(MPFR_OBJ(im)) < 0) c[slen++] = '-'; else c[slen++] = '+'; mpfr_abs (MPFR_OBJ(im), MPD_OBJ(f)->im, GMP_RNDN); c[slen++] = 'I'; c[slen++] = '*'; slen += PRINT_MPFR(c+slen, 0, n, MPFR_OBJ(im), GMP_RNDN); } SET_LEN_STRING(str, slen); SHRINK_STRING(str); return str; }
static void WriteBytesNativeString(void * addr, UInt count) { Obj target = MODULE_STATE(Serialize).obj; UInt size = GET_LEN_STRING(target); GROW_STRING(target, size + count + 1); memcpy(CSTR_STRING(target) + size, addr, count); SET_LEN_STRING(target, size + count); }
Obj MPIerror_string( Obj self, Obj errorcode ) { int resultlen; Obj str; str = NEW_STRING( 72 ); MPI_Error_string( INT_INTOBJ(errorcode), (char*)CSTR_STRING(str), &resultlen); ((char*)CSTR_STRING(str))[resultlen] = '\0'; SET_LEN_STRING(str, resultlen); ResizeBag( str, SIZEBAG_STRINGLEN( GET_LEN_STRING(str) ) ); return str; }
Obj MPIget_processor_name( Obj self ) { int resultlen; Obj str; /* It was reported by Frank Celler that a value of 72 instead of 1024 below caused overwriting of the free block list on PC in GAP-3 */ str = NEW_STRING( 1024 ); MPI_Get_processor_name( (char*)CSTR_STRING(str), &resultlen); ((char*)CSTR_STRING(str))[resultlen] = '\0'; #ifndef PRE_GAP_4_3 SET_LEN_STRING(str, resultlen); ResizeBag( str, SIZEBAG_STRINGLEN( GET_LEN_STRING(str) ) ); #endif return str; }
/**************************************************************************** ** *F AppendBufToString() ** ** Append 'bufsize' bytes from the string buffer 'buf' to the string object ** 'string'. If 'string' is 0, then a new string object is allocated first. ** ** The string object is returned at the end, regardless of whether it was ** given as an argument, or created from scratch. ** */ static Obj AppendBufToString(Obj string, const char * buf, UInt bufsize) { char *s; if (string == 0) { string = NEW_STRING(bufsize); s = CSTR_STRING(string); } else { const UInt len = GET_LEN_STRING(string); GROW_STRING(string, len + bufsize); SET_LEN_STRING(string, len + bufsize); s = CSTR_STRING(string) + len; } memcpy(s, buf, bufsize); s[bufsize] = '\0'; return string; }
Obj FuncREAD_IOSTREAM_NOWAIT(Obj self, Obj stream, Obj len) { Obj string; UInt pty = INT_INTOBJ(stream); Int ret; string = NEW_STRING(INT_INTOBJ(len)); while (!PtyIOStreams[pty].inuse) pty = INT_INTOBJ(ErrorReturnObj("IOSTREAM %d is not in use",pty,0L, "you can replace stream number <num> via 'return <num>;'")); /* HandleChildStatusChanges(pty); Omit this to allow picking up "trailing" bytes*/ ret = ReadFromPty2(pty, CSTR_STRING(string), INT_INTOBJ(len), 0); if (ret == -1) return Fail; SET_LEN_STRING(string, ret); ResizeBag(string, SIZEBAG_STRINGLEN(ret)); return string; }
static Obj STRING_MPD(Obj self, Obj f, Obj digits) { mp_prec_t prec = mpd_get_prec(GET_MPD(f)); Obj str = NEW_STRING(2*(prec*302/1000+10)+3); int slen = 0, n; TEST_IS_INTOBJ("STRING_MPD",digits); n = INT_INTOBJ(digits); if (n == 1) n = 2; char *c = CSTR_STRING(str); slen += PRINT_MPFR(c+slen, 0, n, GET_MPD(f)->re, GMP_RNDN); c[slen++] = '+'; c[slen++] = 'I'; c[slen++] = '*'; slen += PRINT_MPFR(c+slen, 0, n, MPD_OBJ(f)->im, GMP_RNDN); SET_LEN_STRING(str, slen); SHRINK_STRING(str); return str; }