Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

gnugol -a all fixed

It was possible for an old, obsolete engine to crash gnugol.
Null check added.

Also cleaned up whitespace issues
  • Loading branch information...
commit 3feeee7532c95b5051ef28d76652161668a2dfac 1 parent d878c71
@dtaht authored
View
2  README-FreeBSD.org
@@ -1,4 +1,4 @@
-* INSTALLATION ON FREEBSD
+gimake* INSTALLATION ON FREEBSD
** Required Packages
View
69 doc/CodingStyle.org
@@ -1,7 +1,68 @@
-* C conventions for Gnugol
-** Gnugol uses the C99 standard whenever possible
- It's been 12 years, time to adopt it!
+* Gnugol C conventions
+** Gnugol uses the C99 standard whenever logical
** In client applications especially, use assert.
+** Use a thread pooling model
+ The gnugol threadpool contains a small number of threads that
+ defaults to 2xnumber of cores Task routing is used to queue things
+ to the thread pool.
+
+ This model scales very well. It tends to keep the threads (and
+ cores) busy, without causing a lot of thread contention. It also
+ tends to force the program into a design model where threaded work
+ is broken up into easily-queued work items, rather than large,
+ monolithic entities that have to be made thread-safe.
+*** NOTE: open problem here is the latency of queries over the internet.
+ I loathe the one thread per open socket model of early
+ java. However, non-blocking I/O is not particularly easy to get
+ right on the first try, or the second. Or, third.
+ Elsewhere, the thread pool makes complete sense.
+
+** noun_verb functions and objects
+ The majority of libraries that gnugol interfaces with currently use noun_verb naming schemes for their functions. For consistency, if not clarity, it is best to use similar naming schemes
+
+
+ Ah well ... it's ... um ... based a lot of aesthetics and a preference for
+vertical alignment. Braces on their own line (it's a more vertical style as
+well---I absolutely loathe K&R style; always have), indents at two spaces,
+one variable per declaration (again, it's that vertical style) and formatted
+in a columnar style:
+
+ FILE *fpin;
+ FILE *fpout;
+ char buffer[BUFSIZ];
+ struct tm now;
+**
+char *a;
+int b;
+
* CodingStyle
+** Commit messages
+*** First line must be PG-13 and alphanumeric only
+ Sometimes only a good curse word adequately captures the essence
+ of a commit. For profanity to retain its magical power, however,
+ its uses must be reserved to those rare cases where it is truly
+ warranted. Do not use foul language as the first line. Try to
+ remember that commits are forever and public.
+*** 72 columns max with tab unless unavoidable
+*** Be polite
+ Feel free to call yourself an idiot, but nobody else.
+*** Blunt language is preferred
+ Use "Wrong" rather than "that turns out not to be the case". There is no reason to use businessspeak.
+*** Snark and humor is always appreciated
+ Feel free to use them in documentation, comments, etc. This project would not be as fun if it wasn't somewhat subversive in nature.
+*** TODO bug tracker
+ Some day I'd like to have a distributed bug tracker. Bugs everywhere?
+** Trailing whitespace
+ Try to omit trailing whitespace. Patch reviewers will appreciate you.
+** No tabs
+ Tabs are treated differently by different editors. Use spaces to indent code.
+** 80 column lines
+** Adhere to the existing coding style
+*** DO
+*** DON'T
+* UNRESOLVED
+** The glib library
++ Well debugged, widely used library (firefox, others) that brings
+- Bloated, complex and possibly hard to stay
+** glib-json vs jansson
-Pretty various. I'd like to enforce a coding style at some point.
View
26 src/common/engines.c
@@ -31,14 +31,14 @@ GnuGolEngine gnugol_engine_load(const char *name)
{
GnuGolEngine engine;
char libname[FILENAME_MAX];
-
+
assert(name != NULL);
-
+
engine = malloc(sizeof(struct ggengine));
if (engine == NULL)
return NULL;
-
- snprintf(libname,sizeof(libname),GNUGOL_SHAREDLIBDIR "/%s." SO_EXT,name);
+
+ snprintf(libname,sizeof(libname),GNUGOL_SHAREDLIBDIR "%s." SO_EXT,name);
engine->lib = dlopen(libname,RTLD_LAZY | RTLD_GLOBAL);
if (engine->lib == NULL)
@@ -46,21 +46,21 @@ GnuGolEngine gnugol_engine_load(const char *name)
free(engine);
return NULL;
}
-
+
engine->setup = dlsym(engine->lib,"setup");
if (engine->setup == NULL)
engine->setup = gnugol_default_setup;
-
+
engine->search = dlsym(engine->lib,"search");
if (engine->search == NULL)
engine->search = gnugol_default_search;
-
+
engine->description = (const char *)dlsym(engine->lib,"description");
if (engine->description == NULL)
engine->description = "There is no description";
-
+
engine->name = strdup(name);
-
+
return engine;
}
@@ -69,17 +69,17 @@ GnuGolEngine gnugol_engine_load(const char *name)
int gnugol_engine_query(GnuGolEngine engine,QueryOptions_t *query)
{
int rc;
-
+
assert(engine != NULL);
assert(query != NULL);
-
+
rc = (*engine->setup)(query);
if (rc < 0)
{
GNUGOL_OUTW(query,"%s: Went boom on setup\n",engine->name);
return rc;
}
-
+
return (*engine->search)(query);
}
@@ -88,7 +88,7 @@ int gnugol_engine_query(GnuGolEngine engine,QueryOptions_t *query)
void gnugol_engine_unload(GnuGolEngine engine)
{
assert(engine != NULL);
-
+
free((void *)engine->name);
dlclose(engine->lib);
free(engine);
View
19 src/engines/credits.c
@@ -89,16 +89,16 @@ static int search_engines(QueryOptions_t *q)
{
size_t extlen;
DIR *dir;
-
+
dir = opendir(GNUGOL_SHAREDLIBDIR);
if (dir == NULL)
{
/* error */
return 0;
}
-
+
extlen = strlen(SO_EXT);
-
+
while(1)
{
GnuGolEngine engine;
@@ -107,25 +107,28 @@ static int search_engines(QueryOptions_t *q)
size_t len;
char name[BUFSIZ];
int rc;
-
+
rc = readdir_r(dir,&entry,&pentry);
if (rc != 0)
{
/* error */
break;
}
-
+
if (pentry == NULL) break;
len = strlen(entry.d_name);
if (len <= extlen) continue;
if (strcmp(&entry.d_name[len-extlen],SO_EXT) != 0) continue;
memcpy(name,entry.d_name,(len - extlen) - 1);
name[(len - extlen) - 1] = '\0';
- engine = gnugol_engine_load(name);
+
+ if((engine = gnugol_engine_load(name)) != NULL)
+ {
gnugol_result_out(q,NULL,engine->name,engine->description);
gnugol_engine_unload(engine);
+ }
}
-
+
gnugol_result_out(
q,
"http://gnugol.taht.net/bugs.html",
@@ -170,7 +173,7 @@ int search(QueryOptions_t *q) {
}
}
gnugol_footer_out(q);
- }
+ }
else if (strcmp("engines",q->keywords) == 0)
{
gnugol_header_out(q);
View
6 src/include/gnugol_engines.h
@@ -8,12 +8,12 @@
#endif
#if DEBUG_SHAREDLIBS
-# define GNUGOL_SHAREDLIBDIR "../engines"
+# define GNUGOL_SHAREDLIBDIR "../engines/"
#else
# ifdef __FreeBSD__
-# define GNUGOL_SHAREDLIBDIR "/usr/local/lib/gnugol"
+# define GNUGOL_SHAREDLIBDIR "/usr/local/lib/gnugol/"
# else
-# define GNUGOL_SHAREDLIBDIR "/var/lib/gnugol"
+# define GNUGOL_SHAREDLIBDIR "/var/lib/gnugol/"
# endif
#endif
Please sign in to comment.
Something went wrong with that request. Please try again.