WojciechMula / pyahocorasick

Python module (C extension and plain python) implementing Aho-Corasick algorithm
BSD 3-Clause "New" or "Revised" License
948 stars 125 forks source link

GCC warnings with latest 1.1.5 #72

Closed pombredanne closed 6 years ago

pombredanne commented 6 years ago

A build gives this:

creating build/temp.linux-x86_64-3.6
gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -DAHOCORASICK_UNICODE= -I/home/pombreda/.pyenv/versions/3.6.1/include/python3.6m -c pyahocorasick.c -o build/temp.linux-x86_64-3.6/pyahocorasick.o
In file included from pyahocorasick.c:22:0:
utils.c: In function ‘pymod_get_string’:
utils.c:49:19: warning: pointer targets in assignment differ in signedness [-Wpointer-sign]
             *word = PyUnicode_AS_UNICODE(obj);
                   ^
utils.c:44:8: warning: unused variable ‘bytes’ [-Wunused-variable]
  char* bytes;
        ^
utils.c:43:10: warning: unused variable ‘i’ [-Wunused-variable]
  ssize_t i;
          ^
In file included from pyahocorasick.c:23:0:
trienode.c: In function ‘trienode_get_next’:
trienode.c:37:14: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (i=0; i < node->n; i++)
              ^
In file included from pyahocorasick.c:24:0:
trie.c: In function ‘trie_add_word’:
trie.c:30:14: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (i=0; i < wordlen; i++) {
              ^
trie.c: In function ‘trie_traverse_aux’:
trie.c:128:14: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (i=0; i < node->n; i++) {
              ^
In file included from pyahocorasick.c:26:0:
Automaton.c: In function ‘automaton_add_word’:
Automaton.c:250:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
      if (integer == -1 and PyErr_Occurred())
                  ^
Automaton.c: In function ‘clear_aux’:
Automaton.c:337:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (i=0; i < node->n; i++) {
               ^
Automaton.c: In function ‘automaton_make_automaton’:
Automaton.c:547:14: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (i=0; i < automaton->root->n; i++) {
              ^
Automaton.c:573:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (i=0; i < node->n; i++) {
               ^
Automaton.c: In function ‘get_stats_aux’:
Automaton.c:961:14: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (i=0; i < node->n; i++)
              ^
Automaton.c: In function ‘dump_aux’:
Automaton.c:1047:14: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (i=0; i < node->n; i++) {
              ^
In file included from Automaton.c:1133:0,
                 from pyahocorasick.c:26:
Automaton_pickle.c: In function ‘pickle_dump_save’:
Automaton_pickle.c:155:14: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (i=0; i < node->n; i++) {
              ^
Automaton_pickle.c: In function ‘automaton_unpickle’:
Automaton_pickle.c:364:14: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (i=1; i < id; i++) {
              ^
Automaton_pickle.c:397:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (i=1; i < id; i++) {
               ^
In file included from pyahocorasick.c:27:0:
AutomatonItemsIter.c: In function ‘automaton_items_iter_next’:
AutomatonItemsIter.c:207:6: warning: pointer targets in passing argument 1 of ‘PyUnicode_FromUnicode’ differ in signedness [-Wpointer-sign]
      return PyUnicode_FromUnicode(iter->buffer + 1, item->depth);
      ^
In file included from /home/pombreda/.pyenv/versions/3.6.1/include/python3.6m/Python.h:77:0,
                 from common.h:14,
                 from pyahocorasick.c:13:
/home/pombreda/.pyenv/versions/3.6.1/include/python3.6m/unicodeobject.h:688:23: note: expected ‘const Py_UNICODE *’ but argument is of type ‘uint32_t *’
 PyAPI_FUNC(PyObject*) PyUnicode_FromUnicode(
                       ^
In file included from pyahocorasick.c:22:0:
pyahocorasick.c: At top level:
utils.c:111:1: warning: ‘pymod_get_string_from_tuple’ defined but not used [-Wunused-function]
 pymod_get_string_from_tuple(PyObject* tuple, int index, TRIE_LETTER_TYPE** word, ssize_t* wordlen) {
 ^
utils.c:169:1: warning: ‘pymod_get_sequence_from_tuple’ defined but not used [-Wunused-function]
 pymod_get_sequence_from_tuple(PyObject* tuple, int index, TRIE_LETTER_TYPE** word, ssize_t* wordlen) {
 ^
creating build/lib.linux-x86_64-3.6

This likely innocuous though

WojciechMula commented 6 years ago

It would be worth to eliminate as many warning as possible.

WojciechMula commented 6 years ago

@pombredanne BTW, which version of GCC do you have? My GCC 7.2 doesn't complain about signed/unsigned comparisons.

WojciechMula commented 6 years ago

@pombredanne Sorry, there was no question :) I see GCC is called with different flags on my system (Debian).

WojciechMula commented 6 years ago

I believe most annoying warning were eliminated. We may close this issue with the next release.

pombredanne commented 6 years ago
$ gcc --version
gcc (Ubuntu 4.8.4-2ubuntu1~14.04.3) 4.8.4
Copyright (C) 2013 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

that's the default on Ubuntu 14.04 LTS... I like to avoid being on the leading edge ;)

pombredanne commented 6 years ago

@WojciechMula Thanks++ With the latest master 3d46569825ba69572b0a499a20c9b62c631dd9cc I only get this now:

gcc -pthread -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -I/home/pombreda/.pyenv/versions/2.7.13/include/python2.7 -c pyahocorasick.c -o build/temp.linux-x86_64-2.7/pyahocorasick.o
In file included from pyahocorasick.c:22:0:
utils.c: In function ‘__read_sequence__from_tuple’:
utils.c:135:4: warning: format ‘%zd’ expects argument of type ‘signed size_t’, but argument 5 has type ‘int’ [-Wformat=]
    PyErr_Format(PyExc_ValueError, "item #%zd: value %zd outside range [%zd..%zd]", i, value, 0, 65535);
    ^
utils.c:135:4: warning: format ‘%zd’ expects argument of type ‘signed size_t’, but argument 6 has type ‘int’ [-Wformat=]
creating build/lib.linux-x86_64-2.7
pombredanne commented 6 years ago

this is with a python setup.py build

WojciechMula commented 6 years ago

I believe all warnings have gone. :)