Skip to content

Commit 340a53f

Browse files
committed
fix xpc string bug
1 parent c5592a0 commit 340a53f

File tree

3 files changed

+33
-8
lines changed

3 files changed

+33
-8
lines changed

help/xpyc.maxhelp

+24-5
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,26 @@
1313
"rect" : [ 81.0, 109.0, 640.0, 480.0 ],
1414
"gridsize" : [ 15.0, 15.0 ],
1515
"boxes" : [ {
16+
"box" : {
17+
"id" : "obj-21",
18+
"maxclass" : "message",
19+
"numinlets" : 2,
20+
"numoutlets" : 1,
21+
"outlettype" : [ "" ],
22+
"patching_rect" : [ 309.5, 229.0, 80.0, 22.0 ],
23+
"text" : "request str(1)"
24+
}
25+
26+
}
27+
, {
1628
"box" : {
1729
"id" : "obj-17",
1830
"maxclass" : "message",
1931
"numinlets" : 2,
2032
"numoutlets" : 1,
2133
"outlettype" : [ "" ],
22-
"patching_rect" : [ 309.5, 195.0, 128.0, 22.0 ],
23-
"text" : "request \\\"abc\\\".upper()"
34+
"patching_rect" : [ 309.5, 195.0, 135.0, 22.0 ],
35+
"text" : "request sum.__name__"
2436
}
2537

2638
}
@@ -104,7 +116,7 @@
104116
"numoutlets" : 1,
105117
"outlettype" : [ "" ],
106118
"patching_rect" : [ 51.0, 279.0, 108.0, 22.0 ],
107-
"text" : "nan"
119+
"text" : "sum"
108120
}
109121

110122
}
@@ -199,8 +211,8 @@
199211
"maxclass" : "comment",
200212
"numinlets" : 1,
201213
"numoutlets" : 0,
202-
"patching_rect" : [ 23.0, 17.0, 578.0, 24.0 ],
203-
"text" : "xpyc: an xpc client embedded in an external (now just addition of two numbers)"
214+
"patching_rect" : [ 23.0, 17.0, 325.0, 24.0 ],
215+
"text" : "xpyc: an xpc client embedded in an external"
204216
}
205217

206218
}
@@ -323,6 +335,13 @@
323335
"source" : [ "obj-2", 0 ]
324336
}
325337

338+
}
339+
, {
340+
"patchline" : {
341+
"destination" : [ "obj-1", 0 ],
342+
"source" : [ "obj-21", 0 ]
343+
}
344+
326345
}
327346
, {
328347
"patchline" : {

source/projects/xpyc/services/PythonService/main.c

+5
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,13 @@ void evaluate_python(xpc_object_t reply, const char* code)
100100
long result = PyLong_AsLong(pval);
101101
xpc_dictionary_set_int64(reply, "result_type", (long)value_type);
102102
xpc_dictionary_set_int64(reply, "result", result);
103+
103104
} else if(PyFloat_Check(pval)) {
104105
double result = PyFloat_AsDouble(pval);
105106
ValueType value_type = get_pyobject_type(pval);
106107
xpc_dictionary_set_int64(reply, "result_type", (long)value_type);
107108
xpc_dictionary_set_double(reply, "result", result);
109+
108110
} else if(PyUnicode_Check(pval)) {
109111
const char* result = PyUnicode_AsUTF8(pval);
110112
if (result == NULL) {
@@ -114,6 +116,9 @@ void evaluate_python(xpc_object_t reply, const char* code)
114116
xpc_dictionary_set_int64(reply, "result_type", (long)value_type);
115117
xpc_dictionary_set_string(reply, "result", result);
116118
}
119+
else {
120+
// do nothing
121+
}
117122
goto finally;
118123

119124
error:

source/projects/xpyc/xpyc.c

+4-3
Original file line numberDiff line numberDiff line change
@@ -252,13 +252,14 @@ void xpyc_request(t_xpyc* x, t_symbol* s, int argc, t_atom* argv)
252252
post("result: %lld", result);
253253
outlet_int(x->outlet, result);;
254254
}
255-
else if (result_type = XPYC_TYPE_DOUBLE) {
255+
256+
else if (result_type == XPYC_TYPE_DOUBLE) {
256257
double result = xpc_dictionary_get_double(reply, "result");
257258
post("result: %f", result);
258-
outlet_float(x->outlet, result);;
259+
outlet_float(x->outlet, result);
259260
}
260261

261-
else if (result_type = XPYC_TYPE_STRING) {
262+
else if (result_type == XPYC_TYPE_STRING) {
262263
const char* result = xpc_dictionary_get_string(reply, "result");
263264
post("result: %s", result);
264265
outlet_anything(x->outlet, gensym(result), 0, NIL);

0 commit comments

Comments
 (0)