Thank you for the answers and sorry for the double post, I have some 
problems with Google Groups email updates :-/

Il giorno martedì 28 gennaio 2014 14:19:45 UTC+1, Isaiah ha scritto:
>
> https://groups.google.com/d/msg/julia-dev/qgncotDBFx0/3L1hj9dibrIJ
>
>
> On Tue, Jan 28, 2014 at 3:32 AM, Maurizio De Santis 
> <[email protected]<javascript:>
> > wrote:
>
>> Hello,
>>
>> I'm studying Julia and I'm trying to write a libpq (PostgreSQL) wrapper.
>>
>> The C PQconnectdb function starts a PostgreSQL connection, and returns a 
>> pointer to the connection struct. The connection struct is not exposed by 
>> libpq, since it is not useful.
>> When the connection finishes, it must be closed using the C function 
>> PQfinish which, among other things, takes care to free the struct memory.
>>
>> So I guess I should call the PQfinish function when the connection get 
>> finalized by the GC, which this is the purpose of the following code (Julia 
>> version: 0.3.0-744~ubuntu13.10.1):
>>
>> module LibPQ
>>
>>   typealias PGconn Ptr{Void}
>>
>>   function pgconn_finalizer(x::PGconn)
>>     ccall( (:PQfinish, "libpq"), Void, (PGconn,), x )
>>     println("finalized")
>>   end
>>
>>   c = ccall( (:PQconnectdb, "libpq"), PGconn, (Ptr{Uint8},), "connection 
>> params" )
>>
>>   finalizer(c, pgconn_finalizer)
>>
>>   println(c)
>>
>>   gc()
>>
>> end
>>
>> But I get this error:
>>
>> $ julia libpq.jl 
>> ERROR: objects of type Ptr{None} cannot be finalized
>>  in finalizer at base.jl:103
>>  in include at boot.jl:240
>> while loading ./libpq.jl, in expression starting on line 12
>>
>> I guess I should use another type for the PGconn typealias, but I can't 
>> figure out what type. Any idea?
>>
>> Thank you :-)
>>
>
>

Reply via email to