GemTalk / GemConnectForRabbitMQ

Connects GemStone/64 to RabbitMQ via librabbitmq
MIT License
0 stars 1 forks source link

GsAmqpBytes class>>fromStringEncodeAsUtf8: #8

Open feldti opened 6 months ago

feldti commented 6 months ago

This method is a helper method and only called by methods in AmqpFieldValue. In my code I had instances of Unicode16 and they are delivered to this method (via byteObj) and the method crashes. This may happen, when you build a dictionary in your code and then you want to build an instance of GsAmqpTableEntryArray from a dictionary.

fromStringEncodeAsUtf8: byteObj ^(byteObj size == 0) "Handle both empty byteObj and nil" ifTrue: [self emptyBytes] ifFalse: [| cba res |GsAmqpFieldValue byteObj _validateClasses: { String . MultiByteString } . "Prevent assertion failure in slow builds where byteObj class == Utf8 " cba := CByteArray gcMalloc: byteObj size. cba encodeUTF8From: byteObj into: 0 allowCodePointZero: false. (res := self new) setBytes: cba . res]

Here a

GsAmqpBytes fromStringEncodeAsUtf8: '0061_vallée_de_l-ernz_az_en_gm_zs-ddxml'

feldti commented 6 months ago

Ok, I would argue, that this is a bug in Gemstone/S. You may strip it down to:

| cByteArray sourceString |

sourceString := 'grüne' . cByteArray := CByteArray gcMalloc: sourceString size. cByteArray encodeUTF8From: sourceString into: 0 allowCodePointZero: false

feldti commented 6 months ago

I made a bug request at GemtalkSystems

feldti commented 6 months ago

Ok, after getting an answer from GemtalkSystem, the method mentioned above should coded in that way. Notice the usage of #sizeForEncodeAsUTF8 and consider instances of MultiByteString. The original error message is - by the way - a bug. They check for the size of the CByteArray and in an error case they throw an exception, but the false one.

So here is the corrected method:

GsAmqpBytes>>fromStringEncodeAsUtf8: byteObj ^(byteObj size == 0) "Handle both empty byteObj and nil" ifTrue: [self emptyBytes] ifFalse: [| cba res |GsAmqpFieldValue byteObj _validateClasses: { String . MultiByteString } . "Prevent assertion failure in slow builds where byteObj class == Utf8 " cba := CByteArray gcMalloc: byteObj sizeForEncodeAsUTF8. cba encodeUTF8From: byteObj into: 0 allowCodePointZero: false. (res := self new) setBytes: cba . res]