Skip to content

Commit 4f664c4

Browse files
committed
Merge pull request #1010 from hintjens/master
Solved some minor clusiness
2 parents 42414a4 + 19a3504 commit 4f664c4

File tree

11 files changed

+134
-65
lines changed

11 files changed

+134
-65
lines changed

api/zframe.xml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@
2424
<return type = "zframe" fresh = "1" />
2525
</method>
2626

27+
<method name = "from" singleton = "1">
28+
Create a frame with a specified string content.
29+
<argument name = "string" type = "string" />
30+
<return type = "zframe" fresh = "1" />
31+
</method>
32+
2733
<method name = "recv" singleton = "1">
2834
Receive frame from socket, returns zframe_t object or NULL if the recv
2935
was interrupted. Does a blocking recv, if you want to not block then use
@@ -82,7 +88,7 @@
8288
</method>
8389

8490
<method name = "set more">
85-
Set frame MORE indicator (1 or 0). Note this is NOT used when sending
91+
Set frame MORE indicator (1 or 0). Note this is NOT used when sending
8692
frame to socket, you have to specify flag explicitly.
8793
<argument name = "more" type = "integer" />
8894
</method>

bindings/python/czmq.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -656,6 +656,8 @@ def test(verbose):
656656
lib.zframe_destroy.argtypes = [POINTER(zframe_p)]
657657
lib.zframe_new_empty.restype = zframe_p
658658
lib.zframe_new_empty.argtypes = []
659+
lib.zframe_from.restype = zframe_p
660+
lib.zframe_from.argtypes = [c_char_p]
659661
lib.zframe_recv.restype = zframe_p
660662
lib.zframe_recv.argtypes = [c_void_p]
661663
lib.zframe_send.restype = c_int
@@ -726,6 +728,11 @@ def new_empty():
726728
"""Create an empty (zero-sized) frame"""
727729
return Zframe(lib.zframe_new_empty(), True)
728730

731+
@staticmethod
732+
def from(string):
733+
"""Create a frame with a specified string content."""
734+
return Zframe(lib.zframe_from(string), True)
735+
729736
@staticmethod
730737
def recv(source):
731738
"""Receive frame from socket, returns zframe_t object or NULL if the recv
@@ -772,7 +779,7 @@ def more(self):
772779
return lib.zframe_more(self._as_parameter_)
773780

774781
def set_more(self, more):
775-
"""Set frame MORE indicator (1 or 0). Note this is NOT used when sending
782+
"""Set frame MORE indicator (1 or 0). Note this is NOT used when sending
776783
frame to socket, you have to specify flag explicitly."""
777784
return lib.zframe_set_more(self._as_parameter_, more)
778785

bindings/qml/src/QmlZframe.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ int QmlZframe::more () {
6363
};
6464

6565
///
66-
// Set frame MORE indicator (1 or 0). Note this is NOT used when sending
67-
// frame to socket, you have to specify flag explicitly.
66+
// Set frame MORE indicator (1 or 0). Note this is NOT used when sending
67+
// frame to socket, you have to specify flag explicitly.
6868
void QmlZframe::setMore (int more) {
6969
zframe_set_more (self, more);
7070
};
@@ -103,6 +103,14 @@ QmlZframe *QmlZframeAttached::newEmpty () {
103103
return retQ_;
104104
};
105105

106+
///
107+
// Create a frame with a specified string content.
108+
QmlZframe *QmlZframeAttached::from (const QString &string) {
109+
QmlZframe *retQ_ = new QmlZframe ();
110+
retQ_->self = zframe_from (string.toUtf8().data());
111+
return retQ_;
112+
};
113+
106114
///
107115
// Receive frame from socket, returns zframe_t object or NULL if the recv
108116
// was interrupted. Does a blocking recv, if you want to not block then use

bindings/qml/src/QmlZframe.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ public slots:
5353
// or by the zframe_set_more() method
5454
int more ();
5555

56-
// Set frame MORE indicator (1 or 0). Note this is NOT used when sending
57-
// frame to socket, you have to specify flag explicitly.
56+
// Set frame MORE indicator (1 or 0). Note this is NOT used when sending
57+
// frame to socket, you have to specify flag explicitly.
5858
void setMore (int more);
5959

6060
// Return TRUE if two frames have identical size and data
@@ -83,6 +83,9 @@ public slots:
8383
// Create an empty (zero-sized) frame
8484
QmlZframe *newEmpty ();
8585

86+
// Create a frame with a specified string content.
87+
QmlZframe *from (const QString &string);
88+
8689
// Receive frame from socket, returns zframe_t object or NULL if the recv
8790
// was interrupted. Does a blocking recv, if you want to not block then use
8891
// zpoller or zloop.

bindings/ruby/lib/czmq/ffi.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ def self.available?
106106
attach_function :zframe_new, [:pointer, :size_t], :pointer, **opts
107107
attach_function :zframe_destroy, [:pointer], :void, **opts
108108
attach_function :zframe_new_empty, [], :pointer, **opts
109+
attach_function :zframe_from, [:string], :pointer, **opts
109110
attach_function :zframe_recv, [:pointer], :pointer, **opts
110111
attach_function :zframe_send, [:pointer, :pointer, :int], :int, **opts
111112
attach_function :zframe_size, [:pointer], :size_t, **opts

bindings/ruby/lib/czmq/ffi/zframe.rb

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,14 @@ def self.new_empty
7474
result
7575
end
7676

77+
# Create a frame with a specified string content.
78+
def self.from string
79+
string = String(string)
80+
result = ::CZMQ::FFI.zframe_from string
81+
result = Zframe.__new result, true
82+
result
83+
end
84+
7785
# Receive frame from socket, returns zframe_t object or NULL if the recv
7886
# was interrupted. Does a blocking recv, if you want to not block then use
7987
# zpoller or zloop.
@@ -147,8 +155,8 @@ def more
147155
result
148156
end
149157

150-
# Set frame MORE indicator (1 or 0). Note this is NOT used when sending
151-
# frame to socket, you have to specify flag explicitly.
158+
# Set frame MORE indicator (1 or 0). Note this is NOT used when sending
159+
# frame to socket, you have to specify flag explicitly.
152160
def set_more more
153161
raise DestroyedError unless @ptr
154162
more = Integer(more)

include/zframe.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ CZMQ_EXPORT void
4040
CZMQ_EXPORT zframe_t *
4141
zframe_new_empty ();
4242

43+
// Create a frame with a specified string content.
44+
// The caller is responsible for destroying the return value when finished with it.
45+
CZMQ_EXPORT zframe_t *
46+
zframe_from (const char *string);
47+
4348
// Receive frame from socket, returns zframe_t object or NULL if the recv
4449
// was interrupted. Does a blocking recv, if you want to not block then use
4550
// zpoller or zloop.
@@ -87,8 +92,8 @@ CZMQ_EXPORT bool
8792
CZMQ_EXPORT int
8893
zframe_more (zframe_t *self);
8994

90-
// Set frame MORE indicator (1 or 0). Note this is NOT used when sending
91-
// frame to socket, you have to specify flag explicitly.
95+
// Set frame MORE indicator (1 or 0). Note this is NOT used when sending
96+
// frame to socket, you have to specify flag explicitly.
9297
CZMQ_EXPORT void
9398
zframe_set_more (zframe_t *self, int more);
9499

include/zlistx.h

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,33 +23,33 @@ extern "C" {
2323
// Create a new, empty list.
2424
CZMQ_EXPORT zlistx_t *
2525
zlistx_new (void);
26-
26+
2727
// Destroy a list. If an item destructor was specified, all items in the
2828
// list are automatically destroyed as well.
2929
CZMQ_EXPORT void
3030
zlistx_destroy (zlistx_t **self_p);
31-
31+
3232
// Add an item to the head of the list. Calls the item duplicator, if any,
3333
// on the item. Resets cursor to list head. Returns an item handle on
3434
// success, NULL if memory was exhausted.
3535
CZMQ_EXPORT void *
3636
zlistx_add_start (zlistx_t *self, void *item);
37-
37+
3838
// Add an item to the tail of the list. Calls the item duplicator, if any,
3939
// on the item. Resets cursor to list head. Returns an item handle on
4040
// success, NULL if memory was exhausted.
4141
CZMQ_EXPORT void *
4242
zlistx_add_end (zlistx_t *self, void *item);
43-
43+
4444
// Return the number of items in the list
4545
CZMQ_EXPORT size_t
4646
zlistx_size (zlistx_t *self);
47-
47+
4848
// Return the item at the head of list. If the list is empty, returns NULL.
4949
// Leaves cursor pointing at the head item, or NULL if the list is empty.
5050
CZMQ_EXPORT void *
5151
zlistx_first (zlistx_t *self);
52-
52+
5353
// Return the next item. At the end of the list (or in an empty list),
5454
// returns NULL. Use repeated zlistx_next () calls to work through the list
5555
// from zlistx_first (). First time, acts as zlistx_first().
@@ -61,7 +61,7 @@ CZMQ_EXPORT void *
6161
// backwards from zlistx_last (). First time, acts as zlistx_last().
6262
CZMQ_EXPORT void *
6363
zlistx_prev (zlistx_t *self);
64-
64+
6565
// Return the item at the tail of list. If the list is empty, returns NULL.
6666
// Leaves cursor pointing at the tail item, or NULL if the list is empty.
6767
CZMQ_EXPORT void *
@@ -96,14 +96,21 @@ CZMQ_EXPORT void *
9696
CZMQ_EXPORT void *
9797
zlistx_detach (zlistx_t *self, void *handle);
9898

99+
// Detach item at the cursor, if any, from the list. The item is not modified,
100+
// and the caller is responsible for destroying it as necessary. Returns item
101+
// that was detached, or null if none was. Moves cursor to previous item, so
102+
// you can detach items while iterating forwards through a list.
103+
CZMQ_EXPORT void *
104+
zlistx_detach_cur (zlistx_t *self);
105+
99106
// Delete an item, using its handle. Calls the item destructor is any is
100107
// set. If handle is null, deletes the first item on the list. Returns 0
101108
// if an item was deleted, -1 if not. If cursor was at item, moves cursor
102109
// to previous item, so you can delete items while iterating forwards
103110
// through a list.
104111
CZMQ_EXPORT int
105112
zlistx_delete (zlistx_t *self, void *handle);
106-
113+
107114
// Move an item to the start of the list, via its handle.
108115
CZMQ_EXPORT void
109116
zlistx_move_start (zlistx_t *self, void *handle);
@@ -116,13 +123,13 @@ CZMQ_EXPORT void
116123
// is set.
117124
CZMQ_EXPORT void
118125
zlistx_purge (zlistx_t *self);
119-
126+
120127
// Sort the list. If an item comparator was set, calls that to compare
121128
// items, otherwise compares on item value. The sort is not stable, so may
122129
// reorder equal items.
123130
CZMQ_EXPORT void
124131
zlistx_sort (zlistx_t *self);
125-
132+
126133
// Create a new node and insert it into a sorted list. Calls the item
127134
// duplicator, if any, on the item. If low_value is true, starts searching
128135
// from the start of the list, otherwise searches from the end. Use the item
@@ -131,7 +138,7 @@ CZMQ_EXPORT void
131138
// list head.
132139
CZMQ_EXPORT void *
133140
zlistx_insert (zlistx_t *self, void *item, bool low_value);
134-
141+
135142
// Move an item, specified by handle, into position in a sorted list. Uses
136143
// the item comparator, if any, to determine the new location. If low_value
137144
// is true, starts searching from the start of the list, otherwise searches
@@ -149,7 +156,7 @@ CZMQ_EXPORT zlistx_t *
149156
// freed when the list is destroyed.
150157
CZMQ_EXPORT void
151158
zlistx_set_destructor (zlistx_t *self, czmq_destructor destructor);
152-
159+
153160
// Set a user-defined duplicator for list items; by default items are not
154161
// copied when the list is duplicated.
155162
CZMQ_EXPORT void

src/czmq_selftest.c

Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -33,47 +33,47 @@ main (int argc, char *argv [])
3333

3434
printf ("Running czmq selftests...\n");
3535

36-
zactor_test (verbose);
37-
zauth_test (verbose);
38-
zarmour_test (verbose);
39-
zbeacon_test (verbose);
40-
zcert_test (verbose);
41-
zcertstore_test (verbose);
42-
zchunk_test (verbose);
43-
zclock_test (verbose);
44-
zconfig_test (verbose);
45-
zdigest_test (verbose);
46-
zdir_test (verbose);
47-
zdir_patch_test (verbose);
48-
zfile_test (verbose);
49-
zframe_test (verbose);
50-
zgossip_test (verbose);
51-
zhashx_test (verbose);
52-
ziflist_test (verbose);
53-
zlistx_test (verbose);
54-
zloop_test (verbose);
55-
zmonitor_test (verbose);
56-
zmsg_test (verbose);
57-
zpoller_test (verbose);
58-
zproxy_test (verbose);
59-
zrex_test (verbose);
60-
zsock_test (verbose);
61-
zsock_option_test (verbose);
62-
zstr_test (verbose);
63-
zsys_test (verbose);
64-
zuuid_test (verbose);
65-
zgossip_msg_test (verbose);
66-
zauth_v2_test (verbose);
67-
zbeacon_v2_test (verbose);
68-
zctx_test (verbose);
69-
zhash_test (verbose);
70-
zlist_test (verbose);
71-
zmonitor_v2_test (verbose);
72-
zmutex_test (verbose);
73-
zproxy_v2_test (verbose);
74-
zsocket_test (verbose);
75-
zsockopt_test (verbose);
76-
zthread_test (verbose);
36+
zactor_test (verbose);
37+
zauth_test (verbose);
38+
zarmour_test (verbose);
39+
zbeacon_test (verbose);
40+
zcert_test (verbose);
41+
zcertstore_test (verbose);
42+
zchunk_test (verbose);
43+
zclock_test (verbose);
44+
zconfig_test (verbose);
45+
zdigest_test (verbose);
46+
zdir_test (verbose);
47+
zdir_patch_test (verbose);
48+
zfile_test (verbose);
49+
zframe_test (verbose);
50+
zgossip_test (verbose);
51+
zhashx_test (verbose);
52+
ziflist_test (verbose);
53+
zlistx_test (verbose);
54+
zloop_test (verbose);
55+
zmonitor_test (verbose);
56+
zmsg_test (verbose);
57+
zpoller_test (verbose);
58+
zproxy_test (verbose);
59+
zrex_test (verbose);
60+
zsock_test (verbose);
61+
zsock_option_test (verbose);
62+
zstr_test (verbose);
63+
zsys_test (verbose);
64+
zuuid_test (verbose);
65+
zgossip_msg_test (verbose);
66+
zauth_v2_test (verbose);
67+
zbeacon_v2_test (verbose);
68+
zctx_test (verbose);
69+
zhash_test (verbose);
70+
zlist_test (verbose);
71+
zmonitor_v2_test (verbose);
72+
zmutex_test (verbose);
73+
zproxy_v2_test (verbose);
74+
zsocket_test (verbose);
75+
zsockopt_test (verbose);
76+
zthread_test (verbose);
7777

7878
printf ("Tests passed OK\n");
7979
return 0;

src/zframe.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ zframe_new (const void *data, size_t size)
6161

6262

6363
// --------------------------------------------------------------------------
64-
// Create an empty (zero-sized) frame. The caller is responsible for
64+
// Create an empty (zero-sized) frame. The caller is responsible for
6565
// destroying the return value when finished with it.
6666

6767
zframe_t *
@@ -94,6 +94,17 @@ zframe_destroy (zframe_t **self_p)
9494
}
9595

9696

97+
// --------------------------------------------------------------------------
98+
// Create a frame with a specified string content.
99+
// The caller is responsible for destroying the return value when finished with it.
100+
101+
zframe_t *
102+
zframe_from (const char *string)
103+
{
104+
return zframe_new (string, strlen (string));
105+
}
106+
107+
97108
// --------------------------------------------------------------------------
98109
// Receive frame from socket, returns zframe_t object or NULL if the recv
99110
// was interrupted. Does a blocking recv, if you want to not block then use
@@ -254,7 +265,7 @@ zframe_streq (zframe_t *self, const char *string)
254265
assert (zframe_is (self));
255266

256267
if (zframe_size (self) == strlen (string)
257-
&& memcmp (zframe_data (self), string, strlen (string)) == 0)
268+
&& memcmp (zframe_data (self), string, strlen (string)) == 0)
258269
return true;
259270
else
260271
return false;

0 commit comments

Comments
 (0)