czmq-ffi-gen 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -60,22 +60,27 @@ module CZMQ
60
60
  raise DestroyedError unless @ptr
61
61
  ptr_ptr = ::FFI::MemoryPointer.new :pointer
62
62
  ptr_ptr.write_pointer @ptr
63
- ObjectSpace.undefine_finalizer self if @finalizer
64
- @finalizer = nil
63
+ __undef_finalizer if @finalizer
65
64
  @ptr = nil
66
65
  ptr_ptr
67
66
  end
67
+ # Undefines the finalizer for this object.
68
+ # @note Only use this if you need to and can guarantee that the native
69
+ # object will be freed by other means.
70
+ # @return [void]
71
+ def __undef_finalizer
72
+ ObjectSpace.undefine_finalizer self
73
+ @finalizer = nil
74
+ end
68
75
 
69
76
  # Create new patch
70
- # @param path [String, #to_str, #to_s]
77
+ # @param path [String, #to_s, nil]
71
78
  # @param file [Zfile, #__ptr]
72
79
  # @param op [Symbol]
73
- # @param alias_ [String, #to_str, #to_s]
80
+ # @param alias_ [String, #to_s, nil]
74
81
  # @return [CZMQ::ZdirPatch]
75
82
  def self.new(path, file, op, alias_)
76
- path = String(path)
77
83
  file = file.__ptr if file
78
- alias_ = String(alias_)
79
84
  ptr = ::CZMQ::FFI.zdir_patch_new(path, file, op, alias_)
80
85
  __new ptr
81
86
  end
@@ -60,23 +60,28 @@ module CZMQ
60
60
  raise DestroyedError unless @ptr
61
61
  ptr_ptr = ::FFI::MemoryPointer.new :pointer
62
62
  ptr_ptr.write_pointer @ptr
63
- ObjectSpace.undefine_finalizer self if @finalizer
64
- @finalizer = nil
63
+ __undef_finalizer if @finalizer
65
64
  @ptr = nil
66
65
  ptr_ptr
67
66
  end
67
+ # Undefines the finalizer for this object.
68
+ # @note Only use this if you need to and can guarantee that the native
69
+ # object will be freed by other means.
70
+ # @return [void]
71
+ def __undef_finalizer
72
+ ObjectSpace.undefine_finalizer self
73
+ @finalizer = nil
74
+ end
68
75
 
69
76
  # If file exists, populates properties. CZMQ supports portable symbolic
70
77
  # links, which are files with the extension ".ln". A symbolic link is a
71
78
  # text file containing one line, the filename of a target file. Reading
72
79
  # data from the symbolic link actually reads from the target file. Path
73
80
  # may be NULL, in which case it is not used.
74
- # @param path [String, #to_str, #to_s]
75
- # @param name [String, #to_str, #to_s]
81
+ # @param path [String, #to_s, nil]
82
+ # @param name [String, #to_s, nil]
76
83
  # @return [CZMQ::Zfile]
77
84
  def self.new(path, name)
78
- path = String(path)
79
- name = String(name)
80
85
  ptr = ::CZMQ::FFI.zfile_new(path, name)
81
86
  __new ptr
82
87
  end
@@ -105,12 +110,11 @@ module CZMQ
105
110
 
106
111
  # Return file name, remove path if provided
107
112
  #
108
- # @param path [String, #to_str, #to_s]
113
+ # @param path [String, #to_s, nil]
109
114
  # @return [String]
110
115
  def filename(path)
111
116
  raise DestroyedError unless @ptr
112
117
  self_p = @ptr
113
- path = String(path)
114
118
  result = ::CZMQ::FFI.zfile_filename(self_p, path)
115
119
  result
116
120
  end
@@ -60,11 +60,18 @@ module CZMQ
60
60
  raise DestroyedError unless @ptr
61
61
  ptr_ptr = ::FFI::MemoryPointer.new :pointer
62
62
  ptr_ptr.write_pointer @ptr
63
- ObjectSpace.undefine_finalizer self if @finalizer
64
- @finalizer = nil
63
+ __undef_finalizer if @finalizer
65
64
  @ptr = nil
66
65
  ptr_ptr
67
66
  end
67
+ # Undefines the finalizer for this object.
68
+ # @note Only use this if you need to and can guarantee that the native
69
+ # object will be freed by other means.
70
+ # @return [void]
71
+ def __undef_finalizer
72
+ ObjectSpace.undefine_finalizer self
73
+ @finalizer = nil
74
+ end
68
75
 
69
76
  # Create a new frame. If size is not null, allocates the frame data
70
77
  # to the specified size. If additionally, data is not null, copies
@@ -86,10 +93,9 @@ module CZMQ
86
93
  end
87
94
 
88
95
  # Create a frame with a specified string content.
89
- # @param string [String, #to_str, #to_s]
96
+ # @param string [String, #to_s, nil]
90
97
  # @return [CZMQ::Zframe]
91
98
  def self.from(string)
92
- string = String(string)
93
99
  ptr = ::CZMQ::FFI.zframe_from(string)
94
100
  __new ptr
95
101
  end
@@ -186,12 +192,11 @@ module CZMQ
186
192
 
187
193
  # Return TRUE if frame body is equal to string, excluding terminator
188
194
  #
189
- # @param string [String, #to_str, #to_s]
195
+ # @param string [String, #to_s, nil]
190
196
  # @return [Boolean]
191
197
  def streq(string)
192
198
  raise DestroyedError unless @ptr
193
199
  self_p = @ptr
194
- string = String(string)
195
200
  result = ::CZMQ::FFI.zframe_streq(self_p, string)
196
201
  result
197
202
  end
@@ -273,12 +278,11 @@ module CZMQ
273
278
  # Send message to zsys log sink (may be stdout, or system facility as
274
279
  # configured by zsys_set_logstream). Prefix shows before frame, if not null.
275
280
  #
276
- # @param prefix [String, #to_str, #to_s]
281
+ # @param prefix [String, #to_s, nil]
277
282
  # @return [void]
278
283
  def print(prefix)
279
284
  raise DestroyedError unless @ptr
280
285
  self_p = @ptr
281
- prefix = String(prefix)
282
286
  result = ::CZMQ::FFI.zframe_print(self_p, prefix)
283
287
  result
284
288
  end
@@ -60,11 +60,18 @@ module CZMQ
60
60
  raise DestroyedError unless @ptr
61
61
  ptr_ptr = ::FFI::MemoryPointer.new :pointer
62
62
  ptr_ptr.write_pointer @ptr
63
- ObjectSpace.undefine_finalizer self if @finalizer
64
- @finalizer = nil
63
+ __undef_finalizer if @finalizer
65
64
  @ptr = nil
66
65
  ptr_ptr
67
66
  end
67
+ # Undefines the finalizer for this object.
68
+ # @note Only use this if you need to and can guarantee that the native
69
+ # object will be freed by other means.
70
+ # @return [void]
71
+ def __undef_finalizer
72
+ ObjectSpace.undefine_finalizer self
73
+ @finalizer = nil
74
+ end
68
75
 
69
76
  # Create a new callback of the following type:
70
77
  # Callback function for zhash_freefn method
@@ -131,13 +138,12 @@ module CZMQ
131
138
  # If key is already present returns -1 and leaves existing item unchanged
132
139
  # Returns 0 on success.
133
140
  #
134
- # @param key [String, #to_str, #to_s]
141
+ # @param key [String, #to_s, nil]
135
142
  # @param item [::FFI::Pointer, #to_ptr]
136
143
  # @return [Integer]
137
144
  def insert(key, item)
138
145
  raise DestroyedError unless @ptr
139
146
  self_p = @ptr
140
- key = String(key)
141
147
  result = ::CZMQ::FFI.zhash_insert(self_p, key, item)
142
148
  result
143
149
  end
@@ -146,13 +152,12 @@ module CZMQ
146
152
  # If key is already present, destroys old item and inserts new one.
147
153
  # Use free_fn method to ensure deallocator is properly called on item.
148
154
  #
149
- # @param key [String, #to_str, #to_s]
155
+ # @param key [String, #to_s, nil]
150
156
  # @param item [::FFI::Pointer, #to_ptr]
151
157
  # @return [void]
152
158
  def update(key, item)
153
159
  raise DestroyedError unless @ptr
154
160
  self_p = @ptr
155
- key = String(key)
156
161
  result = ::CZMQ::FFI.zhash_update(self_p, key, item)
157
162
  result
158
163
  end
@@ -160,24 +165,22 @@ module CZMQ
160
165
  # Remove an item specified by key from the hash table. If there was no such
161
166
  # item, this function does nothing.
162
167
  #
163
- # @param key [String, #to_str, #to_s]
168
+ # @param key [String, #to_s, nil]
164
169
  # @return [void]
165
170
  def delete(key)
166
171
  raise DestroyedError unless @ptr
167
172
  self_p = @ptr
168
- key = String(key)
169
173
  result = ::CZMQ::FFI.zhash_delete(self_p, key)
170
174
  result
171
175
  end
172
176
 
173
177
  # Return the item at the specified key, or null
174
178
  #
175
- # @param key [String, #to_str, #to_s]
179
+ # @param key [String, #to_s, nil]
176
180
  # @return [::FFI::Pointer]
177
181
  def lookup(key)
178
182
  raise DestroyedError unless @ptr
179
183
  self_p = @ptr
180
- key = String(key)
181
184
  result = ::CZMQ::FFI.zhash_lookup(self_p, key)
182
185
  result
183
186
  end
@@ -185,14 +188,12 @@ module CZMQ
185
188
  # Reindexes an item from an old key to a new key. If there was no such
186
189
  # item, does nothing. Returns 0 if successful, else -1.
187
190
  #
188
- # @param old_key [String, #to_str, #to_s]
189
- # @param new_key [String, #to_str, #to_s]
191
+ # @param old_key [String, #to_s, nil]
192
+ # @param new_key [String, #to_s, nil]
190
193
  # @return [Integer]
191
194
  def rename(old_key, new_key)
192
195
  raise DestroyedError unless @ptr
193
196
  self_p = @ptr
194
- old_key = String(old_key)
195
- new_key = String(new_key)
196
197
  result = ::CZMQ::FFI.zhash_rename(self_p, old_key, new_key)
197
198
  result
198
199
  end
@@ -203,13 +204,12 @@ module CZMQ
203
204
  # you don't have memory leaks. You can pass 'free' or NULL as a free_fn.
204
205
  # Returns the item, or NULL if there is no such item.
205
206
  #
206
- # @param key [String, #to_str, #to_s]
207
+ # @param key [String, #to_s, nil]
207
208
  # @param free_fn [::FFI::Pointer, #to_ptr]
208
209
  # @return [::FFI::Pointer]
209
210
  def freefn(key, free_fn)
210
211
  raise DestroyedError unless @ptr
211
212
  self_p = @ptr
212
- key = String(key)
213
213
  result = ::CZMQ::FFI.zhash_freefn(self_p, key, free_fn)
214
214
  result
215
215
  end
@@ -294,13 +294,12 @@ module CZMQ
294
294
  # comment lines as you like. These comment lines are discarded when loading
295
295
  # the file. If you use a null format, all comments are deleted.
296
296
  #
297
- # @param format [String, #to_str, #to_s]
297
+ # @param format [String, #to_s, nil]
298
298
  # @param args [Array<Object>] see https://github.com/ffi/ffi/wiki/examples#using-varargs
299
299
  # @return [void]
300
300
  def comment(format, *args)
301
301
  raise DestroyedError unless @ptr
302
302
  self_p = @ptr
303
- format = String(format)
304
303
  result = ::CZMQ::FFI.zhash_comment(self_p, format, *args)
305
304
  result
306
305
  end
@@ -339,12 +338,11 @@ module CZMQ
339
338
  # printable strings; keys may not contain '=' character. Returns 0 if OK,
340
339
  # else -1 if a file error occurred.
341
340
  #
342
- # @param filename [String, #to_str, #to_s]
341
+ # @param filename [String, #to_s, nil]
343
342
  # @return [Integer]
344
343
  def save(filename)
345
344
  raise DestroyedError unless @ptr
346
345
  self_p = @ptr
347
- filename = String(filename)
348
346
  result = ::CZMQ::FFI.zhash_save(self_p, filename)
349
347
  result
350
348
  end
@@ -353,12 +351,11 @@ module CZMQ
353
351
  # already exist. Hash values must printable strings; keys may not contain
354
352
  # '=' character. Returns 0 if OK, else -1 if a file was not readable.
355
353
  #
356
- # @param filename [String, #to_str, #to_s]
354
+ # @param filename [String, #to_s, nil]
357
355
  # @return [Integer]
358
356
  def load(filename)
359
357
  raise DestroyedError unless @ptr
360
358
  self_p = @ptr
361
- filename = String(filename)
362
359
  result = ::CZMQ::FFI.zhash_load(self_p, filename)
363
360
  result
364
361
  end
@@ -60,11 +60,18 @@ module CZMQ
60
60
  raise DestroyedError unless @ptr
61
61
  ptr_ptr = ::FFI::MemoryPointer.new :pointer
62
62
  ptr_ptr.write_pointer @ptr
63
- ObjectSpace.undefine_finalizer self if @finalizer
64
- @finalizer = nil
63
+ __undef_finalizer if @finalizer
65
64
  @ptr = nil
66
65
  ptr_ptr
67
66
  end
67
+ # Undefines the finalizer for this object.
68
+ # @note Only use this if you need to and can guarantee that the native
69
+ # object will be freed by other means.
70
+ # @return [void]
71
+ def __undef_finalizer
72
+ ObjectSpace.undefine_finalizer self
73
+ @finalizer = nil
74
+ end
68
75
 
69
76
  # Create a new callback of the following type:
70
77
  # Destroy an item
@@ -366,13 +373,12 @@ module CZMQ
366
373
  # comment lines as you like. These comment lines are discarded when loading
367
374
  # the file. If you use a null format, all comments are deleted.
368
375
  #
369
- # @param format [String, #to_str, #to_s]
376
+ # @param format [String, #to_s, nil]
370
377
  # @param args [Array<Object>] see https://github.com/ffi/ffi/wiki/examples#using-varargs
371
378
  # @return [void]
372
379
  def comment(format, *args)
373
380
  raise DestroyedError unless @ptr
374
381
  self_p = @ptr
375
- format = String(format)
376
382
  result = ::CZMQ::FFI.zhashx_comment(self_p, format, *args)
377
383
  result
378
384
  end
@@ -381,12 +387,11 @@ module CZMQ
381
387
  # printable strings; keys may not contain '=' character. Returns 0 if OK,
382
388
  # else -1 if a file error occurred.
383
389
  #
384
- # @param filename [String, #to_str, #to_s]
390
+ # @param filename [String, #to_s, nil]
385
391
  # @return [Integer]
386
392
  def save(filename)
387
393
  raise DestroyedError unless @ptr
388
394
  self_p = @ptr
389
- filename = String(filename)
390
395
  result = ::CZMQ::FFI.zhashx_save(self_p, filename)
391
396
  result
392
397
  end
@@ -395,12 +400,11 @@ module CZMQ
395
400
  # already exist. Hash values must printable strings; keys may not contain
396
401
  # '=' character. Returns 0 if OK, else -1 if a file was not readable.
397
402
  #
398
- # @param filename [String, #to_str, #to_s]
403
+ # @param filename [String, #to_s, nil]
399
404
  # @return [Integer]
400
405
  def load(filename)
401
406
  raise DestroyedError unless @ptr
402
407
  self_p = @ptr
403
- filename = String(filename)
404
408
  result = ::CZMQ::FFI.zhashx_load(self_p, filename)
405
409
  result
406
410
  end
@@ -60,11 +60,18 @@ module CZMQ
60
60
  raise DestroyedError unless @ptr
61
61
  ptr_ptr = ::FFI::MemoryPointer.new :pointer
62
62
  ptr_ptr.write_pointer @ptr
63
- ObjectSpace.undefine_finalizer self if @finalizer
64
- @finalizer = nil
63
+ __undef_finalizer if @finalizer
65
64
  @ptr = nil
66
65
  ptr_ptr
67
66
  end
67
+ # Undefines the finalizer for this object.
68
+ # @note Only use this if you need to and can guarantee that the native
69
+ # object will be freed by other means.
70
+ # @return [void]
71
+ def __undef_finalizer
72
+ ObjectSpace.undefine_finalizer self
73
+ @finalizer = nil
74
+ end
68
75
 
69
76
  # Get a list of network interfaces currently defined on the system
70
77
  # @return [CZMQ::Ziflist]
@@ -60,11 +60,18 @@ module CZMQ
60
60
  raise DestroyedError unless @ptr
61
61
  ptr_ptr = ::FFI::MemoryPointer.new :pointer
62
62
  ptr_ptr.write_pointer @ptr
63
- ObjectSpace.undefine_finalizer self if @finalizer
64
- @finalizer = nil
63
+ __undef_finalizer if @finalizer
65
64
  @ptr = nil
66
65
  ptr_ptr
67
66
  end
67
+ # Undefines the finalizer for this object.
68
+ # @note Only use this if you need to and can guarantee that the native
69
+ # object will be freed by other means.
70
+ # @return [void]
71
+ def __undef_finalizer
72
+ ObjectSpace.undefine_finalizer self
73
+ @finalizer = nil
74
+ end
68
75
 
69
76
  # Create a new callback of the following type:
70
77
  # Comparison function e.g. for sorting and removing.
@@ -60,11 +60,18 @@ module CZMQ
60
60
  raise DestroyedError unless @ptr
61
61
  ptr_ptr = ::FFI::MemoryPointer.new :pointer
62
62
  ptr_ptr.write_pointer @ptr
63
- ObjectSpace.undefine_finalizer self if @finalizer
64
- @finalizer = nil
63
+ __undef_finalizer if @finalizer
65
64
  @ptr = nil
66
65
  ptr_ptr
67
66
  end
67
+ # Undefines the finalizer for this object.
68
+ # @note Only use this if you need to and can guarantee that the native
69
+ # object will be freed by other means.
70
+ # @return [void]
71
+ def __undef_finalizer
72
+ ObjectSpace.undefine_finalizer self
73
+ @finalizer = nil
74
+ end
68
75
 
69
76
  # Create a new callback of the following type:
70
77
  # Callback function for reactor socket activity
@@ -60,11 +60,18 @@ module CZMQ
60
60
  raise DestroyedError unless @ptr
61
61
  ptr_ptr = ::FFI::MemoryPointer.new :pointer
62
62
  ptr_ptr.write_pointer @ptr
63
- ObjectSpace.undefine_finalizer self if @finalizer
64
- @finalizer = nil
63
+ __undef_finalizer if @finalizer
65
64
  @ptr = nil
66
65
  ptr_ptr
67
66
  end
67
+ # Undefines the finalizer for this object.
68
+ # @note Only use this if you need to and can guarantee that the native
69
+ # object will be freed by other means.
70
+ # @return [void]
71
+ def __undef_finalizer
72
+ ObjectSpace.undefine_finalizer self
73
+ @finalizer = nil
74
+ end
68
75
 
69
76
  # Create a new empty message object
70
77
  # @return [CZMQ::Zmsg]
@@ -272,12 +279,11 @@ module CZMQ
272
279
  # Push string as new frame to front of message.
273
280
  # Returns 0 on success, -1 on error.
274
281
  #
275
- # @param string [String, #to_str, #to_s]
282
+ # @param string [String, #to_s, nil]
276
283
  # @return [Integer]
277
284
  def pushstr(string)
278
285
  raise DestroyedError unless @ptr
279
286
  self_p = @ptr
280
- string = String(string)
281
287
  result = ::CZMQ::FFI.zmsg_pushstr(self_p, string)
282
288
  result
283
289
  end
@@ -285,12 +291,11 @@ module CZMQ
285
291
  # Push string as new frame to end of message.
286
292
  # Returns 0 on success, -1 on error.
287
293
  #
288
- # @param string [String, #to_str, #to_s]
294
+ # @param string [String, #to_s, nil]
289
295
  # @return [Integer]
290
296
  def addstr(string)
291
297
  raise DestroyedError unless @ptr
292
298
  self_p = @ptr
293
- string = String(string)
294
299
  result = ::CZMQ::FFI.zmsg_addstr(self_p, string)
295
300
  result
296
301
  end
@@ -298,13 +303,12 @@ module CZMQ
298
303
  # Push formatted string as new frame to front of message.
299
304
  # Returns 0 on success, -1 on error.
300
305
  #
301
- # @param format [String, #to_str, #to_s]
306
+ # @param format [String, #to_s, nil]
302
307
  # @param args [Array<Object>] see https://github.com/ffi/ffi/wiki/examples#using-varargs
303
308
  # @return [Integer]
304
309
  def pushstrf(format, *args)
305
310
  raise DestroyedError unless @ptr
306
311
  self_p = @ptr
307
- format = String(format)
308
312
  result = ::CZMQ::FFI.zmsg_pushstrf(self_p, format, *args)
309
313
  result
310
314
  end
@@ -312,13 +316,12 @@ module CZMQ
312
316
  # Push formatted string as new frame to end of message.
313
317
  # Returns 0 on success, -1 on error.
314
318
  #
315
- # @param format [String, #to_str, #to_s]
319
+ # @param format [String, #to_s, nil]
316
320
  # @param args [Array<Object>] see https://github.com/ffi/ffi/wiki/examples#using-varargs
317
321
  # @return [Integer]
318
322
  def addstrf(format, *args)
319
323
  raise DestroyedError unless @ptr
320
324
  self_p = @ptr
321
- format = String(format)
322
325
  result = ::CZMQ::FFI.zmsg_addstrf(self_p, format, *args)
323
326
  result
324
327
  end