mirror of
https://github.com/libevent/libevent.git
synced 2025-01-31 09:12:55 +08:00
Port event_rpcgen.py
and test/check-dumpevents.py
to Python 3.
These scripts remain compatible with Python 2.
This commit is contained in:
parent
62866f98a5
commit
8b0aa7b36a
@ -915,19 +915,18 @@ if (NOT EVENT__DISABLE_TESTS)
|
|||||||
# Generate Regress tests.
|
# Generate Regress tests.
|
||||||
#
|
#
|
||||||
if (NOT EVENT__DISABLE_REGRESS)
|
if (NOT EVENT__DISABLE_REGRESS)
|
||||||
# (We require python2 to generate the regress tests)
|
# (We require python to generate the regress tests)
|
||||||
foreach (PY python2.6 python2.7 python2)
|
find_package(PythonInterp 3)
|
||||||
unset(FIND_PYTHON2 CACHE)
|
|
||||||
find_program(FIND_PYTHON2 ${PY})
|
|
||||||
if (FIND_PYTHON2)
|
|
||||||
set(PYTHON_EXECUTABLE "${PY}")
|
|
||||||
break()
|
|
||||||
endif()
|
|
||||||
endforeach()
|
|
||||||
find_package(PythonInterp)
|
|
||||||
|
|
||||||
if (PYTHONINTERP_FOUND AND PYTHON_VERSION_STRING VERSION_LESS "3.0.0")
|
if (PYTHONINTERP_FOUND)
|
||||||
set(__FOUND_USABLE_PYTHON 1)
|
set(__FOUND_USABLE_PYTHON 1)
|
||||||
|
else()
|
||||||
|
find_package(PythonInterp 2)
|
||||||
|
if (PYTHONINTERP_FOUND)
|
||||||
|
set(__FOUND_USABLE_PYTHON 1)
|
||||||
|
else()
|
||||||
|
message(ERROR "No suitable Python version found, bailing...")
|
||||||
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if (__FOUND_USABLE_PYTHON)
|
if (__FOUND_USABLE_PYTHON)
|
||||||
|
167
event_rpcgen.py
167
event_rpcgen.py
@ -1,4 +1,4 @@
|
|||||||
#!/usr/bin/env python2
|
#!/usr/bin/env python
|
||||||
#
|
#
|
||||||
# Copyright (c) 2005-2007 Niels Provos <provos@citi.umich.edu>
|
# Copyright (c) 2005-2007 Niels Provos <provos@citi.umich.edu>
|
||||||
# Copyright (c) 2007-2012 Niels Provos and Nick Mathewson
|
# Copyright (c) 2007-2012 Niels Provos and Nick Mathewson
|
||||||
@ -36,10 +36,10 @@ QUIETLY = 0
|
|||||||
|
|
||||||
def declare(s):
|
def declare(s):
|
||||||
if not QUIETLY:
|
if not QUIETLY:
|
||||||
print s
|
print(s)
|
||||||
|
|
||||||
def TranslateList(mylist, mydict):
|
def TranslateList(mylist, mydict):
|
||||||
return map(lambda x: x % mydict, mylist)
|
return [x % mydict for x in mylist]
|
||||||
|
|
||||||
# Exception class for parse errors
|
# Exception class for parse errors
|
||||||
class RpcGenError(Exception):
|
class RpcGenError(Exception):
|
||||||
@ -57,7 +57,7 @@ class Struct:
|
|||||||
declare(' Created struct: %s' % name)
|
declare(' Created struct: %s' % name)
|
||||||
|
|
||||||
def AddEntry(self, entry):
|
def AddEntry(self, entry):
|
||||||
if self._tags.has_key(entry.Tag()):
|
if entry.Tag() in self._tags:
|
||||||
raise RpcGenError(
|
raise RpcGenError(
|
||||||
'Entry "%s" duplicates tag number %d from "%s" '
|
'Entry "%s" duplicates tag number %d from "%s" '
|
||||||
'around line %d' % (entry.Name(), entry.Tag(),
|
'around line %d' % (entry.Name(), entry.Tag(),
|
||||||
@ -78,7 +78,7 @@ class Struct:
|
|||||||
def PrintIndented(self, file, ident, code):
|
def PrintIndented(self, file, ident, code):
|
||||||
"""Takes an array, add indentation to each entry and prints it."""
|
"""Takes an array, add indentation to each entry and prints it."""
|
||||||
for entry in code:
|
for entry in code:
|
||||||
print >>file, '%s%s' % (ident, entry)
|
file.write('%s%s\n' % (ident, entry))
|
||||||
|
|
||||||
class StructCCode(Struct):
|
class StructCCode(Struct):
|
||||||
""" Knows how to generate C code for a struct """
|
""" Knows how to generate C code for a struct """
|
||||||
@ -88,20 +88,19 @@ class StructCCode(Struct):
|
|||||||
|
|
||||||
def PrintTags(self, file):
|
def PrintTags(self, file):
|
||||||
"""Prints the tag definitions for a structure."""
|
"""Prints the tag definitions for a structure."""
|
||||||
print >>file, '/* Tag definition for %s */' % self._name
|
file.write('/* Tag definition for %s */\n' % self._name)
|
||||||
print >>file, 'enum %s_ {' % self._name.lower()
|
file.write('enum %s_ {\n' % self._name.lower())
|
||||||
for entry in self._entries:
|
for entry in self._entries:
|
||||||
print >>file, ' %s=%d,' % (self.EntryTagName(entry),
|
file.write(' %s=%d,\n' % (self.EntryTagName(entry), entry.Tag()))
|
||||||
entry.Tag())
|
file.write(' %s_MAX_TAGS\n' % (self._name.upper()))
|
||||||
print >>file, ' %s_MAX_TAGS' % (self._name.upper())
|
file.write('};\n\n')
|
||||||
print >>file, '};\n'
|
|
||||||
|
|
||||||
def PrintForwardDeclaration(self, file):
|
def PrintForwardDeclaration(self, file):
|
||||||
print >>file, 'struct %s;' % self._name
|
file.write('struct %s;\n' % self._name)
|
||||||
|
|
||||||
def PrintDeclaration(self, file):
|
def PrintDeclaration(self, file):
|
||||||
print >>file, '/* Structure declaration for %s */' % self._name
|
file.write('/* Structure declaration for %s */\n' % self._name)
|
||||||
print >>file, 'struct %s_access_ {' % self._name
|
file.write('struct %s_access_ {\n' % self._name)
|
||||||
for entry in self._entries:
|
for entry in self._entries:
|
||||||
dcl = entry.AssignDeclaration('(*%s_assign)' % entry.Name())
|
dcl = entry.AssignDeclaration('(*%s_assign)' % entry.Name())
|
||||||
dcl.extend(
|
dcl.extend(
|
||||||
@ -110,20 +109,19 @@ class StructCCode(Struct):
|
|||||||
dcl.extend(
|
dcl.extend(
|
||||||
entry.AddDeclaration('(*%s_add)' % entry.Name()))
|
entry.AddDeclaration('(*%s_add)' % entry.Name()))
|
||||||
self.PrintIndented(file, ' ', dcl)
|
self.PrintIndented(file, ' ', dcl)
|
||||||
print >>file, '};\n'
|
file.write('};\n\n')
|
||||||
|
|
||||||
print >>file, 'struct %s {' % self._name
|
file.write('struct %s {\n' % self._name)
|
||||||
print >>file, ' struct %s_access_ *base;\n' % self._name
|
file.write(' struct %s_access_ *base;\n\n' % self._name)
|
||||||
for entry in self._entries:
|
for entry in self._entries:
|
||||||
dcl = entry.Declaration()
|
dcl = entry.Declaration()
|
||||||
self.PrintIndented(file, ' ', dcl)
|
self.PrintIndented(file, ' ', dcl)
|
||||||
print >>file, ''
|
file.write('\n')
|
||||||
for entry in self._entries:
|
for entry in self._entries:
|
||||||
print >>file, ' ev_uint8_t %s_set;' % entry.Name()
|
file.write(' ev_uint8_t %s_set;\n' % entry.Name())
|
||||||
print >>file, '};\n'
|
file.write('};\n\n')
|
||||||
|
|
||||||
print >>file, \
|
file.write("""struct %(name)s *%(name)s_new(void);
|
||||||
"""struct %(name)s *%(name)s_new(void);
|
|
||||||
struct %(name)s *%(name)s_new_with_arg(void *);
|
struct %(name)s *%(name)s_new_with_arg(void *);
|
||||||
void %(name)s_free(struct %(name)s *);
|
void %(name)s_free(struct %(name)s *);
|
||||||
void %(name)s_clear(struct %(name)s *);
|
void %(name)s_clear(struct %(name)s *);
|
||||||
@ -133,7 +131,7 @@ int %(name)s_complete(struct %(name)s *);
|
|||||||
void evtag_marshal_%(name)s(struct evbuffer *, ev_uint32_t,
|
void evtag_marshal_%(name)s(struct evbuffer *, ev_uint32_t,
|
||||||
const struct %(name)s *);
|
const struct %(name)s *);
|
||||||
int evtag_unmarshal_%(name)s(struct evbuffer *, ev_uint32_t,
|
int evtag_unmarshal_%(name)s(struct evbuffer *, ev_uint32_t,
|
||||||
struct %(name)s *);""" % { 'name' : self._name }
|
struct %(name)s *);\n""" % { 'name' : self._name })
|
||||||
|
|
||||||
|
|
||||||
# Write a setting function of every variable
|
# Write a setting function of every variable
|
||||||
@ -146,22 +144,21 @@ int evtag_unmarshal_%(name)s(struct evbuffer *, ev_uint32_t,
|
|||||||
self.PrintIndented(file, '', entry.AddDeclaration(
|
self.PrintIndented(file, '', entry.AddDeclaration(
|
||||||
entry.AddFuncName()))
|
entry.AddFuncName()))
|
||||||
|
|
||||||
print >>file, '/* --- %s done --- */\n' % self._name
|
file.write('/* --- %s done --- */\n\n' % self._name)
|
||||||
|
|
||||||
def PrintCode(self, file):
|
def PrintCode(self, file):
|
||||||
print >>file, ('/*\n'
|
file.write(('/*\n'
|
||||||
' * Implementation of %s\n'
|
' * Implementation of %s\n'
|
||||||
' */\n') % self._name
|
' */\n\n') % self._name)
|
||||||
|
|
||||||
print >>file, \
|
file.write('static struct %(name)s_access_ %(name)s_base__ = {\n' % \
|
||||||
'static struct %(name)s_access_ %(name)s_base__ = {' % \
|
{ 'name' : self._name })
|
||||||
{ 'name' : self._name }
|
|
||||||
for entry in self._entries:
|
for entry in self._entries:
|
||||||
self.PrintIndented(file, ' ', entry.CodeBase())
|
self.PrintIndented(file, ' ', entry.CodeBase())
|
||||||
print >>file, '};\n'
|
file.write('};\n\n')
|
||||||
|
|
||||||
# Creation
|
# Creation
|
||||||
print >>file, (
|
file.write((
|
||||||
'struct %(name)s *\n'
|
'struct %(name)s *\n'
|
||||||
'%(name)s_new(void)\n'
|
'%(name)s_new(void)\n'
|
||||||
'{\n'
|
'{\n'
|
||||||
@ -176,77 +173,77 @@ int evtag_unmarshal_%(name)s(struct evbuffer *, ev_uint32_t,
|
|||||||
' event_warn("%%s: malloc", __func__);\n'
|
' event_warn("%%s: malloc", __func__);\n'
|
||||||
' return (NULL);\n'
|
' return (NULL);\n'
|
||||||
' }\n'
|
' }\n'
|
||||||
' tmp->base = &%(name)s_base__;\n') % { 'name' : self._name }
|
' tmp->base = &%(name)s_base__;\n\n') % { 'name' : self._name })
|
||||||
|
|
||||||
for entry in self._entries:
|
for entry in self._entries:
|
||||||
self.PrintIndented(file, ' ', entry.CodeInitialize('tmp'))
|
self.PrintIndented(file, ' ', entry.CodeInitialize('tmp'))
|
||||||
print >>file, ' tmp->%s_set = 0;\n' % entry.Name()
|
file.write(' tmp->%s_set = 0;\n\n' % entry.Name())
|
||||||
|
|
||||||
print >>file, (
|
file.write((
|
||||||
' return (tmp);\n'
|
' return (tmp);\n'
|
||||||
'}\n')
|
'}\n\n'))
|
||||||
|
|
||||||
# Adding
|
# Adding
|
||||||
for entry in self._entries:
|
for entry in self._entries:
|
||||||
if entry.Array():
|
if entry.Array():
|
||||||
self.PrintIndented(file, '', entry.CodeAdd())
|
self.PrintIndented(file, '', entry.CodeAdd())
|
||||||
print >>file, ''
|
file.write('\n')
|
||||||
|
|
||||||
# Assigning
|
# Assigning
|
||||||
for entry in self._entries:
|
for entry in self._entries:
|
||||||
self.PrintIndented(file, '', entry.CodeAssign())
|
self.PrintIndented(file, '', entry.CodeAssign())
|
||||||
print >>file, ''
|
file.write('\n')
|
||||||
|
|
||||||
# Getting
|
# Getting
|
||||||
for entry in self._entries:
|
for entry in self._entries:
|
||||||
self.PrintIndented(file, '', entry.CodeGet())
|
self.PrintIndented(file, '', entry.CodeGet())
|
||||||
print >>file, ''
|
file.write('\n')
|
||||||
|
|
||||||
# Clearing
|
# Clearing
|
||||||
print >>file, ( 'void\n'
|
file.write(( 'void\n'
|
||||||
'%(name)s_clear(struct %(name)s *tmp)\n'
|
'%(name)s_clear(struct %(name)s *tmp)\n'
|
||||||
'{'
|
'{'
|
||||||
) % { 'name' : self._name }
|
'\n') % { 'name' : self._name })
|
||||||
for entry in self._entries:
|
for entry in self._entries:
|
||||||
self.PrintIndented(file, ' ', entry.CodeClear('tmp'))
|
self.PrintIndented(file, ' ', entry.CodeClear('tmp'))
|
||||||
|
|
||||||
print >>file, '}\n'
|
file.write('}\n\n')
|
||||||
|
|
||||||
# Freeing
|
# Freeing
|
||||||
print >>file, ( 'void\n'
|
file.write(( 'void\n'
|
||||||
'%(name)s_free(struct %(name)s *tmp)\n'
|
'%(name)s_free(struct %(name)s *tmp)\n'
|
||||||
'{'
|
'{'
|
||||||
) % { 'name' : self._name }
|
'\n') % { 'name' : self._name })
|
||||||
|
|
||||||
for entry in self._entries:
|
for entry in self._entries:
|
||||||
self.PrintIndented(file, ' ', entry.CodeFree('tmp'))
|
self.PrintIndented(file, ' ', entry.CodeFree('tmp'))
|
||||||
|
|
||||||
print >>file, (' free(tmp);\n'
|
file.write((' free(tmp);\n'
|
||||||
'}\n')
|
'}\n\n'))
|
||||||
|
|
||||||
# Marshaling
|
# Marshaling
|
||||||
print >>file, ('void\n'
|
file.write(('void\n'
|
||||||
'%(name)s_marshal(struct evbuffer *evbuf, '
|
'%(name)s_marshal(struct evbuffer *evbuf, '
|
||||||
'const struct %(name)s *tmp)'
|
'const struct %(name)s *tmp)'
|
||||||
'{') % { 'name' : self._name }
|
'{\n') % { 'name' : self._name })
|
||||||
for entry in self._entries:
|
for entry in self._entries:
|
||||||
indent = ' '
|
indent = ' '
|
||||||
# Optional entries do not have to be set
|
# Optional entries do not have to be set
|
||||||
if entry.Optional():
|
if entry.Optional():
|
||||||
indent += ' '
|
indent += ' '
|
||||||
print >>file, ' if (tmp->%s_set) {' % entry.Name()
|
file.write(' if (tmp->%s_set) {\n' % entry.Name())
|
||||||
self.PrintIndented(
|
self.PrintIndented(
|
||||||
file, indent,
|
file, indent,
|
||||||
entry.CodeMarshal('evbuf', self.EntryTagName(entry),
|
entry.CodeMarshal('evbuf', self.EntryTagName(entry),
|
||||||
entry.GetVarName('tmp'),
|
entry.GetVarName('tmp'),
|
||||||
entry.GetVarLen('tmp')))
|
entry.GetVarLen('tmp')))
|
||||||
if entry.Optional():
|
if entry.Optional():
|
||||||
print >>file, ' }'
|
file.write(' }\n')
|
||||||
|
|
||||||
print >>file, '}\n'
|
file.write('}\n\n')
|
||||||
|
|
||||||
# Unmarshaling
|
# Unmarshaling
|
||||||
print >>file, ('int\n'
|
file.write(('int\n'
|
||||||
'%(name)s_unmarshal(struct %(name)s *tmp, '
|
'%(name)s_unmarshal(struct %(name)s *tmp, '
|
||||||
' struct evbuffer *evbuf)\n'
|
' struct evbuffer *evbuf)\n'
|
||||||
'{\n'
|
'{\n'
|
||||||
@ -255,14 +252,14 @@ int evtag_unmarshal_%(name)s(struct evbuffer *, ev_uint32_t,
|
|||||||
' if (evtag_peek(evbuf, &tag) == -1)\n'
|
' if (evtag_peek(evbuf, &tag) == -1)\n'
|
||||||
' return (-1);\n'
|
' return (-1);\n'
|
||||||
' switch (tag) {\n'
|
' switch (tag) {\n'
|
||||||
) % { 'name' : self._name }
|
'\n') % { 'name' : self._name })
|
||||||
for entry in self._entries:
|
for entry in self._entries:
|
||||||
print >>file, ' case %s:\n' % self.EntryTagName(entry)
|
file.write(' case %s:\n' % self.EntryTagName(entry))
|
||||||
if not entry.Array():
|
if not entry.Array():
|
||||||
print >>file, (
|
file.write((
|
||||||
' if (tmp->%s_set)\n'
|
' if (tmp->%s_set)\n'
|
||||||
' return (-1);'
|
' return (-1);'
|
||||||
) % (entry.Name())
|
'\n') % (entry.Name()))
|
||||||
|
|
||||||
self.PrintIndented(
|
self.PrintIndented(
|
||||||
file, ' ',
|
file, ' ',
|
||||||
@ -271,26 +268,26 @@ int evtag_unmarshal_%(name)s(struct evbuffer *, ev_uint32_t,
|
|||||||
entry.GetVarName('tmp'),
|
entry.GetVarName('tmp'),
|
||||||
entry.GetVarLen('tmp')))
|
entry.GetVarLen('tmp')))
|
||||||
|
|
||||||
print >>file, ( ' tmp->%s_set = 1;\n' % entry.Name() +
|
file.write(( ' tmp->%s_set = 1;\n' % entry.Name() +
|
||||||
' break;\n' )
|
' break;\n' ))
|
||||||
print >>file, ( ' default:\n'
|
file.write(( ' default:\n'
|
||||||
' return -1;\n'
|
' return -1;\n'
|
||||||
' }\n'
|
' }\n'
|
||||||
' }\n' )
|
' }\n\n' ))
|
||||||
# Check if it was decoded completely
|
# Check if it was decoded completely
|
||||||
print >>file, ( ' if (%(name)s_complete(tmp) == -1)\n'
|
file.write(( ' if (%(name)s_complete(tmp) == -1)\n'
|
||||||
' return (-1);'
|
' return (-1);'
|
||||||
) % { 'name' : self._name }
|
'\n') % { 'name' : self._name })
|
||||||
|
|
||||||
# Successfully decoded
|
# Successfully decoded
|
||||||
print >>file, ( ' return (0);\n'
|
file.write(( ' return (0);\n'
|
||||||
'}\n')
|
'}\n\n'))
|
||||||
|
|
||||||
# Checking if a structure has all the required data
|
# Checking if a structure has all the required data
|
||||||
print >>file, (
|
file.write((
|
||||||
'int\n'
|
'int\n'
|
||||||
'%(name)s_complete(struct %(name)s *msg)\n'
|
'%(name)s_complete(struct %(name)s *msg)\n'
|
||||||
'{' ) % { 'name' : self._name }
|
'{\n' ) % { 'name' : self._name })
|
||||||
for entry in self._entries:
|
for entry in self._entries:
|
||||||
if not entry.Optional():
|
if not entry.Optional():
|
||||||
code = [
|
code = [
|
||||||
@ -303,12 +300,12 @@ int evtag_unmarshal_%(name)s(struct evbuffer *, ev_uint32_t,
|
|||||||
self.PrintIndented(
|
self.PrintIndented(
|
||||||
file, ' ',
|
file, ' ',
|
||||||
entry.CodeComplete('msg', entry.GetVarName('msg')))
|
entry.CodeComplete('msg', entry.GetVarName('msg')))
|
||||||
print >>file, (
|
file.write((
|
||||||
' return (0);\n'
|
' return (0);\n'
|
||||||
'}\n' )
|
'}\n\n' ))
|
||||||
|
|
||||||
# Complete message unmarshaling
|
# Complete message unmarshaling
|
||||||
print >>file, (
|
file.write((
|
||||||
'int\n'
|
'int\n'
|
||||||
'evtag_unmarshal_%(name)s(struct evbuffer *evbuf, '
|
'evtag_unmarshal_%(name)s(struct evbuffer *evbuf, '
|
||||||
'ev_uint32_t need_tag, struct %(name)s *msg)\n'
|
'ev_uint32_t need_tag, struct %(name)s *msg)\n'
|
||||||
@ -330,10 +327,10 @@ int evtag_unmarshal_%(name)s(struct evbuffer *, ev_uint32_t,
|
|||||||
' error:\n'
|
' error:\n'
|
||||||
' evbuffer_free(tmp);\n'
|
' evbuffer_free(tmp);\n'
|
||||||
' return (res);\n'
|
' return (res);\n'
|
||||||
'}\n' ) % { 'name' : self._name }
|
'}\n\n' ) % { 'name' : self._name })
|
||||||
|
|
||||||
# Complete message marshaling
|
# Complete message marshaling
|
||||||
print >>file, (
|
file.write((
|
||||||
'void\n'
|
'void\n'
|
||||||
'evtag_marshal_%(name)s(struct evbuffer *evbuf, ev_uint32_t tag, '
|
'evtag_marshal_%(name)s(struct evbuffer *evbuf, ev_uint32_t tag, '
|
||||||
'const struct %(name)s *msg)\n'
|
'const struct %(name)s *msg)\n'
|
||||||
@ -343,7 +340,7 @@ int evtag_unmarshal_%(name)s(struct evbuffer *, ev_uint32_t,
|
|||||||
' %(name)s_marshal(buf_, msg);\n'
|
' %(name)s_marshal(buf_, msg);\n'
|
||||||
' evtag_marshal_buffer(evbuf, tag, buf_);\n '
|
' evtag_marshal_buffer(evbuf, tag, buf_);\n '
|
||||||
' evbuffer_free(buf_);\n'
|
' evbuffer_free(buf_);\n'
|
||||||
'}\n' ) % { 'name' : self._name }
|
'}\n\n' ) % { 'name' : self._name })
|
||||||
|
|
||||||
class Entry:
|
class Entry:
|
||||||
def __init__(self, type, name, tag):
|
def __init__(self, type, name, tag):
|
||||||
@ -420,7 +417,7 @@ class Entry:
|
|||||||
"optaddarg" :
|
"optaddarg" :
|
||||||
self._optaddarg and ", const %s value" % self._ctype or ""
|
self._optaddarg and ", const %s value" % self._ctype or ""
|
||||||
}
|
}
|
||||||
for (k, v) in extradict.items():
|
for (k, v) in list(extradict.items()):
|
||||||
mapping[k] = v
|
mapping[k] = v
|
||||||
|
|
||||||
return mapping
|
return mapping
|
||||||
@ -1127,7 +1124,7 @@ class EntryArray(Entry):
|
|||||||
|
|
||||||
codearrayassign = self._entry.CodeArrayAssign(
|
codearrayassign = self._entry.CodeArrayAssign(
|
||||||
'msg->%(name)s_data[off]' % self.GetTranslation(), 'value')
|
'msg->%(name)s_data[off]' % self.GetTranslation(), 'value')
|
||||||
code += map(lambda x: ' ' + x, codearrayassign)
|
code += [' ' + x for x in codearrayassign]
|
||||||
|
|
||||||
code += TranslateList([
|
code += TranslateList([
|
||||||
' }',
|
' }',
|
||||||
@ -1168,7 +1165,7 @@ class EntryArray(Entry):
|
|||||||
|
|
||||||
code = TranslateList(code, self.GetTranslation())
|
code = TranslateList(code, self.GetTranslation())
|
||||||
|
|
||||||
code += map(lambda x: ' ' + x, codearrayadd)
|
code += [' ' + x for x in codearrayadd]
|
||||||
|
|
||||||
code += TranslateList([
|
code += TranslateList([
|
||||||
' msg->%(name)s_set = 1;',
|
' msg->%(name)s_set = 1;',
|
||||||
@ -1196,7 +1193,7 @@ class EntryArray(Entry):
|
|||||||
|
|
||||||
code = TranslateList(code, translate)
|
code = TranslateList(code, translate)
|
||||||
|
|
||||||
code += map(lambda x: ' ' + x, tmp)
|
code += [' ' + x for x in tmp]
|
||||||
|
|
||||||
code += [
|
code += [
|
||||||
' }',
|
' }',
|
||||||
@ -1261,7 +1258,7 @@ class EntryArray(Entry):
|
|||||||
code = TranslateList(code, translate)
|
code = TranslateList(code, translate)
|
||||||
|
|
||||||
if codearrayfree:
|
if codearrayfree:
|
||||||
code += map(lambda x: ' ' + x, codearrayfree)
|
code += [' ' + x for x in codearrayfree]
|
||||||
code += [
|
code += [
|
||||||
' }' ]
|
' }' ]
|
||||||
|
|
||||||
@ -1687,23 +1684,23 @@ class CommandLine:
|
|||||||
|
|
||||||
declare('... creating "%s"' % header_file)
|
declare('... creating "%s"' % header_file)
|
||||||
header_fp = open(header_file, 'w')
|
header_fp = open(header_file, 'w')
|
||||||
print >>header_fp, factory.HeaderPreamble(filename)
|
header_fp.write(factory.HeaderPreamble(filename))
|
||||||
|
|
||||||
# Create forward declarations: allows other structs to reference
|
# Create forward declarations: allows other structs to reference
|
||||||
# each other
|
# each other
|
||||||
for entry in entities:
|
for entry in entities:
|
||||||
entry.PrintForwardDeclaration(header_fp)
|
entry.PrintForwardDeclaration(header_fp)
|
||||||
print >>header_fp, ''
|
header_fp.write('\n')
|
||||||
|
|
||||||
for entry in entities:
|
for entry in entities:
|
||||||
entry.PrintTags(header_fp)
|
entry.PrintTags(header_fp)
|
||||||
entry.PrintDeclaration(header_fp)
|
entry.PrintDeclaration(header_fp)
|
||||||
print >>header_fp, factory.HeaderPostamble(filename)
|
header_fp.write(factory.HeaderPostamble(filename))
|
||||||
header_fp.close()
|
header_fp.close()
|
||||||
|
|
||||||
declare('... creating "%s"' % impl_file)
|
declare('... creating "%s"' % impl_file)
|
||||||
impl_fp = open(impl_file, 'w')
|
impl_fp = open(impl_file, 'w')
|
||||||
print >>impl_fp, factory.BodyPreamble(filename, header_file)
|
impl_fp.write(factory.BodyPreamble(filename, header_file))
|
||||||
for entry in entities:
|
for entry in entities:
|
||||||
entry.PrintCode(impl_fp)
|
entry.PrintCode(impl_fp)
|
||||||
impl_fp.close()
|
impl_fp.close()
|
||||||
@ -1713,16 +1710,16 @@ if __name__ == '__main__':
|
|||||||
CommandLine(sys.argv).run()
|
CommandLine(sys.argv).run()
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
except RpcGenError, e:
|
except RpcGenError as e:
|
||||||
print >>sys.stderr, e
|
sys.stderr.write(e)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
except EnvironmentError, e:
|
except EnvironmentError as e:
|
||||||
if e.filename and e.strerror:
|
if e.filename and e.strerror:
|
||||||
print >>sys.stderr, "%s: %s" % (e.filename, e.strerror)
|
sys.stderr.write("%s: %s" % (e.filename, e.strerror))
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
elif e.strerror:
|
elif e.strerror:
|
||||||
print >> sys.stderr, e.strerror
|
sys.stderr.write(e.strerror)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
else:
|
else:
|
||||||
raise
|
raise
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
#!/usr/bin/python2
|
#!/usr/bin/env python
|
||||||
#
|
#
|
||||||
# Post-process the output of test-dumpevents and check it for correctness.
|
# Post-process the output of test-dumpevents and check it for correctness.
|
||||||
#
|
#
|
||||||
@ -15,12 +15,12 @@ try:
|
|||||||
got_inserted_pos = text.index("Inserted events:\n")
|
got_inserted_pos = text.index("Inserted events:\n")
|
||||||
got_active_pos = text.index("Active events:\n")
|
got_active_pos = text.index("Active events:\n")
|
||||||
except ValueError:
|
except ValueError:
|
||||||
print >>sys.stderr, "Missing expected dividing line in dumpevents output"
|
sys.stderr.write("Missing expected dividing line in dumpevents output")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
if not (expect_inserted_pos < expect_active_pos <
|
if not (expect_inserted_pos < expect_active_pos <
|
||||||
got_inserted_pos < got_active_pos):
|
got_inserted_pos < got_active_pos):
|
||||||
print >>sys.stderr, "Sections out of order in dumpevents output"
|
sys.stderr.write("Sections out of order in dumpevents output")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
now,T= text[1].split()
|
now,T= text[1].split()
|
||||||
@ -45,10 +45,10 @@ cleaned_inserted = set( pat.sub(replace_time, s) for s in got_inserted
|
|||||||
if "Internal" not in s)
|
if "Internal" not in s)
|
||||||
|
|
||||||
if cleaned_inserted != want_inserted:
|
if cleaned_inserted != want_inserted:
|
||||||
print >>sys.stderr, "Inserted event lists were not as expected!"
|
sys.stderr.write("Inserted event lists were not as expected!")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
if set(got_active) != set(want_active):
|
if set(got_active) != set(want_active):
|
||||||
print >>sys.stderr, "Active event lists were not as expected!"
|
sys.stderr.write("Active event lists were not as expected!")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
@ -25,19 +25,10 @@ exit_failed() {
|
|||||||
echo "Could not generate regress.gen.\[ch\] using event_rpcgen.sh" >&2
|
echo "Could not generate regress.gen.\[ch\] using event_rpcgen.sh" >&2
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
if [ -x /usr/bin/python2 ] ; then
|
|
||||||
PYTHON2=/usr/bin/python2
|
|
||||||
elif [ "x`which python2`" != x ] ; then
|
|
||||||
PYTHON2=python2
|
|
||||||
else
|
|
||||||
PYTHON2=python
|
|
||||||
fi
|
|
||||||
|
|
||||||
srcdir=$1
|
srcdir=$1
|
||||||
srcdir=${srcdir:-.}
|
srcdir=${srcdir:-.}
|
||||||
|
|
||||||
${PYTHON2} ${srcdir}/../event_rpcgen.py --quiet ${srcdir}/regress.rpc \
|
${srcdir}/../event_rpcgen.py --quiet ${srcdir}/regress.rpc \
|
||||||
test/regress.gen.h test/regress.gen.c
|
test/regress.gen.h test/regress.gen.c
|
||||||
|
|
||||||
case "$?" in
|
case "$?" in
|
||||||
|
@ -82,8 +82,8 @@ run_tests () {
|
|||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
announce_n " test-dumpevents: "
|
announce_n " test-dumpevents: "
|
||||||
if python2 -c 'import sys; assert(sys.version_info >= (2, 4))' 2>/dev/null && test -f $TEST_SRC_DIR/check-dumpevents.py; then
|
if python -c 'import sys; assert(sys.version_info >= (2, 4))' 2>/dev/null && test -f $TEST_SRC_DIR/check-dumpevents.py; then
|
||||||
if $TEST_DIR/test-dumpevents | python2 $TEST_SRC_DIR/check-dumpevents.py >> "$TEST_OUTPUT_FILE" ;
|
if $TEST_DIR/test-dumpevents | $TEST_SRC_DIR/check-dumpevents.py >> "$TEST_OUTPUT_FILE" ;
|
||||||
then
|
then
|
||||||
announce OKAY ;
|
announce OKAY ;
|
||||||
else
|
else
|
||||||
|
Loading…
x
Reference in New Issue
Block a user