mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
2000-01-08
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@601 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
a3da8465b4
commit
a69b9bce31
12 changed files with 403 additions and 386 deletions
|
@ -1,3 +1,12 @@
|
|||
Fri Jan 7 00:59:29 2000 Masahiro Tomita <tommy@tmtm.org>
|
||||
|
||||
* io.c (io_fread): TRAP_BEG/TRAP_END added around getc().
|
||||
|
||||
Thu Jan 6 00:39:54 2000 Yukihiro Matsumoto <matz@netlab.co.jp>
|
||||
|
||||
* random.c (rb_f_rand): should be initialized unless srand is
|
||||
called before.
|
||||
|
||||
Wed Jan 5 02:14:46 2000 EGUCHI Osamu <eguchi@shizuokanet.ne.jp>
|
||||
|
||||
* parse.y: Fix SEGV on empty parens with UMINUS or UPLUS.
|
||||
|
|
54
array.c
54
array.c
|
@ -292,31 +292,6 @@ rb_ary_pop(ary)
|
|||
return RARRAY(ary)->ptr[--RARRAY(ary)->len];
|
||||
}
|
||||
|
||||
static VALUE
|
||||
rb_ary_pop_m(argc, argv, ary)
|
||||
int argc;
|
||||
VALUE *argv;
|
||||
VALUE ary;
|
||||
{
|
||||
int n = 1;
|
||||
VALUE result;
|
||||
|
||||
if (argc == 0) {
|
||||
return rb_ary_pop(ary);
|
||||
}
|
||||
if (argc > 2) {
|
||||
rb_raise(rb_eArgError, "wrong # of arguments (%d for 1)", argc);
|
||||
}
|
||||
n = NUM2INT(argv[0]);
|
||||
if (RARRAY(ary)->len < n)
|
||||
n = RARRAY(ary)->len;
|
||||
result = rb_ary_new2(n);
|
||||
while (n--) {
|
||||
rb_ary_store(result, n, rb_ary_pop(ary));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
VALUE
|
||||
rb_ary_shift(ary)
|
||||
VALUE ary;
|
||||
|
@ -339,31 +314,6 @@ rb_ary_shift(ary)
|
|||
return top;
|
||||
}
|
||||
|
||||
static VALUE
|
||||
rb_ary_shift_m(argc, argv, ary)
|
||||
int argc;
|
||||
VALUE *argv;
|
||||
VALUE ary;
|
||||
{
|
||||
int n = 1;
|
||||
VALUE result;
|
||||
|
||||
if (argc == 0) {
|
||||
return rb_ary_shift(ary);
|
||||
}
|
||||
if (argc > 2) {
|
||||
rb_raise(rb_eArgError, "wrong # of arguments (%d for 1)", argc);
|
||||
}
|
||||
n = NUM2INT(argv[0]);
|
||||
if (RARRAY(ary)->len < n)
|
||||
n = RARRAY(ary)->len;
|
||||
result = rb_ary_new2(n);
|
||||
while (n--) {
|
||||
rb_ary_push(result, rb_ary_shift(ary));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
VALUE
|
||||
rb_ary_unshift(ary, item)
|
||||
VALUE ary, item;
|
||||
|
@ -1600,8 +1550,8 @@ Init_Array()
|
|||
rb_define_method(rb_cArray, "concat", rb_ary_concat, 1);
|
||||
rb_define_method(rb_cArray, "<<", rb_ary_push, 1);
|
||||
rb_define_method(rb_cArray, "push", rb_ary_push_m, -1);
|
||||
rb_define_method(rb_cArray, "pop", rb_ary_pop_m, -1);
|
||||
rb_define_method(rb_cArray, "shift", rb_ary_shift_m, -1);
|
||||
rb_define_method(rb_cArray, "pop", rb_ary_pop, 0);
|
||||
rb_define_method(rb_cArray, "shift", rb_ary_shift, 0);
|
||||
rb_define_method(rb_cArray, "unshift", rb_ary_unshift, 1);
|
||||
rb_define_method(rb_cArray, "each", rb_ary_each, 0);
|
||||
rb_define_method(rb_cArray, "each_index", rb_ary_each_index, 0);
|
||||
|
|
|
@ -4,5 +4,6 @@ RUBYCWDLL=rubycw.dll
|
|||
|
||||
miniruby$(EXEEXT): $(RUBYCWDLL)
|
||||
|
||||
$(RUBYCWDLL): $(OBJS) dmyext.o
|
||||
$(LDSHARED) $(DLDFLAGS) -o $(RUBYCWDLL) --output-lib=$(LIBRUBY_SO) --dllname=$(RUBYCWDLL) -Wl,-e,__cygwin_noncygwin_dll_entry@12 --add-stdcall-alias $(OBJS) dmyext.o
|
||||
@NM@ --extern-only $(OBJS) dmyext.o | sed -n '/^........ [CD] _\(.*\)$$/s//#define \1 (*__imp_\1)/p' >import.h
|
||||
|
|
|
@ -92,10 +92,13 @@ static void
|
|||
sock_finalize(fptr)
|
||||
OpenFile *fptr;
|
||||
{
|
||||
if (!fptr->f) return;
|
||||
SOCKET s;
|
||||
|
||||
if (!fptr->f) return;
|
||||
s = get_osfhandle(fileno(fptr->f));
|
||||
myfdclose(fptr->f);
|
||||
if(fptr->f2) myfdclose(fptr->f2);
|
||||
if (fptr->f2) myfdclose(fptr->f2);
|
||||
closesocket(s);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
7
file.c
7
file.c
|
@ -403,8 +403,8 @@ eaccess(path, mode)
|
|||
if (st.st_mode & mode) return 0;
|
||||
|
||||
return -1;
|
||||
#else /* !NT*/
|
||||
return 0;
|
||||
#else /* !NT */
|
||||
return access(path, mode);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -1502,6 +1502,9 @@ rb_file_flock(obj, operation)
|
|||
rb_secure(2);
|
||||
GetOpenFile(obj, fptr);
|
||||
|
||||
if (fptr->mode & FMODE_WRITABLE) {
|
||||
fflush(GetWriteFile(fptr));
|
||||
}
|
||||
if (flock(fileno(fptr->f), NUM2INT(operation)) < 0) {
|
||||
#ifdef EWOULDBLOCK
|
||||
if (errno == EWOULDBLOCK) {
|
||||
|
|
5
io.c
5
io.c
|
@ -454,7 +454,9 @@ io_fread(ptr, len, f)
|
|||
if (!READ_DATA_PENDING(f)) {
|
||||
rb_thread_wait_fd(fileno(f));
|
||||
}
|
||||
TRAP_BEG;
|
||||
c = getc(f);
|
||||
TRAP_END;
|
||||
if (c == EOF) {
|
||||
*ptr = '\0';
|
||||
break;
|
||||
|
@ -1456,7 +1458,8 @@ pipe_open(pname, mode)
|
|||
pipe_add_fptr(fptr);
|
||||
if (modef & FMODE_READABLE) fptr->f = f;
|
||||
if (modef & FMODE_WRITABLE) {
|
||||
fptr->f2 = f;
|
||||
if (fptr->f) fptr->f2 = f;
|
||||
else fptr->f = f;
|
||||
rb_io_synchronized(fptr);
|
||||
}
|
||||
return (VALUE)port;
|
||||
|
|
|
@ -109,7 +109,7 @@ class DEBUGGER__
|
|||
|
||||
def var_list(ary, binding)
|
||||
ary.sort!
|
||||
if ary.size > 24
|
||||
if false # ary.size < 0
|
||||
f = open("|less", "w")
|
||||
for v in ary
|
||||
f.printf " %s => %s\n", v, eval(v, binding).inspect
|
||||
|
@ -125,7 +125,6 @@ class DEBUGGER__
|
|||
def debug_variable_info(input, binding)
|
||||
case input
|
||||
when /^\s*g(?:lobal)?$/
|
||||
f = open("|less", "w")
|
||||
var_list(global_variables, binding)
|
||||
|
||||
when /^\s*l(?:ocal)?$/
|
||||
|
@ -162,9 +161,9 @@ class DEBUGGER__
|
|||
stdout.print "\n"
|
||||
|
||||
else
|
||||
obj = debug_eval($', binding)
|
||||
obj = debug_eval(input, binding)
|
||||
unless obj.kind_of? Module
|
||||
stdout.print "should be Class/Module: ", $', "\n"
|
||||
stdout.print "should be Class/Module: ", input, "\n"
|
||||
else
|
||||
len = 0
|
||||
for v in obj.instance_methods.sort
|
||||
|
|
|
@ -1430,6 +1430,7 @@ Init_Numeric()
|
|||
|
||||
rb_define_method(rb_cNumeric, "+@", num_uplus, 0);
|
||||
rb_define_method(rb_cNumeric, "-@", num_uminus, 0);
|
||||
rb_define_method(rb_cNumeric, "===", num_equal, 1);
|
||||
rb_define_method(rb_cNumeric, "eql?", num_eql, 1);
|
||||
rb_define_method(rb_cNumeric, "divmod", num_divmod, 1);
|
||||
rb_define_method(rb_cNumeric, "abs", num_abs, 0);
|
||||
|
|
3
parse.y
3
parse.y
|
@ -588,8 +588,7 @@ undef_list : fitem
|
|||
$$ = block_append($1, NEW_UNDEF($4));
|
||||
}
|
||||
|
||||
op : tDOT2 { $$ = tDOT2; }
|
||||
| '|' { $$ = '|'; }
|
||||
op : '|' { $$ = '|'; }
|
||||
| '^' { $$ = '^'; }
|
||||
| '&' { $$ = '&'; }
|
||||
| tCMP { $$ = tCMP; }
|
||||
|
|
54
random.c
54
random.c
|
@ -81,27 +81,13 @@ static int first = 1;
|
|||
static char state[256];
|
||||
#endif
|
||||
|
||||
static VALUE
|
||||
rb_f_srand(argc, argv, obj)
|
||||
int argc;
|
||||
VALUE *argv;
|
||||
VALUE obj;
|
||||
static int
|
||||
rand_init(seed)
|
||||
long seed;
|
||||
{
|
||||
VALUE a;
|
||||
unsigned int seed, old;
|
||||
int old;
|
||||
static unsigned int saved_seed;
|
||||
|
||||
if (rb_scan_args(argc, argv, "01", &a) == 0) {
|
||||
static int n = 0;
|
||||
struct timeval tv;
|
||||
|
||||
gettimeofday(&tv, 0);
|
||||
seed = tv.tv_sec ^ tv.tv_usec ^ getpid() ^ n++;
|
||||
}
|
||||
else {
|
||||
seed = NUM2UINT(a);
|
||||
}
|
||||
|
||||
#ifdef HAVE_RANDOM
|
||||
if (first == 1) {
|
||||
initstate(1, state, sizeof state);
|
||||
|
@ -116,6 +102,30 @@ rb_f_srand(argc, argv, obj)
|
|||
old = saved_seed;
|
||||
saved_seed = seed;
|
||||
|
||||
return old;
|
||||
}
|
||||
|
||||
static VALUE
|
||||
rb_f_srand(argc, argv, obj)
|
||||
int argc;
|
||||
VALUE *argv;
|
||||
VALUE obj;
|
||||
{
|
||||
VALUE a;
|
||||
unsigned int seed, old;
|
||||
|
||||
if (rb_scan_args(argc, argv, "01", &a) == 0) {
|
||||
static int n = 0;
|
||||
struct timeval tv;
|
||||
|
||||
gettimeofday(&tv, 0);
|
||||
seed = tv.tv_sec ^ tv.tv_usec ^ getpid() ^ n++;
|
||||
}
|
||||
else {
|
||||
seed = NUM2UINT(a);
|
||||
}
|
||||
old = rand_init(seed);
|
||||
|
||||
return rb_uint2inum(old);
|
||||
}
|
||||
|
||||
|
@ -125,6 +135,14 @@ rb_f_rand(obj, vmax)
|
|||
{
|
||||
long val, max;
|
||||
|
||||
static initialized = 0;
|
||||
|
||||
if (first) {
|
||||
struct timeval tv;
|
||||
|
||||
gettimeofday(&tv, 0);
|
||||
rand_init(tv.tv_sec ^ tv.tv_usec ^ getpid());
|
||||
}
|
||||
switch (TYPE(vmax)) {
|
||||
case T_FLOAT:
|
||||
if (RFLOAT(vmax)->value <= LONG_MAX && RFLOAT(vmax)->value >= LONG_MIN)
|
||||
|
|
|
@ -229,7 +229,6 @@ char *getlogin()
|
|||
struct {
|
||||
int inuse;
|
||||
int pid;
|
||||
HANDLE oshandle;
|
||||
FILE *pipe;
|
||||
} MyPopenRecord[MYPOPENSIZE];
|
||||
|
||||
|
@ -509,23 +508,11 @@ mypopen (char *cmd, char *mode)
|
|||
sa.lpSecurityDescriptor = NULL;
|
||||
sa.bInheritHandle = TRUE;
|
||||
|
||||
if (!reading) {
|
||||
FILE *fp;
|
||||
|
||||
fp = (_popen)(cmd, mode);
|
||||
|
||||
MyPopenRecord[slot].inuse = TRUE;
|
||||
MyPopenRecord[slot].pipe = fp;
|
||||
MyPopenRecord[slot].pid = -1;
|
||||
|
||||
if (!fp)
|
||||
rb_fatal("cannot open pipe \"%s\" (%s)", cmd, strerror(errno));
|
||||
return fp;
|
||||
}
|
||||
|
||||
fRet = CreatePipe(&hInFile, &hOutFile, &sa, 2048L);
|
||||
if (!fRet)
|
||||
rb_fatal("cannot open pipe \"%s\" (%s)", cmd, strerror(errno));
|
||||
if (!fRet) {
|
||||
errno = GetLastError();
|
||||
rb_sys_fail("mypopen: CreatePipe");
|
||||
}
|
||||
|
||||
memset(&aStartupInfo, 0, sizeof (STARTUPINFO));
|
||||
memset(&aProcessInformation, 0, sizeof (PROCESS_INFORMATION));
|
||||
|
@ -547,46 +534,50 @@ mypopen (char *cmd, char *mode)
|
|||
lpCommandLine = cmd;
|
||||
if (NtHasRedirection(cmd) || isInternalCmd(cmd)) {
|
||||
lpApplicationName = getenv("COMSPEC");
|
||||
lpCmd2 = malloc(strlen(lpApplicationName) + 1 + strlen(cmd) + sizeof (" /c "));
|
||||
if (lpCmd2 == NULL)
|
||||
rb_fatal("Mypopen: malloc failed");
|
||||
lpCmd2 = xmalloc(strlen(lpApplicationName) + 1 + strlen(cmd) + sizeof (" /c "));
|
||||
sprintf(lpCmd2, "%s %s%s", lpApplicationName, " /c ", cmd);
|
||||
lpCommandLine = lpCmd2;
|
||||
}
|
||||
|
||||
fRet = CreateProcess(lpApplicationName, lpCommandLine, &sa, &sa,
|
||||
sa.bInheritHandle, dwCreationFlags, NULL, NULL, &aStartupInfo, &aProcessInformation);
|
||||
errno = GetLastError();
|
||||
|
||||
if (lpCmd2)
|
||||
free(lpCmd2);
|
||||
|
||||
CloseHandle(aProcessInformation.hThread);
|
||||
|
||||
if (!fRet) {
|
||||
CloseHandle(hInFile);
|
||||
CloseHandle(hOutFile);
|
||||
rb_fatal("cannot fork for \"%s\" (%s)", cmd, strerror(errno));
|
||||
CloseHandle(aProcessInformation.hProcess);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
CloseHandle(aProcessInformation.hThread);
|
||||
|
||||
if (reading) {
|
||||
fd = _open_osfhandle((long)hInFile, (_O_RDONLY | pipemode));
|
||||
CloseHandle(hOutFile);
|
||||
}
|
||||
else {
|
||||
fd = _open_osfhandle((long)hOutFile, (_O_WRONLY | pipemode));
|
||||
fd = _open_osfhandle((long)hOutFile, (_O_WRONLY | pipemode));
|
||||
CloseHandle(hInFile);
|
||||
}
|
||||
|
||||
if (fd == -1)
|
||||
rb_fatal("cannot open pipe \"%s\" (%s)", cmd, strerror(errno));
|
||||
if (fd == -1) {
|
||||
CloseHandle(reading ? hInFile : hOutFile);
|
||||
CloseHandle(aProcessInformation.hProcess);
|
||||
rb_sys_fail("mypopen: _open_osfhandle");
|
||||
}
|
||||
|
||||
|
||||
if ((fp = (FILE *) fdopen(fd, mode)) == NULL)
|
||||
return NULL;
|
||||
|
||||
if (lpCmd2)
|
||||
free(lpCmd2);
|
||||
if ((fp = (FILE *) fdopen(fd, mode)) == NULL) {
|
||||
_close(fd);
|
||||
CloseHandle(aProcessInformation.hProcess);
|
||||
rb_sys_fail("mypopen: fdopen");
|
||||
}
|
||||
|
||||
MyPopenRecord[slot].inuse = TRUE;
|
||||
MyPopenRecord[slot].pipe = fp;
|
||||
MyPopenRecord[slot].oshandle = (reading ? hInFile : hOutFile);
|
||||
MyPopenRecord[slot].pid = (int)aProcessInformation.hProcess;
|
||||
return fp;
|
||||
}
|
||||
|
@ -638,14 +629,13 @@ mypclose(FILE *fp)
|
|||
}
|
||||
}
|
||||
}
|
||||
CloseHandle((HANDLE)MyPopenRecord[i].pid);
|
||||
#endif
|
||||
|
||||
|
||||
//
|
||||
// close the pipe
|
||||
//
|
||||
// Closehandle() is done by fclose().
|
||||
//CloseHandle(MyPopenRecord[i].oshandle);
|
||||
|
||||
fflush(fp);
|
||||
fclose(fp);
|
||||
|
||||
|
|
Loading…
Reference in a new issue