From: Markus Elfring <Markus.Elfring@web.de>
To: Coccinelle <cocci@systeme.lip6.fr>
Subject: [Cocci] Checking uniqueness for source code positions during SmPL data processing
Date: Mon, 22 Apr 2019 09:49:51 +0200 [thread overview]
Message-ID: <b3a94631-55c3-2162-ff7d-ff3482f66641@web.de> (raw)
[-- Attachment #1: Type: text/plain, Size: 2126 bytes --]
Hello,
I reported that I am trying a specific source code analysis out again.
Information can be imported also into database tables for such a purpose.
I observed a primary key constraint violation for my data processing attempt.
Useful background information can be found for a topic like
“Checking the handling of unique keys/indexes”.
https://groups.google.com/d/msg/sqlalchemy/klmUwiirIQw/LDeeRTcshQ4J
A corresponding aspect can trigger an usual development challenge.
The transaction fails if questionable data were detected. It seems to be hard
to find the single inappropriate data set out by SQL programming interfaces.
Thus I developed the attached script variant for the semantic patch language.
Another test result points interesting details out, doesn't it?
elfring@Sonne:~/Projekte/Linux/next-patched> time spatch ~/Projekte/Coccinelle/janitor/list_duplicate_statement_pairs_from_if_branches5.cocci drivers/media/dvb-frontends/stv0297.c
…
A duplicate key was passed.
function: stv0297_readreg
file: drivers/media/dvb-frontends/stv0297.c
line: 87
column: 4
Traceback (most recent call last):
File "<string>", line 4, in <module>
File "<string>", line 26, in store_statements
RuntimeError
exn while in timeout_function
Error in Python script, line 34, file …
real 0m0,606s
user 0m0,541s
sys 0m0,037s
By the way: I would like to point out once more that the code from
the SmPL rule “initialize” is 18 lines long and the definition for
the function “store_statements” starts at line 4 originally.
The implementation of the function “stv0297_readreg” contains two statements
which are repeated in three if branches for the desired exception handling.
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/media/dvb-frontends/stv0297.c?id=085b7755808aa11f78ab9377257e1dad2e6fa4bb#n66
Now I wonder about the shown software behaviour again when the corresponding
source code position should be unique based on the specified data fields.
How can affected software areas be improved further?
Regards,
Markus
[-- Attachment #2: list_duplicate_statement_pairs_from_if_branches5.cocci --]
[-- Type: text/plain, Size: 2191 bytes --]
@initialize:python@
@@
import sys
mapping = {}
def store_statements(fun, source, s1, s2):
"""Add data to an internal table."""
for place in source:
key = (fun, place.file, place.line, int(place.column) + 1)
if key in mapping:
sys.stderr.write("""A duplicate key was passed.
function: %s
file: %s
line: %s
column: %d
""" % key)
raise RuntimeError
else:
mapping[key] = (s1, s2)
@searching@
identifier work;
statement s1, s2;
position pos;
type T;
@@
T work(...)
{
... when any
if (...)
{
... when any
s1@pos
s2
}
... when any
}
@script:python collection@
fun << searching.work;
s1 << searching.s1;
s2 << searching.s2;
place << searching.pos;
@@
store_statements(fun, place, s1, s2)
@finalize:python@
@@
entries = len(mapping)
if entries > 0:
from collections import Counter
counts = Counter()
for k, v in mapping.items():
counts[(v[0], v[1], k[0], k[1])] += 1
delimiter = "|"
duplicates = {}
for k, v in counts.items():
if v > 1:
duplicates[k] = v
if len(duplicates.keys()) > 0:
sys.stdout.write(delimiter.join(["statement1",
"statement2",
'"function name"',
'"source file"',
"incidence"]))
sys.stdout.write("\r\n")
for k, v in duplicates.items():
sys.stdout.write(delimiter.join([k[0], k[1], k[2], k[3], str(v)]))
sys.stdout.write("\r\n")
else:
sys.stderr.write("Duplicate statements were not determined from "
+ str(entries) + " records.\n")
sys.stderr.write(delimiter.join(["statement1",
"statement2",
'"function name"',
'"source file"',
"line"]))
sys.stderr.write("\r\n")
for k, v in counts.items():
sys.stdout.write(delimiter.join([v[0], v[1], k[1], k[0], k[2]]))
sys.stderr.write("\r\n")
else:
sys.stderr.write("No result for this analysis!\n")
[-- Attachment #3: Type: text/plain, Size: 136 bytes --]
_______________________________________________
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci
next reply other threads:[~2019-04-22 7:50 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-04-22 7:49 Markus Elfring [this message]
2019-04-22 7:55 ` [Cocci] Checking uniqueness for source code positions during SmPL data processing Julia Lawall
2019-04-22 8:55 ` Markus Elfring
2019-04-22 9:05 ` Julia Lawall
2019-04-22 9:26 ` Markus Elfring
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=b3a94631-55c3-2162-ff7d-ff3482f66641@web.de \
--to=markus.elfring@web.de \
--cc=cocci@systeme.lip6.fr \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).