[Openmcl-devel] odd behaviour of #_malloc and length?

Gary Byers gb at clozure.com
Thu Jan 12 11:16:24 PST 2006



On Thu, 12 Jan 2006, Gary Byers wrote:

>
>
> On Thu, 12 Jan 2006, rs wrote:
>
>> i know there is ccl::malloc, but...
>> when i use length on a local variable containing a string in a
>> #_malloc call it errors out with:
>>   value NIL is not of the expected type (UNSIGNED-BYTE 32).
>>
>> (let* ((a "a string")
>>           (mem (#_malloc (+ (length a) 1))))
>>   (format t "mem is ~s" mem)
>>   (when mem
>>     (#_free mem)))
>>
>> -> value NIL is not of the expected type (UNSIGNED-BYTE 32).
>>
> This is pretty nasty (and I think that it's been lurking around for
> a fairly long time.)  Let me try to do a little testing (not an
> entirely foreign concept ...) and I'll try to check in fixes to
> both the main and bleeding-edge CVS trees later today.

I think that I found all cases of this (fixnum addition, subtraction,
and negation weren't storing the result of the operation in the right
register when the result was being used to initialize a foreign arg
of type (UNSIGNED-BYTE 32).  I checked the changes into both CVS trees.

It's currently not too hard to rebuild from the main CVS tree with
OpenMCL-1.0; if you do a CVS update and recompile everything, you
may get a few (benign) warnings during (COMPILE-CCL), but things 
should be run OK.

If you build (as of today) from the main CVS tree, the resulting
lisp will identify itself as "Version 1.0-p060112".  It incorporates
a few other post 1.0 bug fixes; there -are- some known 1.0 bugs
whose fixes are harder to bootstrap, so there should probably be
a 1.1 maintenance release soon.

As I said, this bug is nasty (there may be other situtations - besides
FFI stuff - where things wind up in the wrong machine register.)  I
-think- that the changes that I just committed fix it, but if you'd
asked me yesterday I would have said that this stuff was simple/mature
enough that nothing could go wrong.

>
>>
>> (let* ((mem (#_malloc (+ (length "a string") 1))))
>>
>> (let* ((mem (#_malloc (+ (length "a string") 1))))
>>
>> (let* ((a "a string")
>>           (mem (#_malloc (+ (array-total-size a) 1))))
>>
>> (let* ((a "a string")
>>        (mem (#_malloc (+ (ccl::uv-size a) 1))))
>>
>> (let* ((a '(1 2 3 4))
>>           (mem (#_malloc (+ (length a) 1))))
>>
>> (let* ((a "a string")
>>           (len (+ (length a) 1))
>>           (mem (#_malloc len)))
>>
>>
>>
>> _______________________________________________
>> Openmcl-devel mailing list
>> Openmcl-devel at clozure.com
>> http://clozure.com/mailman/listinfo/openmcl-devel
>>
>>
> _______________________________________________
> Openmcl-devel mailing list
> Openmcl-devel at clozure.com
> http://clozure.com/mailman/listinfo/openmcl-devel
>
>



More information about the Openmcl-devel mailing list