You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@thrift.apache.org by Miguel Enrique Cobá Martinez <mi...@gmail.com> on 2009/12/08 20:57:35 UTC

Smalltalk code generation bug and fix

Hi all,

I have found a bug in the generated code for the Smalltalk thrift
interface.

I used svn revision:

miguel@laptop:~/thrift-svn$ svn info
Ruta: .
URL: http://svn.apache.org/repos/asf/incubator/thrift/trunk
Raíz del repositorio: http://svn.apache.org/repos/asf
UUID del repositorio: 13f79535-47bb-0310-9956-ffa450edef68
Revisión: 888521
Tipo de nodo: directorio
Agendado: normal
Autor del último cambio: todd
Revisión del último cambio: 887812
Fecha de último cambio: 2009-12-06 18:42:38 -0600 (dom 06 de dic de
2009)

I did:

bootstrap.sh
configure
make

and then I tried to load the thrift smalltalk code from

lib/st/thrift.st 

in a squeak Squeak3.10.2-7179-basic.zip, pristine image from squeak.org.
That halted with an error about a duplicated readString method
declaration. The error is fixed in the attached patch.

Next I compiled the code for the cassandra thrift:

https://svn.apache.org/repos/asf/incubator/cassandra/trunk/interface/cassandra.thrift

with the command:

./compiler/cpp/thrift --gen st cassandra.thrift 

and tried to file in the generated code 

gen-st/cassandra.st

in said image.

Again the load halted. This time because of the underscores in the
generated code for the cassandra thrift definition. Squeak (and derived
smalltalks as Pharo) doesn't allow underscores in variable names (the
underscore is a legacy character used for variable assigment). Anyway I
have modified the code for smalltalk generator:

compiler/cpp/src/generate/t_st_generator.cc 

so that when a variable name in the thrift definition has a "_"
character, this is removed and the next character is converted to
uppercase. e.g. a variable like column_name will be generated in
smalltalk code as columnName. This way the code loads (and works
correctly) on Squeak.

The generated code has been tested in the following smalltalks:

Squeak3.10.2-7179-basic.image
PharoCore-1.0-10491rc1.image

and in both of them the new generated code for cassandra works
correctly.

I haven't tested the code generation with a thrift spec other than
cassandra, so maybe this will introduce some bugs. For my case it worked
great.
If anyone is using cassandra and want to test it, I installed the
default cassandra server on localhost port 9160 and tested from Squeak
and from Pharo by loading

lib/st/thrift.st
gen-st/cassandra.st

Then in a Squeak or Pharo workspace:

"Insert 10000 values"
[| cp result client |

client := CassandraClient binaryOnHost: 'localhost' port: 9160.

cp := ColumnPath new
  columnFamily: 'Standard1';
  column: 'col1'.

1 to: 10000 do: [ :i |
result := client insertKeyspace: 'Keyspace1'
  key: 'row', i asString
  columnPath: cp
  value: 'v', i asString
  timestamp: 1
  consistencyLevel: ((Cassandra enums at: 'ConsistencyLevel') at:
'QUORUM').]] timeToRun

And read the values just inserted:

"Read 10000 values"
[| cp result client |

client := CassandraClient binaryOnHost: 'localhost' port: 9160.
cp := ColumnPath new
  columnFamily: 'Standard1';
  column: 'col1'.

1 to: 10000 do: [ :i |
result := client getKeyspace: 'Keyspace1'
  key: 'row', i asString
  columnPath: cp
  consistencyLevel: ((Cassandra enums at: 'ConsistencyLevel') at:
'QUORUM').]] timeToRun


Regarding the patch, I am not a C++ expert and the drop_underscores()
function surely can be improved by someone with more experience with C++
idioms. Essentially what it does is to convert:

from -> to
-----   -----
a_variable -> aVariable
a_new_var -> aNewVar
column_path -> columnPath
variable -> variable

Give it a try and if deemed good enough please add it to the thrift
code.
Those changes are published under the apache public license, the same as
the thrift codebase.

Also, I just subscribed to the mailing list and saw the JIRA bug
tracking system. I tried to search for a related ticket but (apart for
the not very user-friendly interface) can't find anything. Also tried to
add an issue for the fix but asked me to register. I didn't follow that
path. If the rules for the project are to add a issue in JIRA I could
give a try again, but I prefer not to (I don't want to have other
user/password to remember).

The patch is generated with

svn diff -x -u > patch.888520

against revision 888520 of the thrift svn code.

Comments, directions, criticisms are welcome.

Cheers,
-- 
Miguel Cobá
http://miguel.leugim.com.mx

Re: Smalltalk code generation bug and fix

Posted by Miguel Enrique Cobá Martinez <mi...@gmail.com>.
I did my homework and have added an issue to the JIRA:

https://issues.apache.org/jira/browse/THRIFT-643

Cheers
-- 
Miguel Cobá
http://miguel.leugim.com.mx