[前][次][番号順一覧][スレッド一覧]

ruby-changes:55493

From: git <ko1@a...>
Date: Tue, 23 Apr 2019 16:39:49 +0900 (JST)
Subject: [ruby-changes:55493] git:4d8f35a521 (ruby_2_4): * 2019-04-23

git	2019-04-23 10:35:18 +0900 (Tue, 23 Apr 2019)

  New Revision: 4d8f35a521

  https://git.ruby-lang.org/ruby.git/commit/?id=4d8f35a521

  Log:
    * 2019-04-23

  Modified files:
    version.h
Index: KOSAKO/st.c
===================================================================
--- KOSAKO/st.c	(nonexistent)
+++ KOSAKO/st.c	(revision 4)
@@ -0,0 +1,435 @@ https://github.com/ruby/ruby/blob/trunk/KOSAKO/st.c#L1
+/* This is a general purpose hash table package written by Peter Moore @ UCB. */
+
+static	char	sccsid[] = "@(#) st.c 5.1 89/12/14 Crucible";
+
+#include "config.h"
+#include <stdio.h>
+#include "st.h"
+
+#define ST_DEFAULT_MAX_DENSITY 5
+#define ST_DEFAULT_INIT_TABLE_SIZE 11
+
+    /*
+     * DEFAULT_MAX_DENSITY is the default for the largest we allow the
+     * average number of items per bin before increasing the number of
+     * bins
+     *
+     * DEFAULT_INIT_TABLE_SIZE is the default for the number of bins
+     * allocated initially
+     *
+     */
+static int numcmp();
+static int numhash();
+static struct st_hash_type type_numhash = {
+    numcmp,
+    numhash,
+};
+
+extern int strcmp();
+static int strhash();
+static struct st_hash_type type_strhash = {
+    strcmp,
+    strhash,
+};
+
+void *xmalloc();
+void *xcalloc();
+void *xrealloc();
+static void rehash();
+
+#define max(a,b) ((a) > (b) ? (a) : (b))
+#define nil(type) ((type*)0)
+#define alloc(type) (type*)xmalloc((unsigned)sizeof(type))
+#define Calloc(n,s) (char*)xcalloc((n),(s))
+
+#define EQUAL(table, x, y) ((*table->type->compare)(x, y) == 0)
+
+#define do_hash(key, table) (*(table)->type->hash)((key), (table)->num_bins)
+
+st_table*
+st_init_table_with_size(type, size)
+    struct st_hash_type *type;
+    int size;
+{
+    st_table *tbl;
+
+    if (size == 0) size = ST_DEFAULT_INIT_TABLE_SIZE;
+    else size /= ST_DEFAULT_MAX_DENSITY*0.87;
+
+    if (size < ST_DEFAULT_INIT_TABLE_SIZE)
+	size = ST_DEFAULT_INIT_TABLE_SIZE;
+
+    tbl = alloc(st_table);
+    tbl->type = type;
+    tbl->num_entries = 0;
+    tbl->num_bins = size;
+    tbl->bins = (st_table_entry **)Calloc(size, sizeof(st_table_entry*));
+    return tbl;
+}
+
+st_table*
+st_init_table(type)
+    struct st_hash_type *type;
+{
+    return st_init_table_with_size(type, 0);
+}
+
+st_table*
+st_init_numtable()
+{
+    return st_init_table(&type_numhash);
+}
+
+st_table*
+st_init_strtable()
+{
+    return st_init_table(&type_strhash);
+}
+
+void
+st_free_table(table)
+    st_table *table;
+{
+    register st_table_entry *ptr, *next;
+    int i;
+
+    for(i = 0; i < table->num_bins ; i++) {
+	ptr = table->bins[i];
+	while (ptr != nil(st_table_entry)) {
+	    next = ptr->next;
+	    free((char*)ptr);
+	    ptr = next;
+	}
+    }
+    free((char*)table->bins);
+    free((char*)table);
+}
+
+#define PTR_NOT_EQUAL(table, ptr, key) \
+(ptr != nil(st_table_entry) && !EQUAL(table, key, (ptr)->key))
+
+#define FIND_ENTRY(table, ptr, hash_val) \
+ptr = (table)->bins[hash_val];\
+if (PTR_NOT_EQUAL(table, ptr, key)) {\
+    while (PTR_NOT_EQUAL(table, ptr->next, key)) {\
+	ptr = ptr->next;\
+    }\
+    ptr = ptr->next;\
+}
+
+int
+st_lookup(table, key, value)
+    st_table *table;
+    register char *key;
+    char **value;
+{
+    int hash_val;
+    register st_table_entry *ptr;
+
+    hash_val = do_hash(key, table);
+
+    FIND_ENTRY(table, ptr, hash_val);
+
+    if (ptr == nil(st_table_entry)) {
+	return 0;
+    } else {
+	if (value != nil(char*))  *value = ptr->record;
+	return 1;
+    }
+}
+
+#define ADD_DIRECT(table, key, value, hash_val, tbl)\
+{\
+    if (table->num_entries/table->num_bins > ST_DEFAULT_MAX_DENSITY) {\
+	rehash(table);\
+	hash_val = do_hash(key, table);\
+    }\
+    \
+    tbl = alloc(st_table_entry);\
+    \
+    tbl->key = key;\
+    tbl->record = value;\
+    tbl->next = table->bins[hash_val];\
+    table->bins[hash_val] = tbl;\
+    table->num_entries++;\
+}
+
+int
+st_insert(table, key, value)
+    register st_table *table;
+    register char *key;
+    char *value;
+{
+    int hash_val;
+    st_table_entry *tbl;
+    register st_table_entry *ptr;
+
+    hash_val = do_hash(key, table);
+
+    FIND_ENTRY(table, ptr, hash_val);
+
+    if (ptr == nil(st_table_entry)) {
+	ADD_DIRECT(table,key,value,hash_val,tbl);
+	return 0;
+    } else {
+	ptr->record = value;
+	return 1;
+    }
+}
+
+void
+st_add_direct(table, key, value)
+    st_table *table;
+    char *key;
+    char *value;
+{
+    int hash_val;
+    st_table_entry *tbl;
+
+    hash_val = do_hash(key, table);
+    ADD_DIRECT(table, key, value, hash_val, tbl);
+}
+
+int
+st_find_or_add(table, key, slot)
+    st_table *table;
+    char *key;
+    char ***slot;
+{
+    int hash_val;
+    st_table_entry *tbl, *ptr;
+
+    hash_val = do_hash(key, table);
+
+    FIND_ENTRY(table, ptr, hash_val);
+
+    if (ptr == nil(st_table_entry)) {
+	ADD_DIRECT(table, key, (char*)0, hash_val, tbl)
+	if (slot != nil(char**)) *slot = &tbl->record;
+	return 0;
+    } else {
+	if (slot != nil(char**)) *slot = &ptr->record;
+	return 1;
+    }
+}
+
+static void
+rehash(table)
+    register st_table *table;
+{
+    register st_table_entry *ptr, *next, **old_bins = table->bins;
+    int i, old_num_bins = table->num_bins, hash_val;
+
+    table->num_bins = 1.79*old_num_bins;
+
+    if (table->num_bins%2 == 0) {
+	table->num_bins += 1;
+    }
+
+    table->num_entries = 0;
+    table->bins = (st_table_entry **)
+	Calloc((unsigned)table->num_bins, sizeof(st_table_entry*));
+
+    for(i = 0; i < old_num_bins ; i++) {
+	ptr = old_bins[i];
+	while (ptr != nil(st_table_entry)) {
+	    next = ptr->next;
+	    hash_val = do_hash(ptr->key, table);
+	    ptr->next = table->bins[hash_val];
+	    table->bins[hash_val] = ptr;
+	    table->num_entries++;
+	    ptr = next;
+	}
+    }
+    free((char*)old_bins);
+}
+
+st_table*
+st_copy(old_table)
+    st_table *old_table;
+{
+    st_table *new_table;
+    st_table_entry *ptr, *tbl;
+    int i, num_bins = old_table->num_bins;
+
+    new_table = alloc(st_table);
+    if (new_table == nil(st_table)) {
+	return nil(st_table);
+    }
+
+    *new_table = *old_table;
+    new_table->bins = (st_table_entry**)
+	Calloc((unsigned)num_bins, sizeof(st_table_entry*));
+
+    if (new_table->bins == nil(st_table_entry*)) {
+	free((char*)new_table);
+	return nil(st_table);
+    }
+
+    for(i = 0; i < num_bins ; i++) {
+	new_table->bins[i] = nil(st_table_entry);
+	ptr = old_table->bins[i];
+	while (ptr != nil(st_table_entry)) {
+	    tbl = alloc(st_table_entry);
+	    if (tbl == nil(st_table_entry)) {
+		free((char*)new_table->bins);
+		free((char*)new_table);
+		return nil(st_table);
+	    }
+	    *tbl = *ptr;
+	    tbl->next = new_table->bins[i];
+	    new_table->bins[i] = tbl;
+	    ptr = ptr->next;
+	}
+    }
+    return new_table;
+}
+
+int
+st_delete(table, key, value)
+    register st_table *table;
+    register char **key;
+    char **value;
+{
+    int hash_val;
+    st_table_entry *tmp;
+    register st_table_entry *ptr;
+
+    hash_val = do_hash(*key, table);
+
+    ptr = table->bins[hash_val];
+
+    if (ptr == nil(st_table_entry)) {
+	if (value != nil(char*)) *value = nil(char);
+	return 0;
+    }
+
+    if (EQUAL(table, *key, ptr->key)) {
+	table->bins[hash_val] = ptr->next;
+	table->num_entries--;
+	if (value != nil(char*)) *value = ptr->record;
+	*key = ptr->key;
+	free((char*)ptr);
+	return 1;
+    }
+
+    for(; ptr->next != nil(st_table_entry); ptr = ptr->next) {
+	if (EQUAL(table, ptr->next->key, *key)) {
+	    tmp = ptr->next;
+	    ptr->next = ptr->next->next;
+	    table->num_entries--;
+	    if (value != nil(char*)) *value = tmp->record;
+	    *key = tmp->key;
+	    free((char*)tmp);
+	    return 1;
+	}
+    }
+
+    return 0;
+}
+
+int
+st_delete_safe(table, key, value, never)
+    register st_table *table;
+    register char **key;
+    char **value;
+    char *never;
+{
+    int hash_val;
+    register st_table_entry *ptr;
+
+    hash_val = do_hash(*key, table);
+
+    ptr = table->bins[hash_val];
+
+    if (ptr == nil(st_table_entry)) {
+	if (value != nil(char*)) *value = nil(char);
+	return 0;
+    }
+
+    if (EQUAL(table, *key, ptr->key)) {
+	table->num_entries--;
+	*key = ptr->key;
+	if (value != nil(char*)) *value = ptr->record;
+	ptr->key = ptr->record = never;
+	return 1;
+    }
+
+    for(; ptr->next != nil(st_table_entry); ptr = ptr->next) {
+	if (EQUAL(table, ptr->next->key, *key)) {
+	    table->num_entries--;
+	    *key = ptr->key;
+	    if (value != nil(char*)) *value = ptr->record;
+	    ptr->key = ptr->record = never;
+	    return 1;
+	}
+    }
+
+    return 0;
+}
+
+void
+st_foreach(table, func, arg)
+    st_table *table;
+    enum st_retval (*func)();
+    char *arg;
+{
+    st_table_entry *ptr, *last, *tmp;
+    enum st_retval retval;
+    int i;
+
+    for(i = 0; i < table->num_bins; i++) {
+	last = nil(st_table_entry);
+	for(ptr = table->bins[i]; ptr != nil(st_table_entry);) {
+	    retval = (*func)(ptr->key, ptr->record, arg);
+	    switch (retval) {
+	    case ST_CONTINUE:
+		last = ptr;
+		ptr = ptr->next;
+		break;
+	    case ST_STOP:
+		return;
+	    case ST_DELETE:
+		tmp = ptr;
+		if (last == nil(st_table_entry)) {
+		    table->bins[i] = ptr->next;
+		} else {
+		    last->next = ptr->next;
+		}
+		ptr = ptr->next;
+		free((char*)tmp);
+		table->num_entries--;
+	    }
+	}
+    }
+}
+
+static int
+strhash(string, modulus)
+    register char *string;
+    int modulus;
+{
+    register int val = 0;
+    register int c;
+
+    while ((c = *string++) != '\0') {
+	val = val*997 + c;
+    }
+
+    return ((val < 0) ? -val : val)%modulus;
+}
+
+static int
+numcmp(x, y)
+    int x, y;
+{
+    return x != y;
+}
+
+static int
+numhash(n, modulus)
+    int n;
+    int modulus;
+{
+    return n % modulus;
+}

Property changes on: KOSAKO/st.c
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Author Date Id Revision
\ No newline at end of property
Index: KOSAKO/regex.c
===================================================================
--- KOSAKO/regex.c	(nonexistent)
+++ KOSAKO/regex.c	(revision 4)
@@ -0,0 +1,2807 @@ https://github.com/ruby/ruby/blob/trunk/KOSAKO/regex.c#L1
+/* Extended regular expression matching and search library.
+   Copyright (C) 1985, 1989-90 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 1, or (at your option)
+   any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
+/* Multi-byte extension added May, 1993 by t^2 (Takahiro Tanimoto)
+   Last change: May 21, 1993 by t^2  */
+
+
+/* To test, compile with -Dtest.  This Dtestable feature turns this into
+   a self-contained program which reads a pattern, describes how it
+   compiles, then reads a string and searches for it.
+
+   On the other hand, if you compile with both -Dtest and -Dcanned you
+   can run some tests we've already thought of.  */
+
+/* We write fatal error messages on standard error.  */
+#include <stdio.h>
+
+/* isalpha(3) etc. are used for the character classes.  */
+#include <ctype.h>
+#include <sys/types.h>
+
+#include "config.h"
+#include "defines.h"
+
+#ifdef __STDC__
+#define P(s)    s
+#define MALLOC_ARG_T size_t
+#else
+#define P(s)    ()
+#define MALLOC_ARG_T unsigned
+#define volatile
+#define const
+#endif
+
+/* #define	NO_ALLOCA	/* try it out for now */
+#ifndef NO_ALLOCA
+/* Make alloca work the best possible way.  */
+#ifdef __GNUC__
+#ifndef atarist
+#ifndef alloca
+#define alloca __builtin_alloca
+#endif
+#endif /* atarist */
+#else
+#if defined(HAVE_ALLOCA_H) && !defined(__GNUC__)
+#include <alloca.h>
+#else
+char *alloca();
+#endif
+#endif /* __GNUC__ */
+
+#ifdef _AIX
+#pragma alloca
+#endif
+
+#define RE_ALLOCATE alloca
+#define FREE_VARIABLES() alloca(0)
+
+#define FREE_AND_RETURN_VOID(stackb)	return
+#define FREE_AND_RETURN(stackb,val)	return(val)
+#define DOUBLE_STACK(stackx,stackb,len) \
+        (stackx = (unsigned char **) alloca(2 * len			\
+                                            * sizeof(unsigned char *)),\
+	/* Only copy what is in use.  */				\
+        (unsigned char **) memcpy(stackx, stackb, len * sizeof (char *)))
+#else  /* NO_ALLOCA defined */
+
+#define RE_ALLOCATE malloc
+
+#define FREE_VAR(var) if (var) free(var); var = NULL
+#define FREE_VARIABLES()						\
+  do {									\
+    FREE_VAR(regstart);							\
+    FREE_VAR(regend);							\
+    FREE_VAR(best_regstart);						\
+    FREE_VAR(best_regend);						\
+    FREE_VAR(reg_info);							\
+  } while (0)
+
+#define FREE_AND_RETURN_VOID(stackb)   free(stackb);return
+#define FREE_AND_RETURN(stackb,val)    free(stackb);return(val)
+#define DOUBLE_STACK(stackx,stackb,len) \
+        (unsigned char **)xrealloc(stackb, 2 * len * sizeof(unsigned char *))
+#endif /* NO_ALLOCA */
+
+#define RE_TALLOC(n,t)  ((t*)RE_ALLOCATE((n)*sizeof(t)))
+#define TMALLOC(n,t)    ((t*)xmalloc((n)*sizeof(t)))
+#define TREALLOC(s,n,t) (s=((t*)xrealloc(s,(n)*sizeof(t))))
+
+/* Get the interface, including the syntax bits.  */
+#include "regex.h"
+
+static void store_jump P((char *, int, char *));
+static void insert_jump P((int, char *, char *, char *));
+static void store_jump_n P((char *, int, char *, unsigned));
+static void insert_jump_n P((int, char *, char *, char *, unsigned));
+static void insert_op_2 P((int, char *, char *, int, int ));
+static int memcmp_translate P((unsigned char *, unsigned char *,
+			       int, unsigned char *));
+
+/* Define the syntax stuff, so we can do the \<, \>, etc.  */
+
+/* This must be nonzero for the wordchar and notwordchar pattern
+   commands in re_match_2.  */
+#ifndef Sword 
+#define Sword 1
+#endif
+
+#define SYNTAX(c) re_syntax_table[c]
+
+static char re_syntax_table[256];
+static void init_syntax_once P((void));
+
+#undef P
+
+#include "util.h"
+
+static void
+init_syntax_once()
+{
+   register int c;
+   static int done = 0;
+
+   if (done)
+     return;
+
+   memset(re_syntax_table, 0, sizeof re_syntax_table);
+
+   for (c = 'a'; c <= 'z'; c++)
+     re_syntax_table[c] = Sword;
+
+   for (c = 'A'; c <= 'Z'; c++)
+     re_syntax_table[c] = Sword;
+
+   for (c = '0'; c <= '9'; c++)
+     re_syntax_table[c] = Sword;
+
+   re_syntax_table['_'] = Sword;
+
+   /* Add specific syntax for ISO Latin-1.  */
+   for (c = 0300; c <= 0377; c++)
+     re_syntax_table[c] = Sword;
+   re_syntax_table[0327] = 0;
+   re_syntax_table[0367] = 0;
+
+   done = 1;
+}
+
+/* Sequents are missing isgraph.  */
+#ifndef isgraph
+#define isgraph(c) (isprint((c)) && !isspace((c)))
+#endif
+
+/* These are the command codes that appear in compiled regular
+   expressions, one per byte.  Some command codes are followed by
+   argument bytes.  A command code can specify any interpretation
+   whatsoever for its arguments.  Zero-bytes may appear in the compiled
+   regular expression.
+
+   The value of `exactn' is needed in search.c (search_buffer) in emacs.
+   So regex.h defines a symbol `RE_EXACTN_VALUE' to be 1; the value of
+   `exactn' we use here must also be 1.  */
+
+enum regexpcode
+  {
+    unused=0,
+    exactn=1, /* Followed by one byte giving n, then by n literal bytes.  */
+    begline,  /* Fail unless at beginning of line.  */
+    endline,  /* Fail unless at end of line.  */
+    jump,     /* Followed by two bytes giving relative address to jump to.  */
+    on_failure_jump,	 /* Followed by two bytes giving relative address of 
+			    place to resume at in case of failure.  */
+    finalize_jump,	 /* Throw away latest failure point and then jump to 
+			    address.  */
+    maybe_finalize_jump, /* Like jump but finalize if safe to do so.
+			    This is used to jump back to the beginning
+			    of a repeat.  If the command that follows
+			    this jump is clearly incompatible with the
+			    one at the beginning of the repeat, such that
+			    we can be sure that there is no use backtracking
+			    out of repetitions already completed,
+			    then we finalize.  */
+    dummy_failure_jump,  /* Jump, and push a dummy failure point. This 
+			    failure point will be thrown away if an attempt 
+                            is made to use it for a failure. A + construct 
+                            makes this before the first repeat.  Also
+                            use it as an intermediary kind of jump when
+                            compiling an or construct.  */
+    succeed_n,	 /* Used like on_failure_jump except has to succeed n times;
+		    then gets turned into an on_failure_jump. The relative
+                    address following it is useless until then.  The
+                    address is followed by two bytes containing n.  */
+    jump_n,	 /* Similar to jump, but jump n times only; also the relative
+		    address following is in turn followed by yet two more bytes
+                    containing n.  */
+    set_number_at,	/* Set the following relative location to the
+			   subsequent number.  */
+    anychar,	 /* Matches any (more or less) one character.  */
+    charset,     /* Matches any one char belonging to specified set.
+		    First following byte is number of bitmap bytes.
+		    Then come bytes for a bitmap saying which chars are in.
+		    Bits in each byte are ordered low-bit-first.
+		    A character is in the set if its bit is 1.
+		    A character too large to have a bit in the map
+		    is automatically not in the set.  */
+    charset_not, /* Same parameters as charset, but match any character
+                    that is not one of those specified.  */
+    start_memory, /* Start remembering the text that is matched, for
+		    storing in a memory register.  Followed by one
+                    byte containing the register number.  Register numbers
+                    must be in the range 0 through RE_NREGS.  */
+    stop_memory, /* Stop remembering the text that is matched
+		    and store it in a memory register.  Followed by
+                    one byte containing the register number. Register
+                    numbers must be in the range 0 through RE_NREGS.  */
+    duplicate,   /* Match a duplicate of something remembered.
+		    Followed by one byte containing the index of the memory 
+                    register.  */
+    wordchar,    /* Matches any word-constituent character.  */
+    notwordchar, /* Matches any char that is not a word-constituent.  */
+    wordbound,   /* Succeeds if at a word boundary.  */
+    notwordbound,/* Succeeds if not at a word boundary.  */
+  };
+
+
+/* Number of failure points to allocate space for initially,
+   when matching.  If this number is exceeded, more space is allocated,
+   so it is not a hard limit.  */
+
+#ifndef NFAILURES
+#define NFAILURES 80
+#endif
+
+#if defined(CHAR_UNSIGNED) || defined(__CHAR_UNSIGNED__)
+#define SIGN_EXTEND_CHAR(c) ((c)>(char)127?(c)-256:(c)) /* for IBM RT */
+#endif
+#ifndef SIGN_EXTEND_CHAR
+#define SIGN_EXTEND_CHAR(x) (x)
+#endif
+
+
+/* Store NUMBER in two contiguous bytes starting at DESTINATION.  */
+#define STORE_NUMBER(destination, number)				\
+  { (destination)[0] = (number) & 0377;					\
+    (destination)[1] = (number) >> 8; }
+
+/* Same as STORE_NUMBER, except increment the destination pointer to
+   the byte after where the number is stored.  Watch out that values for
+   DESTINATION such as p + 1 won't work, whereas p will.  */
+#define STORE_NUMBER_AND_INCR(destination, number)			\
+  { STORE_NUMBER(destination, number);					\
+    (destination) += 2; }
+
+
+/* Put into DESTINATION a number stored in two contingous bytes starting
+   at SOURCE.  */
+#define EXTRACT_NUMBER(destination, source)				\
+  { (destinat (... truncated)

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]